Chủ Nhật, 1 tháng 12, 2013

Installing Node.js via package manager

The packages on this page are maintained and supported by their respective packagers, not the node.js core team. Please report any issues you encounter to the package maintainer. If it turns out your issue is a bug in node.js itself, the maintainer will report the issue upstream.

Gentoo

Node.js is available in the portage tree.
# emerge nodejs

Debian, LMDE

For Debian Wheezy, you have two options:

Build from source

sudo apt-get install python g++ make checkinstall
mkdir ~/src && cd $_
wget -N http://nodejs.org/dist/node-latest.tar.gz
tar xzvf node-latest.tar.gz && cd node-v* #(remove the "v" in front of the version number in the dialog)
./configure
checkinstall 
sudo dpkg -i node_*
Uninstall:
sudo dpkg -r node
In case you get a permission denied on the node executable, an alternative path might be:
umask 0022
./configure
make
checkinstall -D --umask 0022 --reset-uids --install=no
dpkg -i node_*.deb

Backports

Alternatively, you can install nodejs from wheezy-backports. If you rely on having node as an executable, install nodejs-legacy as well.
If you need npm as well, you can get it through the installer
curl https://npmjs.org/install.sh | sudo sh

Ubuntu, Mint, Elementary OS

At Least from Ubuntu 13.04, an old version (0.6.x) of Node is in the standard repository. To install, just run:
sudo apt-get install nodejs
Obtaining a recent version of Node or installing on older Ubuntu and other apt-based distributions may require a few extra steps. Example install:
sudo apt-get update
sudo apt-get install -y python-software-properties python g++ make
sudo add-apt-repository -y ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
It installs current stable Node on the current stable Ubuntu. Quantal (12.10) users may need to install the software-properties-commonpackage for the add-apt-repository command to work: sudo apt-get install software-properties-common
As of Node.js v0.10.0, the nodejs package from Chris Lea's repo includes both npm and nodejs-dev.
There is a naming conflict with the node package (Amateur Packet Radio Node Program), and the nodejs binary has been renamed fromnode to nodejs. You'll need to symlink /usr/bin/node to /usr/bin/nodejs or you could uninstall the Amateur Packet Radio Node Program to avoid that conflict.

openSUSE & SLE

Node.js stable repos list. Also node.js is available in openSUSE:Factory repository.
Available RPM packages for: openSUSE 11.4, 12.1, Factory and Tumbleweed; SLE 11 (with SP1 and SP2 variations).
Example install on openSUSE 12.1:
sudo zypper ar http://download.opensuse.org/repositories/devel:/languages:/nodejs/openSUSE_12.1/ NodeJSBuildService 
sudo zypper in nodejs nodejs-devel

Fedora

Node.js and npm are available in Fedora 18 and later. Just use your favorite graphical package manager or run this on a terminal to install both npm and node:
sudo yum install npm

RHEL/CentOS/Scientific Linux 6

Node.js and npm are available from the Fedora Extra Packages for Enterprise Linux (EPEL) repository. If you haven't already done so, firstenable EPEL.
To check if you have EPEL, run
yum repolist
if you don't see epel, download it (At the time of this writing, the last version is 6.8.)
curl -O http://download-i2.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
then install it
sudo rpm -ivh epel-release-6-8.noarch.rpm
And then run the following command to install node and npm:
sudo yum install npm --enablerepo=epel

Arch Linux

Node.js is available in the Community Repository.
pacman -S nodejs

FreeBSD and OpenBSD

Node.js is available through the ports system.
/usr/ports/www/node
Development versions are also available using ports
cd /usr/ports/www/node-devel/ && make install clean
or packages on FreeBSD
pkg_add -r node-devel

OSX

Using a package
Simply download Macintosh Installer.
Using homebrew:
brew install node
Using macports:
port install nodejs  

Windows

Using a package
Simply download Windows Installer.
Using chocolatey to install Node:
cinst nodejs  
cinst nodejs.install

Source: https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager

Thứ Năm, 14 tháng 11, 2013

How To Add and Delete Users on Ubuntu 12.04 and CentOS 6

