• This is default featured slide 1 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

  • This is default featured slide 2 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

  • This is default featured slide 3 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

  • This is default featured slide 4 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

  • This is default featured slide 5 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

Install SWAT to configure Samba from Web browser

# yum -y install xinetd
# /etc/rc.d/init.d/xinetd start
# yum -y install samba-swat
# vi /etc/xinetd.d/swat
only_from = 127.0.0.1 192.168.0.0/24
// line 10: add IPs you permit
disable = no
// line 14: change
#/etc/rc.d/init.d/xinetd restart
Access to [http://(server's hostname):901]

After accessing, user name and password is required to login. Input for root's one in it and login, then following screen is shown and you can configure samba on browser.
Share:

How to Backup files with tar

TAR is the Unix Tape ARchive utility. It can be used to either store data on a streaming tape device like a DAT drive, or store files in what is commonly called a tarball file- somewhat like a pkzip file, only compression is optional.


[The basics]

In these examples, I will use the following file structure: a top level directory called DIR1 containing the files picture.jpg, document.doc and database.db.

DIR1/

DIR1/picture.jpg
DIR1/document.doc
DIR1/database.db


[Creating a tarball]

If we were in the directory DIR1 and wanted to backup all the files to a tarball called backup.tar, we could issue this command:

$ tar cvf backup.tar .

./
picture.jpg
doucment.doc
database.db
tar: backup.tar is the archive; not dumped

Note:
c=create (an archive)
v=verbose (just because)
f=filename (the name of our tarball)
.=current directory (what's going to be backed up)

Also worth mentioning is that by default tar is recursive- meaning it will back up all files and subdirectories recursively unless you otherwise specify with the n flag (non-recursive)


[Displaying the Contents of a Tarball]

The current directory will now contain a file called backup.tar. To display the contents of the tarball file, we could issue this command:

$ tar tvf backup.tar

drwxr-xr-x root/gci 0 Jun 29 10:10 ./
-rw-r--r-- root/gci 1 Jun 29 10:10 picture.jpg
-rw-r--r-- root/gci 1 Jun 29 10:10 document.doc
-rw-r--r-- root/gci 1 Jun 29 10:10 databse.db

Note:
t=table of contents (list)
v=verbose (display all info)
f=filename (backup.tar)


[Extracting Data from a Tarball]

To extract the entire contents of the tarball to the current directory, we can type:

$ tar xvf backup.tar

./
picture.jpg
doucment.doc
database.db

Note:
x=extract
v=verbose
f=filename (backup.tar)

To extract only the picture.jpg file from the archive, type the following command:

$ tar xvf backup.tar picture.jpg

Alternatively, you can use wild cards in either the creation or extraction of a tarball. To extract all jpg files from our archive, we can use a command like this:

$ tar xvf backup.tar *.jpg


[Using Compression]

If you would also like to add compression to your tarballs, you can combine the gzip utility with tar on the command line by adding the z switch to the command. Usually when this is done, we change the suffix of our tarball filename from .tar to either .tgz or .tar.gz. This will let whoever sees the file know that it is a gzipped tarball.

$ tar zcvf tarball.tgz .

Note:
z=gzip compression
c=create
v=verbose
f=filename (backup.tgz)
.=current directory (what to backup)


[Permissions with tar]

If you would like to preserve the permissions of the files you backup, use the p option with the tar command. This will save the uid, gid as well as the specific permission attributes of the files (read, write, execute etc.)

$ tar pzcvf tarball.tgz .

You should also use the p option with the tar extraction command:

$ tar pxvf tarball.tgz .


[Using tar with a Tape Drive]

I use tar in conjunction with my Seagate DAT drive. If you issue any of the previous commands in this HOW-TO without the f option and a tarball filename, you will find that tar will default to writing the files to the device /dev/rsa0 (raw sequential access device 0). Basically this is your first SCSI tape drive. If you have more than one tape drive you would like to use, you can issue the f option and the device name (rsa0, rsa1 etc.) of your specific tape drive instead of a filename.

Examples:
Backing up the current directory to Tape:

$ tar cv . <- default tape drive (rsa0)

$ tar cvf /dev/rsa1 . <- second tape drive (rsa1)

Restore files from Tape:

$ tar xv .
$ tar xvf /dev/rsa1

So, there are the basics of tar. If you would like more information on the tar command, try the man pages.

man tar

Nguồn : Internet
Share:

Linux Start up and Run Levels

The Init Program

As seen in the previous section, the kernel will start a program called init, if it finds it. The init process reads the file "/etc/inittab" and uses this file to determine how to create processes. Read the init man page for more information. Also note that init is always running and can dynamically do things and run processes based upon various signals. The administrator can also cause it to dynamically change system processes and runlevels by using the telinit program or editing the "/etc/inittab" file.

Runlevels

Linux utilizes what is called "runlevels". A runlevel is a software configuration of the system that allows only a selected group of processes to exist. Init can run the system in one of eight runlevels. These runlevels are 0-6 and S or s. The system runs in only one of these runlevels at a time. Typically these runlevels are used for different purposes. Runlevels 0, 1, and 6 are reserved. For Redhat Linux version 6, the runlevels are:
0

-

halt
1

-

Single user mode
2

-

Multiuser, without NFS (The same as 3, if you don't have networking)
3

-

Full multiuser mode
4

-

unused
5

-

X11
6

-

Reboot

The inittab file

The "/etc/inittab" file tells init which runlevel to start the system at and describes the processes to be run at each runlevel. An entry in the inittab file has the following format:
id:runlevels:action:process
  • id - A unique sequence of 1-4 characters which identifies an entry in inittab.
  • runlevels - Lists the runlevels for which the specified action should be taken. This field may contain multiple characters for different runlevels allowing a particular process to run at multiple runlevels. For example, 123 specifies that the process should be started in runlevels 1, 2, and 3.
  • action - Describes which action should be taken. Valid actions are listed below
    • respawn - The process will be restarted whenever it terminates.
    • wait - The process will be started once when the specified runlevel is entered and init will wait for its termination.
    • once - The process will be executed once when the specified runlevel is entered
    • boot - The process will be executed during system boot. The runlevels field is ignored.
    • bootwait - Same as "boot" above, but init waits for its termination.
    • off - This does nothing.
    • ondemand - This process will be executed whenever the specified ondemand runlevel is called.
    • initdefault - Specifies the runlevel which should be entered after system boot. If none exists, init will ask for a runlevel on the console. The process field is ignored.
    • sysinit - The process will be executed during system boot. It will be executed before any boot or bootwait entries. The runlevels field is ignored.
    • powerwait - The process will be executed when init receives the SIGPWR signal. Init will wait for the process to finish before continuing.
    • powerfail - Same as powerwait but init does not wait for the process to complete.
    • powerokwait - The process will be executed when init receives the SIGPWR signal provided there is a file called "/etc/powerstatus" containing the word "OK". This means that the power has come back again.
    • ctrlaltdel - This process is executed when init receives the SIGINT signal. This means someone on the system console has pressed the "CTRL-ALT-DEL" key combination.
    • kbrequest - The process will be executed when init receives a signal from the keyboard handler that a special key combination was pressed on the console keyboard.
    • process - Specifies the process to be executed. If the process starts with the '+' character, init will not do utmp and wtmp accounting for that process. This is needed for gettys that insist on doing their own utmp/wtmp housekeeping (a historic bug).
Below is an example file:
  # inittab       This file describes how the INIT process should set up
  #               the system in a certain run-level.
  #
  # Author:       Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
  #               Modified for RHS Linux by Marc Ewing and Donnie Barnes
  #
 
  # Default runlevel. The runlevels used by RHS are:
  #   0 - halt (Do NOT set initdefault to this)
  #   1 - Single user mode
  #   2 - Multiuser, without NFS (The same as 3, if you do not have networking)
  #   3 - Full multiuser mode
  #   4 - unused
  #   5 - X11
  #   6 - reboot (Do NOT set initdefault to this)
  # 
1)       id:3:initdefault:
 
  # System initialization.
2)       si::sysinit:/etc/rc.d/rc.sysinit
 
3)       l0:0:wait:/etc/rc.d/rc 0
4)       l1:1:wait:/etc/rc.d/rc 1
5)       l2:2:wait:/etc/rc.d/rc 2
6)       l3:3:wait:/etc/rc.d/rc 3
7)       l4:4:wait:/etc/rc.d/rc 4
8)       l5:5:wait:/etc/rc.d/rc 5
9)       l6:6:wait:/etc/rc.d/rc 6
 
  # Things to run in every runlevel.
