2012年3月9日星期五
2012年3月8日星期四
Startup and Services
1.Understanding the GRUB Boot Loader
1.1 Configuring GRUB
The GRUB boot loader is highly configurable, and its configuration is contained in the grub.conf
configuration file. On Red Hat, it can be found at /boot/grub/grub.conf (and the file is usually linked symbolically to /etc/grub.conf).
#boot=/dev/sda
default=1
timeout=5
splashimage=(hd0,2)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-238.19.1.el5)
root (hd0,2)
kernel /vmlinuz-2.6.18-238.19.1.el5 ro root=LABEL=/ rhgb quiet
initrd /initrd-2.6.18-238.19.1.el5.img
title CentOS (2.6.18-238.12.1.el5)
root (hd0,2)
kernel /vmlinuz-2.6.18-238.12.1.el5 ro root=LABEL=/ rhgb quiet
initrd /initrd-2.6.18-238.12.1.el5.img
1.2 Securing Your Boot Loader
1.1 Configuring GRUB
The GRUB boot loader is highly configurable, and its configuration is contained in the grub.conf
configuration file. On Red Hat, it can be found at /boot/grub/grub.conf (and the file is usually linked symbolically to /etc/grub.conf).
#boot=/dev/sda
default=1
timeout=5
splashimage=(hd0,2)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-238.19.1.el5)
root (hd0,2)
kernel /vmlinuz-2.6.18-238.19.1.el5 ro root=LABEL=/ rhgb quiet
initrd /initrd-2.6.18-238.19.1.el5.img
title CentOS (2.6.18-238.12.1.el5)
root (hd0,2)
kernel /vmlinuz-2.6.18-238.12.1.el5 ro root=LABEL=/ rhgb quiet
initrd /initrd-2.6.18-238.12.1.el5.img
1.2 Securing Your Boot Loader
GRUB provides the ability to set a password to the boot loader so that any changes to the preconfigured boot process requires the user to enter a password. First you have to generate an MD5 hash password, and then add that to the grub.conf file. To do this, you need to initiate GRUB’s command- line manager using the grub command.
$ sudo grub
grub> md5crypt
Password: ************
Encrypted: $1$3yQFp$MEDEglsxOvuTWzWaztRly.
grub> quit
Next, add this to your grub.conf file like so:
default=1
timeout=10
splashimage=(hd0,2)/grub/splash.xpm.gz
password -- md5 $1$3yQFp$MEDEglsxOvuTWzWaztRly --全局密码,不能直接使用e命令编辑
hiddenmenu
title CentOS (2.6.18-238.19.1.el5)
password -- md5 $1$3yQFp$MEDEglsxOvuTWzWaztRly --菜单密码,输入菜单密码才能启动
root (hd0,2)
kernel /vmlinuz-2.6.18-238.19.1.el5 ro root=LABEL=/ rhgb quiet
initrd /initrd-2.6.18-238.19.1.el5.img
title CentOS (2.6.18-238.12.1.el5)
root (hd0,2)
kernel /vmlinuz-2.6.18-238.12.1.el5 ro root=LABEL=/ rhgb quiet
initrd /initrd-2.6.18-238.12.1.el5.img
1.3 Configuring init
Red Hat generally starts in runlevel 5 if you have a GUI console installed or runlevel 3 for command line only. Red Hat has the following runlevels:
• Runlevel 0: Shuts down the host and brings the system to a halt
• Runlevel 1: Runs in single- user (maintenance) mode, command console, no network
• Runlevel 2: Is unassigned
• Runlevel 3: Runs in multiuser mode, with network, and starts level 3 programs
• Runlevel 4: Is unassigned
• Runlevel 5: Runs in multiuser mode, with network, X Windows (KDE, GNOME), and starts level 5 programs.
• Runlevel 6: Reboots the host
On most distributions, including Red Hat, the /sbin/init tool is configured using the /etc/inittab file. The init tool uses a series of scripts and directories under the /etc/rc.d directory named rc.x where x is the runlevel; for example, the /etc/rc.d/rc3.d directory stores the applications in runlevel 3.
$ man inittab
To change the default runlevel, which is the most common reason for editing the inittab file, you change the initdefault line. Here, the default runlevel is 5:
id:5:initdefault:
To change the default runlevel from 5 to 3, you replace the number 5 with 3 like so:
id:3:initdefault:
You can use the telinit or init command to switch between runlevels. First, work out what runlevel you
are at now by using the runlevel command, which will return a message showing the previous and current runlevel, as shown in this example:
$ sudo runlevel
N 5
$ sudo telinit 3
$ sudo init 3
1.4 Managing Services
You can examine what services will start in each runlevel by listing the contents of the /etc/rc.d/rcn.d directories (where n is a runlevel between 0 and 6). Let’s look at part of the contents of the /etc/rc.d/rc3.d directory.
$ ls -l /etc/rc.d/rc3.d/
lrwxrwxrwx 1 root root 16 2008-04- 29 06:58 K02httpd -> ../init.d/httpd
lrwxrwxrwx 1 root root 17 2008-04- 29 07:31 K30postfix -> ../init.d/postfix
lrwxrwxrwx 1 root root 20 2007-11- 09 04:48 K50netconsole -> ../init.d/netconsole
lrwxrwxrwx 1 root root 19 2008-08- 19 06:58 S08ip6tables -> ../init.d/ip6tables
lrwxrwxrwx 1 root root 18 2008-08- 19 06:58 S08iptables -> ../init.d/iptables
lrwxrwxrwx 1 root root 17 2007-11- 09 04:48 S80postfix -> ../init.d/postfix
You can see that all the files in the /etc/rc.d/rc3.d directory are symbolic links to indi-vidual init.d scripts, which are found in /etc/rc.d/init.d/ directory contain the instructions about how to start, stop, and return the status of each application or service.
1.5 Managing Services on Red Hat
let’s start by looking at a Red Hat init script: take a look at the postfix script located in /etc/init.d. Let’s look at the top of the script using the head command:
$ sudo head –n 5 /etc/init.d/postfix
This will show the first five lines of the /etc/init.d/postfix file, as you can see in Listing 5-4.
#!/bin/bash
# postfix Postfix Mail Transfer Agent
# chkconfig: 2345 80 30
# description: Postfix is a Mail Transport Agent, which is the program \
# that moves mail from one machine to another.
On line 3 you see chkconfig: 2345 80 30. This information is used by a program called chkconfig to set up the symbolic links to the /etc/rc.d/rc2.d, /etc/rc.d/rc3.d, /etc/rc.d/rc4.d, and /etc/rc.d/rc5.d directories you saw earlier in this chapter. In this case, the Postfix script starts on runlevels 2, 3, 4, and 5 (as indicated by 2345), runs with a priority of 80, and stops with a priority of 30. The chkconfig command creates the symbolic links (often called symlinks) to the /etc/init.d/postfix script in the /etc/rc.d/rcn.d/ directories with the S80 and K30 prefixes. The #description line used by chkconfig is also important. Both the ckconfig
and description definitions must be present, or an error will result.
1.5.1 Starting and Stopping Services at Boot and Shutdown
to change service runlevels in Red Hat is to use the chkconfig command.
Option Description
--list Gives information pertaining to a service if that service is specified. Otherwise, all services
are listed, with information given as to whether the service is started or stopped in each runlevel.
--add Adds a service to chkconfig management. An entry in each runlevel is created according to the
information found in the init script.
--del Removes the service from chkconfig management. The symlinks in the /etc/rcn.d directories are
removed.
--level Manages services for particular levels combined with the name of the service and the setting you
wish (e.g., chkconfig -- level 25 httpd off).
$ sudo /sbin/chkconfig -- list
If you intend to have the Postfix mail server added to the default runlevels according to the /etc/rc.d/init.d/postfix script, let chkconfig manage it for you by entering the following command:
$ sudo chkconfig postfix on
This turns the service on for the runlevels specified in the init.d script through chkconfig: 2345 80 30 by default. You can also manually specify with chkconfig the exact runlevels you wish Postfix to start in. For example:
$ sudo chkconfig -- level 35 postfix on
This command will turn Postfix on at runlevels 3 and 5. When your host is rebooted, it will now start the Postfix service in either runlevel 3 or 5, but not in 2 or 4, unless specifically instructed to do so.
If you wish to turn a service off so it doesn’t start when your host is restarted, you would issue the following command:
$ sudo chkconfig postfix off
1.5.2 Starting and Stopping running Services
All of the scripts located in the /etc/init.d directory are generally executable. Each script can also usually take one of the following arguments: start, stop, restart, reload, or status. To see how to restart the Postfix service, take a look at the following example:
$ sudo /etc/init.d/postfix restart
The following command line will reload Postfix (this will reread the configuration files, and the processes will restart as soon as they can):
1.6 Shutting Down and Rebooting Your Linux Host
1.6.1 Shutting Down
$ sudo shutdown –h now
$ sudo init 0
1.6.2 Rebooting
$ sudo shutdown –r now
$ sudo init 6
title CentOS (2.6.18-238.19.1.el5)
password -- md5 $1$3yQFp$MEDEglsxOvuTWzWaztRly --菜单密码,输入菜单密码才能启动
root (hd0,2)
kernel /vmlinuz-2.6.18-238.19.1.el5 ro root=LABEL=/ rhgb quiet
initrd /initrd-2.6.18-238.19.1.el5.img
title CentOS (2.6.18-238.12.1.el5)
root (hd0,2)
kernel /vmlinuz-2.6.18-238.12.1.el5 ro root=LABEL=/ rhgb quiet
initrd /initrd-2.6.18-238.12.1.el5.img
1.3 Configuring init
Red Hat generally starts in runlevel 5 if you have a GUI console installed or runlevel 3 for command line only. Red Hat has the following runlevels:
• Runlevel 0: Shuts down the host and brings the system to a halt
• Runlevel 1: Runs in single- user (maintenance) mode, command console, no network
• Runlevel 2: Is unassigned
• Runlevel 3: Runs in multiuser mode, with network, and starts level 3 programs
• Runlevel 4: Is unassigned
• Runlevel 5: Runs in multiuser mode, with network, X Windows (KDE, GNOME), and starts level 5 programs.
• Runlevel 6: Reboots the host
On most distributions, including Red Hat, the /sbin/init tool is configured using the /etc/inittab file. The init tool uses a series of scripts and directories under the /etc/rc.d directory named rc.x where x is the runlevel; for example, the /etc/rc.d/rc3.d directory stores the applications in runlevel 3.
$ man inittab
To change the default runlevel, which is the most common reason for editing the inittab file, you change the initdefault line. Here, the default runlevel is 5:
id:5:initdefault:
To change the default runlevel from 5 to 3, you replace the number 5 with 3 like so:
id:3:initdefault:
You can use the telinit or init command to switch between runlevels. First, work out what runlevel you
are at now by using the runlevel command, which will return a message showing the previous and current runlevel, as shown in this example:
$ sudo runlevel
N 5
$ sudo telinit 3
$ sudo init 3
1.4 Managing Services
You can examine what services will start in each runlevel by listing the contents of the /etc/rc.d/rcn.d directories (where n is a runlevel between 0 and 6). Let’s look at part of the contents of the /etc/rc.d/rc3.d directory.
$ ls -l /etc/rc.d/rc3.d/
lrwxrwxrwx 1 root root 16 2008-04- 29 06:58 K02httpd -> ../init.d/httpd
lrwxrwxrwx 1 root root 17 2008-04- 29 07:31 K30postfix -> ../init.d/postfix
lrwxrwxrwx 1 root root 20 2007-11- 09 04:48 K50netconsole -> ../init.d/netconsole
lrwxrwxrwx 1 root root 19 2008-08- 19 06:58 S08ip6tables -> ../init.d/ip6tables
lrwxrwxrwx 1 root root 18 2008-08- 19 06:58 S08iptables -> ../init.d/iptables
lrwxrwxrwx 1 root root 17 2007-11- 09 04:48 S80postfix -> ../init.d/postfix
You can see that all the files in the /etc/rc.d/rc3.d directory are symbolic links to indi-vidual init.d scripts, which are found in /etc/rc.d/init.d/ directory contain the instructions about how to start, stop, and return the status of each application or service.
1.5 Managing Services on Red Hat
let’s start by looking at a Red Hat init script: take a look at the postfix script located in /etc/init.d. Let’s look at the top of the script using the head command:
$ sudo head –n 5 /etc/init.d/postfix
This will show the first five lines of the /etc/init.d/postfix file, as you can see in Listing 5-4.
#!/bin/bash
# postfix Postfix Mail Transfer Agent
# chkconfig: 2345 80 30
# description: Postfix is a Mail Transport Agent, which is the program \
# that moves mail from one machine to another.
On line 3 you see chkconfig: 2345 80 30. This information is used by a program called chkconfig to set up the symbolic links to the /etc/rc.d/rc2.d, /etc/rc.d/rc3.d, /etc/rc.d/rc4.d, and /etc/rc.d/rc5.d directories you saw earlier in this chapter. In this case, the Postfix script starts on runlevels 2, 3, 4, and 5 (as indicated by 2345), runs with a priority of 80, and stops with a priority of 30. The chkconfig command creates the symbolic links (often called symlinks) to the /etc/init.d/postfix script in the /etc/rc.d/rcn.d/ directories with the S80 and K30 prefixes. The #description line used by chkconfig is also important. Both the ckconfig
and description definitions must be present, or an error will result.
1.5.1 Starting and Stopping Services at Boot and Shutdown
to change service runlevels in Red Hat is to use the chkconfig command.
Option Description
--list Gives information pertaining to a service if that service is specified. Otherwise, all services
are listed, with information given as to whether the service is started or stopped in each runlevel.
--add Adds a service to chkconfig management. An entry in each runlevel is created according to the
information found in the init script.
--del Removes the service from chkconfig management. The symlinks in the /etc/rcn.d directories are
removed.
--level Manages services for particular levels combined with the name of the service and the setting you
wish (e.g., chkconfig -- level 25 httpd off).
$ sudo /sbin/chkconfig -- list
If you intend to have the Postfix mail server added to the default runlevels according to the /etc/rc.d/init.d/postfix script, let chkconfig manage it for you by entering the following command:
$ sudo chkconfig postfix on
This turns the service on for the runlevels specified in the init.d script through chkconfig: 2345 80 30 by default. You can also manually specify with chkconfig the exact runlevels you wish Postfix to start in. For example:
$ sudo chkconfig -- level 35 postfix on
This command will turn Postfix on at runlevels 3 and 5. When your host is rebooted, it will now start the Postfix service in either runlevel 3 or 5, but not in 2 or 4, unless specifically instructed to do so.
If you wish to turn a service off so it doesn’t start when your host is restarted, you would issue the following command:
$ sudo chkconfig postfix off
1.5.2 Starting and Stopping running Services
All of the scripts located in the /etc/init.d directory are generally executable. Each script can also usually take one of the following arguments: start, stop, restart, reload, or status. To see how to restart the Postfix service, take a look at the following example:
$ sudo /etc/init.d/postfix restart
The following command line will reload Postfix (this will reread the configuration files, and the processes will restart as soon as they can):
$ sudo service postfix reload
Reloading postfix: [ OK ]1.6 Shutting Down and Rebooting Your Linux Host
1.6.1 Shutting Down
$ sudo shutdown –h now
$ sudo init 0
1.6.2 Rebooting
$ sudo shutdown –r now
$ sudo init 6
Notepad++で文字化け
インストールした直後のデフォルト状態だと日本語の文字が文字化けするようです。
(なんか、どこかのバージョンで日本語対応になったと思ってんだけど気のせいかな?)
対応は簡単で以下のような設定を行えばOKです。
1. [設定]-[スタイル設定]をメニューから選択
2. 表示されるダイアログから以下の3項目を設定します。
フォント名: 日本語が表示可能なフォントを選択
フォント名を他のスタイルにも適用:チェックする
フォントサイズを他のスタイルにも適用:チェックする
2012年3月6日星期二
linux下查看进程内存使用情况(转)
动态查看一个进程的内存使用
- 1、top命令
- top -d 1 -p pid [,pid ...] //设置为delay 1s,默认是delay 3s
- 如果想根据内存使用量进行排序,可以shift + m(Sort by memory usage)
静态查看一个进程的内存使用
- 1、pmap命令
- pmap pid
- 2、ps命令
- ps aux|grep process_name
- 3、查看/proc/process_id/文件夹下的status文件
- Name: php
- State: R (running)
- SleepAVG: 0%
- Tgid: 21574
- Pid: 21574
- PPid: 10005
- TracerPid: 0
- Uid: 1000 1000 1000 1000
- Gid: 100 100 100 100
- FDSize: 256
- Groups: 16 100
- VmPeak: 161740 kB
- VmSize: 161740 kB
- VmLck: 0 kB
- VmHWM: 107144 kB
- VmRSS: 107144 kB
- VmData: 106192 kB
- VmStk: 84 kB
- VmExe: 5588 kB
- VmLib: 7884 kB
- VmPTE: 268 kB
- Threads: 1
- SigQ: 0/69632
- SigPnd: 0000000000000000
- ShdPnd: 0000000000000000
- SigBlk: 0000000000000000
- SigIgn: 0000000000001000
- SigCgt: 00000001818040a7
- CapInh: 0000000000000000
- CapPrm: 0000000000000000
- CapEff: 0000000000000000
- Cpus_allowed: 00000000,00000000,00000000,0000000f
- Mems_allowed: 1
- 任务虚拟地址空间的大小 VmSize
- 应用程序正在使用的物理内存的大小 VmRSS
2012年3月4日星期日
CentOS完全禁用IPV6
1.查看IPV6模块加载情况
[root@localhost ~]# lsmod | grep ipv6
ipv6 270561 44 ip6t_REJECT,cnic
xfrm_nalgo 13381 1 ipv6
在其中加入下面这一行,
install ipv6 /bin/true
在其中加入下面这一行,
install ipv6 /bin/true
[root@localhost ~]# lsmod | grep ipv6
ipv6 270561 44 ip6t_REJECT,cnic
xfrm_nalgo 13381 1 ipv6
2.禁用IPV6
- CentOS5.6
在其中加入下面这一行,
install ipv6 /bin/true
- CentOS6
在其中加入下面这一行,
install ipv6 /bin/true
重启系统
3.确认结果
[root@localhost ~]# lsmod | grep ipv6
2012年3月3日星期六
CentOS6安装JDK6
在终端中输入“./jdk-6u31-linux-i586-rpm.bin”执行解压及安装操作。此时,在“/usr”目录下,新增一个“/java”目录。接下来,设置Java的环境变量。
- 用文本编辑器打开/etc/profile(说明:根目录下的/etc/目录,其中的profile文件)
- 在profile文件末尾加入如下字符串
JAVA_HOME=/usr/java/jdk1.6.0_31
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME
export PATH
export CLASSPATH
至此,新的JDK环境安装配置完成。
接下来运行下面命令是配置生效
source /etc/profile
教你如何查看linux版本(转)
1. 查看内核版本命令:
1) [root@localhost ~]# cat /proc/version
Linux version 2.6.18-238.12.1.el5 (mockbuild@builder10.centos.org) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-50)) #1 SMP Tue May 31 13:23:01 EDT 2011
Linux version 2.6.18-238.12.1.el5 (mockbuild@builder10.centos.org) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-50)) #1 SMP Tue May 31 13:23:01 EDT 2011
2) [root@localhost ~]# uname -a
Linux localhost.localdomain 2.6.18-238.12.1.el5 #1 SMP Tue May 31 13:23:01 EDT 2011 i686 i686 i386 GNU/Linux
Linux localhost.localdomain 2.6.18-238.12.1.el5 #1 SMP Tue May 31 13:23:01 EDT 2011 i686 i686 i386 GNU/Linux
3) [root@localhost ~]# uname -r
2.6.18-238.12.1.el5
2.6.18-238.12.1.el5
2. 查看linux版本:
1) 登录到服务器执行 lsb_release -a ,即可列出所有版本信息,例如:
[root@localhost ~]# [root@q1test01 ~]# lsb_release -a
LSB Version: :core-4.0-ia32:core-4.0-noarch:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-ia32:printing-4.0-noarch
LSB Version: :core-4.0-ia32:core-4.0-noarch:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-ia32:printing-4.0-noarch
Distributor ID: CentOS
Description: CentOS release 5.6 (Final)
Release: 5.6
Codename: Final
注:这个命令适用于所有的linux,包括Redhat、SuSE、Debian等发行版。
2) 登录到linux执行cat /etc/issue,例如如下:
[root@localhost ~]# cat /etc/issue
CentOS release 5.6 (Final)
CentOS release 5.6 (Final)
Kernel \r on an \m
3) 登录到linux执行cat /etc/redhat-release ,例如如下:
[root@localhost ~]# cat /etc/redhat-release
CentOS release 5.6 (Final)
CentOS release 5.6 (Final)
4) 登录到linux执行rpm -q redhat-release ,例如如下:
[root@q1test01 ~]# rpm -q redhat-release
订阅:
博文 (Atom)