When you log into a new freshly spun up droplet, you are accessing it from the root user. Although this gives you the power to make any changes you need on the server, you are much better off creating another new user with root privileges on the virtual private server. Additionally, if other people will be accessing the virtual server, you will need to make new users for them as well. This tutorial will go over creating a new user, granting them root privileges, and deleting users.

When you perform any root tasks with the new user, you will need to use the phrase “sudo” before the command. This is a helpful command for 2 reasons: 1) it prevents the user making any system-destroying mistakes 2) it stores all the commands run with sudo to a file where can be reviewed later if needed. Keep in mind however, that this user is as powerful as the root user. If you only need a user for a limited number of tasks on the VPS, you do not need to give them root privileges. 

Setup


This tutorial requires access to the root user or a user with sudo privileges. 

You should have received your root password from the welcome email after you launched your droplet.

Users on Ubuntu 12.04


How to Add a User on Ubuntu 12.04


To add a new user in Ubuntu, use the adduser command, replacing the “newuser” with your preferred username.
sudo adduser newuser

As soon as you type this command, Ubuntu will automatically start the process:
  • Type in and confirm your password

  • Enter in the user’s information. This is not required, pressing enter will automatically fill in the field with the default information

  • Press Y (or enter) when Ubuntu asks you if the information is correct

Congratulations—you have just added a new user. You can log out of the root user by typingexit and then logging back in with the new username and password.

How to Grant a User Root Privileges


As mentioned earlier, you are much better off using a user with root privileges.

You can create the sudo user by opening the sudoers file with this command:
sudo /usr/sbin/visudo

Adding the user’s name and the same permissions as root under the the user privilege specification will grant them the sudo privileges.
# User privilege specification
root    ALL=(ALL:ALL) ALL 
newuser ALL=(ALL:ALL) ALL

Press ‘cntrl x’ to exit the file and then ‘Y’ to save it.

How to Delete a User


Should you find that you find that you no longer want to have a specific user on the virtual private server you can delete them with a single command.
sudo userdel newuser

Finish up by the deleting the user’s home directory:
 sudo rm -rf /home/newuser



Users on CentOS 6


How to Add a User on CentOS 6


To add a new user in CentOS, use the adduser command, replacing the “newuser” with your preferred username.
sudo adduser newuser

Follow up by providing the user with a new password, typing and confirming the new password when prompted:
sudo passwd newuser

Congratulations—you have just added a new user and their password. You can log out of the root user by typing exit and then logging back in with the new username and password.

How to Grant a User Root Privileges


As mentioned earlier, you are much better off using a user with root privileges.

You can create the sudo user by opening the sudoers file with this command:
sudo /usr/sbin/visudo

You will find the section to make the user privilege modifications at the bottom of the file. Type “a” to start inserting text. Adding the user’s name and the same permissions as root under the the user privilege specification will grant them the sudo privileges.
## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
newuser ALL=(ALL)       ALL

Save and Exit the file by press “shift” ZZ. 

How to Delete a User


Should you find that you find that you no longer want to have a specific user on the virtual private server you can delete them with a single command.
sudo userdel newuser

You can add the flag “-r” to the command if you would like to simultaneously remove the users’s home directory and files.
sudo userdel -r newuser

Next Steps


Once you have set up the users will you need, you can start building up your VPS. A good place to start is to install the LAMP stack (a collection of basic web server software) on your droplet, using the tutorials below. 

LAMP on Ubuntu 12.04 

LAMP on CentOS 6



By Etel Sverdlov

How to use FTP from the command line.

FTP (File Transfer Protocol) allows you to transfer files between your PC and other Internet systems (hosts). You can transfer files, work with local or remote directories, rename and display files, and execute system commands. Before you start, you must know how to log on to the remote system and have a userid and password on that system.

Note: Some systems allow anonymous ftp access. To use anonymous ftp, use anonymous as your userid andyour e-mail address as the logon password.


Logging Onto and Off of a Remote System