10)      ud::once:/sbin/update
 
  # Trap CTRL-ALT-DELETE
11)      ca::ctrlaltdel:/sbin/shutdown -t3 -r now
 
  # When our UPS tells us power has failed, assume we have a few minutes
  # of power left.  Schedule a shutdown for 2 minutes from now.
  # This does, of course, assume you have powerd installed and your
  # UPS connected and working correctly.  
12)      pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down"
 
  # If power was restored before the shutdown kicked in, cancel it.
13)      pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"
 
 
  # Run gettys in standard runlevels
14)      1:2345:respawn:/sbin/mingetty tty1
15)      2:2345:respawn:/sbin/mingetty tty2
16)      3:2345:respawn:/sbin/mingetty tty3
17)      4:2345:respawn:/sbin/mingetty tty4
18)      5:2345:respawn:/sbin/mingetty tty5
19)      6:2345:respawn:/sbin/mingetty tty6
 
  # Run xdm in runlevel 5
  # xdm is now a separate service
20)      x:5:respawn:/etc/X11/prefdm -nodaemon
On the left side of the file listing, above, are added numbers to help describe lines. Those lines without line numbers are either blank or begin with a "#" which means the line is a comment. Those line numbers are not part of the original file and are added here for reference purposes.
  • On line 1 above you see "id:3:initdefault:". The id is "id" which stands for initdefault. Note that it is unique on all the numbered lines. The runlevel is 3 which sets the default starting runlevel to runlevel 3. The action is initdefault which tells init to make this runlevel the default runlevel. Note that the process field is blank since it is ignored by the initdefault action.
  • Line 2 tells init to run the program "/etc/rc.d/rc.sysinit" during system boot, before any other processes.
  • Lines 3 through 9 tell init to run the program "/etc/rc.d/rc" for runlevels 0 through 6. Note that for each line the appropriate runlevel is passed to the "/etc/rc.d/rc" script program on the command line. For example note on line 5 above the second field is the runlevel specifying 2. At the end of the line there is a space and a 2 which allows the variable 2 to be passed on the command line to the program.
  • Line 10 specifies that the program "/sbin/update" will run once for every runlevel.
  • Line 11 sets up the program "/sbin/shutdown" to run when someone on the system console has pressed the "CTRL-ALT-DEL" key combination.
  • Line 12 specifies "/sbin/shutdown" to run if the power fails. Note that there are different options passed on the command line for lines 11 and 12 although they run the same program.
  • Line 13 specified "/sbin/shutdown" will run if power is restored for any of runlevels 1 through 5.
  • Lines 14 through 19 specifies the "/sbin/mingetty" program to run on 6 different terminals for runlevels 2 through 5. This means that you can run 6 virtual terminals from your keyboard simultaneously by pressing "ALT-F1" through "ALT-F6". Note pressing "ALT-F7" or above will do nothing, but the screen will not change from your current terminal.
