目录
一、服务简介与分类
1.服务的分类
2.查询已经安装的服务和区分服务
chkconfig --list
命令:chkconfig --list [服务名]
子选项:
--list:列出所有RPM包默认安装服务的自启动状态。
级别:
0 (关机) 1(单用户模式) 2(网络维护模式)
3 (字符界面) 4 (保留) 5 (图形化界面) 6(重启)
二、RPM包默认安装的服务器管理
1.独立服务器管理
1)独立服务的启动管理
使用/etc/init.d/目录中的启动脚本启动服务:
【】# /etc/init.d/httpd start
使用service命令来启动独立的服务:
【】# service httpd start
2)独立服务的自启动管理
使用chkconfig服务自启动管理命令:
【】# chkconfig [--level运行级别] [独立服务名] [on|off]
修改/etc/rc.d/rc.local文件设置服务自启动:(系统开启时系统会读其中可执行语句)
【】# vim/etc/rc.d/rc.local 或者/etc/rc.local
使用ntsysv命令管理自启动
ntsysv [-- level运行级别]
- -level:可以指定设定自启动的运行级别
上下键:在不同服务之间移动。
空格键:选定或取消选定。*为自启动。
tab键:在不同项目之间切换。
F1键:服务详情。
2.基于xinetd服务的管理
1)基于xinetd服务的启动
【】# yum-y install xinetd
用rsync服务来举例,rsync服务是用来进行数据备份的工具,使用873端口。
【】# vim/etc/xinetd.d/rsync
# default: off
# description:Thersyncserver isa good addition to an ftp server,as it \
# allowscrcchecksumming etc.
servicersync #服务名称为rsync。
{disable = yes #服务不启动。
flags = REUSE #标志为REUSE设定TCP/IP socket可重用。
socket_type = stream#套接字类型。
wait = no #允许多个连接同时连接。
user = root #启动服务的用户为root。
server = /usr/bin/rsync#服务的启动程序。
log_on_failure += USERID#登录失败后,记录用户的ID。
}
只需要修改配种文件中的disable = yes 将yes修改为no,然后重启服务即可
(service xinetd restart)。
2)基于xinetd服务的自启动
使用chkconfig命令管理自启动
使用ntsysv命令管理自启动
【】# chkconfig rsync(服务名) on(on|off)
3、源码包安装的服务管理
1.源码包服务启动管理:
/usr/local/apache2/bin/apachectlstart|stop|restart|...
2.源码包服务的自动管理
【】# vim/etc/rc.d/rc.local
3.让源码包服务被服务管理命令识别
接下来我们试着让源码包安装的apache变为和RPM包安装的apache一样,可以被service、chkconfig、ntsysv命令识别。
例:
1)卸载RPM包的apache服务,确保实验准确性。
【】# yum-y remove httpd #卸载RPM包apache避免影响实验效果。
【】# service httpd restart
httpd:未被识别的服务 #确认已经卸载完成。
2)安装源码包apache服务,并启动:
首先将lamp复制到/目录下,然后挂载光盘。
【】# cp -a/media/20150527_165105/lamp/* /lamp/
换DVD1光盘
【】# mount /dev/sr0 /mnt/
mount: block device/dev/sr0 is write-protected, mounting read-only
【】# yum-y install gcc* pcre pcre-devel
【】# cd /lamp/
【】# tar -xvfapr-1.4.6.tar.gz
【】# cd apr-1.4.6
【】# ./configure
【】#make &&makeinstall
【】# cd ..
【】# tar -xvfapr-util-1.4.1.tar.gz
【】# cd apr-util-1.4.1
【】# ./configure-with-apr=/usr/local/apr
【】# make &&makeinstall
【】# cd ..
【】# tar -xvf pcre-8.10.tar.gz
【】# cd pcre-8.10
【】# ./configure
【】# make &&makeinstall
【】# cd ..
【】# tar -xvf httpd-2.4.7.tar.gz
【】# cd httpd-2.4.7[root@localhost httpd-2.4.7]# ./configure--prefix=/usr/local/apache2
【】# make &&makeinstall
【】# /usr/local/apache2/bin/apachectlstart
AH00558: httpd:Could not reliably determinetheserver's fully qualified domain name, using localhost.localdomain. Set the'ServerName' directive globally to suppress this
message
【】# netstat -tlun | grep 80
tcp 0 0 :::80 :::* LISTEN
#启动源码包apache,查看端口是否启动。
3)源码包apache服务被service命令管理启动
[root@localhost ~]# ln -s /usr/local/apache2/bin/apachectl/etc/init.d/apache
#service命令其实只是在/etc/init.d/目录中查找是否有服务启动脚本,所以我们只需要做个软连接把源码包的启动脚本链到/etc/init.d/目录中,就能被
service命令管理了。
【】# serviceapacherestart
AH00558: httpd:Could not reliably determinetheserver's fully qualified domain name, using localhost.localdomain. Set the'ServerName' directive globally to suppress this
message
#测试service命令,restart和start生效。
4.chkconfig命令管理自启动
【】# vim/etc/init.d/apache
#修改源码包apache启动脚本(此文件是软连接,所以修改的还是源码包的启动脚本。)
#!/bin/sh
#chkconfig:35 86 76
#description:source packageapache
【】# chkconfig --add apache
【】# chkconfig --list | grep apache
apache 0:关闭 1:关闭 2:关闭 3:启用 4:关闭 5:启用 6:关闭
#虽然RPM包的apache已经删除了,但是chkconfig命令可以管理源码包apache。
5.ntsysv命令管理源码包apache
nesysv命令其实是和chkconfig命令使用同样的管理机制,也就是说ntsysv已经可以对源码包的apache进行启动管理了。