To begin using Microsoft's FTP client, Open a command prompt and switch to the destination directory (where you want the download file).
To start an FTP session, enter: ftp host_name
where hostname is the name or IP address of the remote system.
You will then be asked to enter your userid and password.
Once you have successfully logged onto a remote system, you will be able to use ftp commands to view a listing of files on the remote system and transfer files between the two systems.
Example: Download i386.exe (Windows NT 3.5 Resource Kit) from ftp://ftp.microsoft.com/bussys/winnt/winnt-public/reskit/nt35/i386 to C:\Temp\Download

  1. Open a command prompt. Enter CD C:\Temp\Download (assuming that directory exists).
    Enter: ftp ftp.microsoft.com

    You should now see a prompt similar to this:
    Connected to ftp.microsoft.com.
    220 Microsoft FTP Service
    User (ftp.microsoft.com:(none)):


  2. For the userid, Enter: anonymous

    You should see a prompt similar to this:
    331 Anonymous access allowed, send identity (e-mail name) as password.
    Password:


  3. Enter: userid@domain.com as the password at the "Password:" prompt.
    Note: Any e-mail address in a userid@domain.com format should work. You will not be able to see the password as you type it.


  4. To download i386.exe from the bussys/winnt/winnt-public/reskit/nt35/i386 directory, Enter: get bussys/winnt/winnt-public/reskit/nt35/i386/i386.exe
    Note: You could have also used ls to view the directory and file names, cd bussys/winnt/winnt-public/reskit/nt35/i386 to switch directories, and get i386.exe to download the file from within that directory.


  5. To end the FTP session, Enter: quit or bye.
Note: Once you have extracted the resource kit, you will have to expand individual files
example: expand choice.ex_ choice.exe


FTP Commands

For a list of FTP commands, at the "ftp>" prompt, Enter: help
When using ftp from the command prompt, the following list of supported commands will be displayed:
Note: Hover your mouse over a command to see what the output of "help *" is for that command.
!   
delete
literal
prompt
send
?   
debug
ls  
put 
status
append
dir
mdelete
pwd 
trace
ascii
disconnect
mdir
quit
type
bell
get 
mget
quote
user
binary
glob
mkdir
recv
verbose
bye 
hash
mls 
remotehelp
 
cd  
help
mput
rename
 
close
lcd 
open
rmdir
 
The question mark (?) command is equivalent to the help command. Typing help or ? followed by the name of a command will display a brief description of the command's purpose.
The exclamation point (!) can be used to shell to the system (command) prompt. Type Exit to return to the FTP session. You can also issue a subset of system commands to perform as you shell out, e.g., ! dir %windir% | more. When the commands in the shell have completed, you will be returned to the FTP session.
The pwd command will list the current directory on the remote machine. To change directories on the remote machine, use the cd command. To create a new directory on the remote machine, use the mkdir command followed by the name you would like to assign to the new directory. The lcd command can be used to change directories on the local (PC) machine.
To display a listing of files on the remote system, enter: ls or dir.
To download a file (copy a file from the remote system to your PC), you can use the command get or recvfollowed by the name of the file you would like to download. Optionally, you can follow the filename with a second filename which will be assigned to the file when it is downloaded to your PC. To download multiple files, you can use the mget command followed by a descriptor for the files you would like to download (e.g.: *.f for all files ending in ".f" or *.* for all files). You will be prompted to indicate whether you would like to download each file in turn. To turn off this prompting, enter the prompt command prior to entering the mget command; you will receive the message "Interactive mode OFF" indicating that prompting has been deactivated.
By default, files are downloaded and uploaded in ASCII file transfer mode. To download or upload files using Binary format mode, enter the command Binary at the "ftp>" prompt prior to downloading or uploading the file(s). To return to ASCII file transfer mode, enter the ASCII command.
To upload a file (copy a file from your PC to the remote system), you can use the command put or send followed by the name of the file you would like to upload. Optionally, you can follow the filename with a second filename which will be assigned to the file when it is uploaded to the remote system. The mput command can be used to upload multiple files.
You can use the close or disconnect command to drop the current ftp connection without exiting from the command enironment and then use the open command to connect to a new host.