Note the order of programs to run as specified above are:
  1. /etc/rc.d/rc.sysinit
  2. /etc/sbin/update
  3. /etc/rc.d/rc 3 - Note: we are running runlevel 3 here.
Therefore, the next thing that the system does is to run the rc.sysinit file, save buffers to the hard drive, then run system script files for the requested runlevel which will start up many system and network services as explained in the next section.
Share:

Cài đặt Ntop CentOS

Download latest ntop

Visit ntop project to grab latest version. You can use wget to grab the same, enter:
# cd /opt
# wget http://freshmeat.net/redir/ntop/7279/url_tgz/ntop-3.3.6.tar.gz

Untar tar ball, enter:
# tar -zxvf ntop-3.3.6.tar.gz

Configure and Compile ntop under RHEL

You must have RRDTool installed. You also need to install libpcap, enter:
# yum install libpcap-devel libpcap
Type the following commands to compile and install ntop:
# cd ntop
# ./autogen.sh

Just type make to compile ntop:
# make
Just type make install to install ntop:
# make install
# make install-data-as

Create ntop user

Type the following command to run ntop as ntop user, enter:
# useradd -M -s /sbin/nologin -r ntop

Setup directory permissions

Next, you need to setup directory permissions, enter:
# chown ntop:root /usr/local/var/ntop/
# chown ntop:ntop /usr/local/share/ntop/

