关键词:service chkconfig kudzu nis nfs rpc s99 rc.local
为什么/etc/init.d/目录和/etc/rc.d/init.d/目录完全相同?
因为/etc/ini.d/是/etc/rc.d/init.d/的链接
[root@localhost etc]# ls -l init.d
lrwxrwxrwx 1 root root 11 Nov 3
00:32 init.d ->
rc.d/init.d |
/etc/init.d下的启动脚本只是定义的地方,不参与启动,真正参与启动的是rc.xd/目录下的S打头的脚本
即只有以SXX,内核才在启动时去读他
rcx.d下的启动脚本/非启动脚本都是init.d目录下启动脚本的链结
[root@localhost rc3.d]# ls -l
total 256
lrwxrwxrwx 1 root root 13 Nov 3
00:36 K01yum -> ../init.d/yum
lrwxrwxrwx 1 root root 24 Nov 3
00:37 K02NetworkManager ->
../init.d/NetworkManager
lrwxrwxrwx 1 root root 34 Nov 3
00:37 K02NetworkManagerDispatcher ->
../init.d/NetworkManagerDispatcher
lient
lrwxrwxrwx 1 root root 15 Nov 3
00:39 K15httpd -> ../init.d/httpd
lrwxrwxrwx 1 root root 16 Nov 11 15:47 K36mysqld
-> ../init.d/mysqld
lrwxrwxrwx 1 root root 17 Nov 3
00:36 K50netdump -> ../init.d/netdump
lrwxrwxrwx 1 root root 16 Nov 3
01:20 K50vsftpd -> ../init.d/vsftpd
lrwxrwxrwx 1 root root 18 Nov 3
00:35 S08iptables
-> ../init.d/iptables
lrwxrwxrwx 1 root root 14 Nov 3
00:36 S55sshd ->
../init.d/sshd
lrwxrwxrwx 1 root root 16 Nov 3
01:59 S56xinetd ->
../init.d/xinetd
lrwxrwxrwx 1 root root 18 Nov 3
00:36 S80sendmail -> ../init.d/sendmail
lrwxrwxrwx 1 root root 13 Nov 3
00:35 S85gpm -> ../init.d/gpm
lrwxrwxrwx 1 root root 15 Nov 3
00:36 S90crond -> ../init.d/crond
lrwxrwxrwx 1 root root 13 Nov 3
00:41 S90xfs -> ../init.d/xfs
lrwxrwxrwx 1 root root 19 Nov 3
00:34 S98haldaemon -> ../init.d/haldaemon
lrwxrwxrwx 1 root root 11 Nov 3
00:33 S99local ->
../rc.local
rc.local是最后一个启动的脚本(所以在rc3.d中是S99打头文件的链结),通常把用户自定义的启动脚本写入其中
lrwxrwxrwx 1 root root 11
Nov 3 00:33 S99local ->
../rc.local |
[root@localhost rc3.d]# more S99local
#!/bin/sh
#
# This script will be executed *after*
all the other init scripts.
# You can put your own
initialization stuff in here if you don't
# want to do the full Sys V style init stuff. |
solaris里没有rc.local文件
一个很好用的开通关闭SXX、KXX脚本的工具——/sbin/chkconfig
但只针对httpd,mysqld 这些系统应用,自编的应用不行
[root@localhost rc3.d]# /sbin/chkconfig
chkconfig version 1.3.20 - Copyright (C) 1997-2000 Red Hat,
Inc.
This may be freely redistributed under the terms of the GNU Public
License.
usage: chkconfig --list
[name]
chkconfig --add
chkconfig --del
chkconfig [--level ]
|
一个简单的开机启动rc3.d httpd的命令
[root@localhost rc3.d]# ls
K15httpd
K36mysqld
K89netplugd
S13portmap
S33nifd
S95anacron
K20nfs
K50netdump
K89rdisc
S14nfslock
S34mDNSResponder S95atd
K20rwhod
K50tux
K94diskdump
S15mdmonitor
S44acpid
S97messagebus
|
[root@localhost rc3.d]#
/sbin/chkconfig --level 3 httpd on |
[root@localhost rc3.d]# ls
K05saslauthd
K35smb
K74ntpd
S09pcmcia
S25netfs
S85gpm
S99local
K10dc_server
K35vncserver
K85mdmpd
S10network
S26apmd
S85httpd
K10psacct
K35winbind
K89named
S12syslog
S28autofs
S90crond |
总结:开机自动启动自定义service两种方法
编写启动脚本(shell)
以SXX名称放入rc3.d或rc5.d
最标准的方法是:脚本在init下建立,然后ln –s
到rc3.d,rc5.d
-
法二:在rc.local(也是个shell)中,写入启动语句
一个手动编制开机自动启动http的例子
不知道怎么回事,安装了httpd,mysqld,但开机总是没有启动,用chkconfig也没用,所以自己编了一个script(当时是简单的一个脚本,不是system
V那种格式的)
root@mac-home macg]# vi server.sh
:
if [ -f /var/run/httpd.pid
]
then
cat /var/run/httpd.pid
else
/etc/init.d/httpd start
fi
if [ -f /var/run/mysqld/mysqld.pid ]
then
cat /var/run/mysqld/mysqld.pid
else
/etc/init.d/mysqld
start
|
[root@mac-home macg]# chmod +x server.sh |
以S99xxx的名字放入/etc/rc.d/rc3.d (如果是以level
3启动的话)
[root@mac-home macg]# cp server.sh
/etc/rc.d/rc3.d/S99apache-mysql
|
/etc/rc.local只执行全路径的,并且不带任何环境变量的命令
把一个sh程序放到rc.local里,发觉每次重起都不执行,ps -ef里面看不见
[root@FW ~]# vi /etc/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init
scripts.
# You can put your own initialization stuff in here if you
don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
/etc/openvpn/openvpn-startup.sh
这个rc.local里的指令虽然是全路径的,但openvpn-startup.sh内却含有不是全路径的指令和环境变量
|
[root@FW ~]# vi /etc/openvpn/openvpn-startup.sh
#!/bin/sh
DIR=/etc/openvpn
# load TUN/TAP kernel module
modprobe tun
openvpn --cd $DIR --daemon
--config static-lfc.conf
openvpn --cd $DIR --daemon
--config static-zhao.conf
#openvpn --cd $DIR --daemon --config vpn2.conf
#openvpn --cd $DIR --daemon --config vpn2.conf
|
解决:
1。去掉变量
2。用全路径
/usr/local/sbin/openvpn --cd
/etc/openvpn --daemon --config static-lfc.conf
/usr/local/sbin/openvpn --cd
/etc/openvpn --daemon --config static-zhao.conf
|
重起后ps -ef能看到
[root@FW ~]# ps -ef
UID
PID PPID C STIME
TTY
TIME CMD
root
2519
1 0 10:45
?
00:00:00 /usr/sbin/atd
dbus
2528
1 0 10:45
?
00:00:00 dbus-daemon-1 --system
root
2537
1 0 10:45
?
00:00:00 hald
root
2648
1 0 10:46
?
00:00:00 /usr/local/sbin/openvpn --cd /etc/openvpn --daemon
--config static-lfc.conf |
Service 安全
你可能只需要其中的ssh,telnet,tftp,其他的都关掉
其它的类如 talk , ntalk, imap , pop-2, pop-3, finger , auth , etc.
除非你真的想用它。否则统统关闭
下面一些服务最好禁止启动(不过具体情况具体决定):
snmpdx
lpsched(LP
print service)
nscd (Name
Service Cache Daemon)
sendmail
Keyserv
rpcbind
建议在DMZ中不要运行NFS服务
/etc/rc3.d/S88nfs.server
/etc/rc2.d/S90nfs.client
关掉一些nfs相关的服务如下服务:
nfsd
mountd
rpc.boot