Much of this article was taken from the dead link,http://www.cc.vt.edu/cc/us/docs/faqlib/windows95/clients/msftp.html

To see the original article, go tohttp://web.archive.org/web/*/http://www.cc.vt.edu/cc/us/docs/faqlib/windows95/clients/msftp.html



Source: http://www.tburke.net/info/misc/cmdline-ftp.htm

Ubuntu Linux: Compress files using tar Command

How do I compress and backup files using tar command to another directory on same computer or another Linux computer under Ubuntu Linux?

First, open up a terminal under Ubuntu Linux. Some directories such as /etc require root permissions to read and write for backup. So you may need to run tar command using sudo command. In this example backup, /etc and your /home/vivek to /backup directory, enter:
$ sudo mkdir /backup
$ sudo tar -zcvpf /backup/files.backup.Nov_6_2009.tar.gz /etc/ /home/vivek

Where,
  • z : Compress the backup file with 'gzip' to make it smaller.
  • c : Create a new backup archive called /backup/files.backup.Nov_6_2009.tar.gz.
  • v : Verbose mode, the tar command will display what it's doing to the screen.
  • p : Preserves the permissions of the files put in the archive for restoration later.
  • f /backup/files.backup.Nov_6_2009.tar.gz: Specifies where to store the backup, /backup/files.backup.Nov_6_2009.tar.gz is the filename used in this example.

How Do I Exclude Certain Files or Directories?