Setup ntop user admin password

Type the following command to set ntop admin password, enter:
# ntop -A
Sample output:
Mon Jul 28 03:38:34 2008  NOTE: Interface merge enabled by default
Mon Jul 28 03:38:34 2008  Initializing gdbm databases

ntop startup - waiting for user response!

Please enter the password for the admin user:
Please enter the password again:
Mon Jul 28 03:38:42 2008  Admin user password has been set

Start ntop

Type the following command to start ntop:
# /usr/local/bin/ntop -d -L -u ntop -P /usr/local/var/ntop --skip-version-check --use-syslog=daemon
Sample output:
Mon Jul 28 03:42:19 2008  NOTE: Interface merge enabled by default
Mon Jul 28 03:42:19 2008  Initializing gdbm databases
If you have multiple interface (eth0, eth1 and so on), start ntop as follows:
# /usr/local/bin/ntop -i "eth0,eth1" -d -L -u ntop -P /usr/local/var/ntop --skip-version-check --use-syslog=daemon
Where,
  • -i "eth0,eth1" : Specifies the network interface or interfaces to be used by ntop for network monitoring. Here you are monitoring eth0 and eth1.
  • -d : Run ntop as a daemon.
  • -L : Send all log messages to the system log (/var/log/messages) instead of screen.
  • -u ntop : Start ntop as ntop user
  • -P /usr/local/var/ntop : Specify where ntop stores database files. You may need to backup database as part of your disaster recovery program.
  • --skip-version-check : By default, ntop accesses a remote file to periodically check if the most current version is running. This option disables that check.
  • --use-syslog=daemon : Use syslog daemon.

How do I view ntop stats?

By default ntop listen on 3000 port. You can view ntop stats by visiting following url:
http://localhost:3000/
OR
http://server-ip:3000/
Share:

Cài đặt Ntop CentOS

Download latest ntop

Visit ntop project to grab latest version. You can use wget to grab the same, enter:
# cd /opt
# wget http://freshmeat.net/redir/ntop/7279/url_tgz/ntop-3.3.6.tar.gz

Untar tar ball, enter:
# tar -zxvf ntop-3.3.6.tar.gz

Configure and Compile ntop under RHEL

You must have RRDTool installed. You also need to install libpcap, enter:
# yum install libpcap-devel libpcap
Type the following commands to compile and install ntop:
# cd ntop
# ./autogen.sh

Just type make to compile ntop:
# make
Just type make install to install ntop:
# make install
# make install-data-as

Create ntop user

Type the following command to run ntop as ntop user, enter:
# useradd -M -s /sbin/nologin -r ntop

Setup directory permissions

Next, you need to setup directory permissions, enter:
# chown ntop:root /usr/local/var/ntop/
# chown ntop:ntop /usr/local/share/ntop/

Setup ntop user admin password

Type the following command to set ntop admin password, enter:
# ntop -A
Sample output:
Mon Jul 28 03:38:34 2008  NOTE: Interface merge enabled by default
Mon Jul 28 03:38:34 2008  Initializing gdbm databases

ntop startup - waiting for user response!

Please enter the password for the admin user:
Please enter the password again:
Mon Jul 28 03:38:42 2008  Admin user password has been set

Start ntop

Type the following command to start ntop:
# /usr/local/bin/ntop -d -L -u ntop -P /usr/local/var/ntop --skip-version-check --use-syslog=daemon
Sample output:
Mon Jul 28 03:42:19 2008  NOTE: Interface merge enabled by default
Mon Jul 28 03:42:19 2008  Initializing gdbm databases
If you have multiple interface (eth0, eth1 and so on), start ntop as follows:
# /usr/local/bin/ntop -i "eth0,eth1" -d -L -u ntop -P /usr/local/var/ntop --skip-version-check --use-syslog=daemon
Where,
  • -i "eth0,eth1" : Specifies the network interface or interfaces to be used by ntop for network monitoring. Here you are monitoring eth0 and eth1.
  • -d : Run ntop as a daemon.
  • -L : Send all log messages to the system log (/var/log/messages) instead of screen.
  • -u ntop : Start ntop as ntop user
  • -P /usr/local/var/ntop : Specify where ntop stores database files. You may need to backup database as part of your disaster recovery program.
  • --skip-version-check : By default, ntop accesses a remote file to periodically check if the most current version is running. This option disables that check.
  • --use-syslog=daemon : Use syslog daemon.

How do I view ntop stats?

By default ntop listen on 3000 port. You can view ntop stats by visiting following url:
http://localhost:3000/
OR
http://server-ip:3000/
Share:

Hướng dẩn cài đặt VNC CentOS

Bước 1 : Cài X Windows System (KDE và GNOME Desktop Environement !)

Kiểm tra xem svr đã cài gói này chưa bằng cách dùng lệnh :