You can exclude all *.mp3 stored in /home/vivek/music directory with --exclude option:
$ sudo tar --exclude='/home/vivek/music/' -zcvpf /backup/files.backup.Nov_6_2009.tar.gz /etc/ /home/vivek
Another example (exclude ~/music/ and ~/Downloads/*.avi files):
$ sudo tar --exclude='/home/vivek/music/' --exclude='/home/vivek/Downloads/*.avi' -zcvpf /backup/files.backup.Nov_6_2009.tar.gz /etc/ /home/vivek

How Do I See a List Of Files Stored In Tar Ball or an Archive?

Type the following command:
$ sudo tar -ztvf /backup/files.backup.Nov_6_2009.tar.gz
Where,
  • t: List the contents of an archive.

How Do I Restore Files?

You can use the command as follows to restore everything in / directory:
$ sudo tar -xvpzf /backup/files.backup.Nov_6_2009.tar.gz -C /
OR
$ cd /
$ sudo tar -xvpzf /backup/files.backup.Nov_6_2009.tar.gz

Where,
  • -x: Extract the files.
  • -C / : Extract the files in / directory.
In this example, you are restoring to the /delta directory.
$ sudo tar -xvpzf /backup/files.backup.Nov_6_2009.tar.gz -C /delta

How Do I Backup Files To a Remote Server Called backup.example.com?

Type the command as follows to backup /etc/ and /home/vivek directories to a remote system called backup.example.com:
$ sudo -s
# ssh user@backup.example.com "mkdir /backup"
# tar zcvpf - /etc/ /home/vivek | ssh user@backup.example.com "cat > /backup/files.backup.Nov_6_2009.tar.gz"

How Do I Restore Backup From a Remote System to Local Ubuntu Box?

Type the command
$ sudo -s
# cd /
# ssh user@backup.example.com "cat /backup/files.backup.Nov_6_2009.tar.gz" | tar zxpvf -
Source: http://www.cyberciti.biz/faq/ubuntu-howto-compress-files-using-tar/

Make Browsers Cache Static Files With mod_expires On Apache2 (Debian Squeeze)

This tutorial explains how you can configure Apache2 to set the Expires HTTP header and the max-age directive of the Cache-Control HTTP header of static files (such as images, CSS and Javascript files) to a date in the future so that these files will be cached by your visitors' browsers. This saves bandwidth and makes your web site appear faster (if a user visits your site for a second time, static files will be fetched from the browser cache). This tutorial was written for Debian Squeeze.
I do not issue any guarantee that this will work for you!

1 Preliminary Note

I'm assuming you have a working Apache setup on your Debian Squeeze server, e.g. as shown in this tutorial: Installing Apache2 With PHP5 And MySQL Support On Debian Squeeze (LAMP)

2 Enabling mod_expires

mod_expires can be enabled as follows:
a2enmod expires
Restart Apache afterwards:
/etc/init.d/apache2 restart

3 Configuring mod_expires

The mod_expires configuration can be placed in the overall Apache server configuration, inside a virtual host container, inside a <Directory> directive, or inside an .htaccess file.
In this example, I will place it in Apache's default vhost which is configured in /etc/apache2/sites-available/default on Debian Squeeze:
vi /etc/apache2/sites-available/default
If you have multiple file types that should expire after the same time after they have been accessed (let's say in one week), you can use a combination of the FilesMatch and the ExpiresDefaultdirectives, e.g. as follows:
[...]
<IfModule mod_expires.c>
          <FilesMatch "\.(jpe?g|png|gif|js|css)$">
                      ExpiresActive On
                      ExpiresDefault "access plus 1 week"
          </FilesMatch>
</IfModule>
[...]
This would tell browsers to cache .jpg, .jpeg, .png, .gif, .js, and .css files for one week.
Restart Apache after your changes:
/etc/init.d/apache2 restart
Instead of using FilesMatch and ExpiresDefault directives, you could also use the ExpiresByType directice and set an Expires header (plus the max-age directive of the Cache-Control HTTP header) individually for each file type, e.g. as follows:
[...]
<IfModule mod_expires.c>
          ExpiresActive on

          ExpiresByType image/jpg "access plus 60 days"
          ExpiresByType image/png "access plus 60 days"
          ExpiresByType image/gif "access plus 60 days"
          ExpiresByType image/jpeg "access plus 60 days"

          ExpiresByType text/css "access plus 1 days"

          ExpiresByType image/x-icon "access plus 1 month"

          ExpiresByType application/pdf "access plus 1 month"
          ExpiresByType audio/x-wav "access plus 1 month"
          ExpiresByType audio/mpeg "access plus 1 month"
          ExpiresByType video/mpeg "access plus 1 month"
          ExpiresByType video/mp4 "access plus 1 month"
          ExpiresByType video/quicktime "access plus 1 month"
          ExpiresByType video/x-ms-wmv "access plus 1 month"
          ExpiresByType application/x-shockwave-flash "access 1 month"

          ExpiresByType text/javascript "access plus 1 week"
          ExpiresByType application/x-javascript "access plus 1 week"
          ExpiresByType application/javascript "access plus 1 week"
</IfModule>
[...]
You might have noticed that I've set three ExpiresByType directives for Javascript files - that is because Javascript files might have different file types on each server. If you set just one directive fortext/javascript, but the server recognizes the Javascript file as application/javascript, then it will not be covered by your configuration, and no cache headers will be set.
You can use the following time units in your configuration:
  • years
  • months
  • weeks
  • days
  • hours
  • minutes
  • seconds
Please note that Apache accepts these time units in both singular and plural, so you can use day and daysweek and weeks, etc.
It is possible to combine multiple time units, e.g. as follows:
ExpiresByType text/html "access plus 1 month 15 days 2 hours"
Also note that if you use a far future Expires header you have to change the component's filename whenever the component changes. Therefore it's a good idea to version your files. For example, if you have a file javascript.js and want to modify it, you should add a version number to the file name of the modified file (e.g. javascript-1.1.js) so that browsers have to download it. If you don't change the file name, browsers will load the (old) file from their cache.
Instead of basing the Expires header on the access time of the browser (e.g. ExpiresByType image/jpg "access plus 60 days"), you can also base it on the modification date of a file (please note that this works only for real files that are stored on the hard drive!) by using the modification keyword instead of access:
ExpiresByType image/gif "modification plus 7 days"

4 Testing

To test if your configuration works, you can install the Live HTTP Headers plugin for Firefox and access a static file through Firefox (e.g. an image). In the Live HTTP Headers output, you should now see an Expires header and a Cache-Control header with a max-age directive (max-age contains a value in seconds, for example 604800 is one week in the future):
Click to enlarge

5 Links