Code - [#]
yum grouplist
Nếu chưa thấy trong mục Installed thì tiến hành cài !

Để cài GNOME Desktop Environnement chạy lệnh :

Code - [#]
yum groupinstall "X Window System" "GNOME Desktop Environment"

Nếu thấy như đoạn dưới đây là thành công :

Code - [#]
Installed: NetworkManager-gnome.x86_64 0:0.3.1-5.el4 file-roller.x86_64 0:2.8.1-1 gconf-editor.x86_64 0:2.8.0-2 gedit.x86_64 1:2.8.1-4 ggv.x86_64 0:2.8.0-1 gimp-print-utils.x86_64 0:4.2.7-2 gnopernicus.x86_64 0:0.9.12-1 gok.x86_64 0:0.11.8-1 gpdf.x86_64 0:2.8.2-7.7.2.el4_7.4 gtk-engines.x86_64 1:0.12-6.el4 gtk-engines.i386 1:0.12-6.el4 gtk2-engines.i386 0:2.2.0-7.el4 hwbrowser.noarch 0:0.19-0.EL4.4 nautilus-media.x86_64 0:0.8.1-3 vino.x86_64 0:2.8.1-1.5 yelp.x86_64 0:2.6.4-2
Dependency Installed: gimp-print.x86_64 0:4.2.7-2 gtk+.i386 1:1.2.10-36 gtksourceview.x86_64 0:1.1.0-4 imlib.i386 1:1.9.13-23 libungif.i386 0:4.1.3-1.el4.2 pyparted.x86_64 0:1.6.8-2
Complete!
Sau khi cài đặt xong GNOME Desktop Environnement,chúng ta chuyển qua KDE chạy lệnh :

Code - [#]
yum groupinstall "X Window System" "GNOME Desktop Environment"
Cài đặt tương tự như GNOME , cũng hỏi y/n chọn y,rồi ngồi đợi
Cái này chắc ko phải nói nhiều ^_^ !

Bước 2 :
Cài đặt VNC Server :

Dùng lệnh :

Code - [#]
yum install vnc-server
Đợi nó cài :

Nếu được như đoạn dưới đây bạn đã cài xong vnc server :

Code - [#]
[root@vps1161 ~]# yum install vnc-server
Loading "priorities" plugin
Loading "fastestmirror" plugin
Setting up Install Process
Setting up repositories
update                    100% |=========================|  951 B    00:00
base                      100% |=========================| 1.1 kB    00:00
contrib                   100% |=========================|  951 B    00:00
centosplus                100% |=========================|  951 B    00:00
addons                    100% |=========================|  951 B    00:00
extras                    100% |=========================| 1.1 kB    00:00
Loading mirror speeds from cached hostfile
Reading repository metadata in from local files
Excluding Packages in global exclude list
Finished
0 packages excluded due to repository priority protections
Parsing package install arguments
Nothing to do
Bước 3 : Hiệu chỉnh config của VNC Server

Bây h chúng ta edit file config của vnc server,chạy lệnh :

Code - [#]
vi /etc/sysconfig/vncservers
Các bạn nào chưa biết sử dụng lệnh vi trong SSH thì mình xin hướng dẫn qua luôn 1 số lệnh cơ bản
Sau khi chạy lệnh

Code - [#]
vi /etc/sysconfig/vncservers
Các bạn sửa nội dung file config vncserver như sau:
Bỏ 2 dấu # ở 2 câu cuối cùng :

Code - [#]
# The VNCSERVERS variable is a list of display:user pairs.
#
# Uncomment the lines below to start a VNC server on display :2
# as my 'myusername' (adjust this to your own). You will also
# need to set a VNC password; run 'man vncpasswd' to see how
# to do that.
#
# DO NOT RUN THIS SERVICE if your local area network is
# untrusted! For a secure way of using VNC, see
# <URL:http://www.uk.research.att.com/archive/vnc/sshvnc.html>.

# Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.

# Use "-nohttpd" to prevent web-based VNC clients connecting.

# Use "-localhost" to prevent remote VNC clients connecting except when
# doing so through a secure tunnel. See the "-via" option in the
# `man vncviewer' manual page.

VNCSERVERS="1:root"
VNCSERVERARGS[1]="-geometry 800x600"
ESC để thoát Insert Mode,rồi dùng lệnh :wq,để save file đó lại và trở về command của SSH !

Bước 4 : Khởi động VNC Server :

Code - [#]
vncserver
Nếu nó đòi pass thì bạn nhập pass vào,pass này sẽ để bạn dùng VNC CLient connect tới svr !

Bước 4 : Sửa file xstartup

Code - [#]
vi /root/.vnc/xstartup
Bỏ 2 dấu thăngs ở 2 đoạn như code dưới :

Code - [#]
unset SESSION_MANAGER
 exec /etc/X11/xinit/xinitrc
Code - [#]
#!/bin/sh

# Uncomment the following two lines for normal desktop:
unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
twm &
Bước 5 : Khởi động lại vnc server :

Code - [#]
/etc/init.d/vncserver restart
Bước 6 : Khởi động khi bật máy

Code - [#]
chkconfig vncserver on
Bước 7 : Tắt firewall

Code - [#]
/etc/init.d/iptables stop
Bước 8 : Tắt firewall khi bật máy

Code - [#]
chkconfig iptables off
Bước 9 : Download VNC CLient về và chén thôi 

Code - [#]
http://www.stanford.edu/class/ee108b/tools/vncviewer.exe
Bật VNC Client , nhập IP SVR theo dạng
IP:1 hoac IP:2 do bạnconfig trong files /etc/sysconfig/vncservers
Share:

Popular Posts