Linux ~ 服务管理。

Linux ~ 服务管理。



服务简介与分类。

在这里插入图片描述



启动与自启动。
  • 服务启动。

在当前系统中让服务运行,并提供功能。

  • 服务自启动。

让服务在系统开机或重启后,随着系统的启动而自动启动服务。



查看已安装的服务。
RMP 包默认安装的服务。
  • chkconfig --list

查看服务自启动状态,可以看到所有 RPM 包安装的服务。



源码包安装的服务。
  • 查看服务的安装位置,一般是 /usr/local 下。


区别。

RPM 包安装服务和源码包安装服务的区别就是安装位置的不同。

  • 源码包安装在指定位置,一般是 /usr/local 下。

  • RPM 包安装在默认位置。(开发人员遵守)。

配置文件在 /etc/ 下。
启动脚本在 /etc/rc.d/init.d/ 下。
-e 删除选项,一起删除。



RPM 包安装服务的管理。

独立服务的管理。
[root@localhost ~]# ll /etc/init.d -d
lrwxrwxrwx. 1 root root 11 Feb 18 07:43 /etc/init.d -> rc.d/init.d
/etc/init.d/ or /etc/rc.d/init.d/启动脚本位置。
/etc/sysconfig/初始化环境配置文件位置。
/etc/配置文件位置。
/etc/xinetd.conf/xinetd 配置文件。
/etc/xinetd.d/基于 xinetd.d 服务的启动脚本。
/var/lib/服务产生的数据放在这里。
/var/log/日志。


独立服务的启动。
  • /etc/init.d/独立服务名 start | stop | status | restart

  • service 独立服务名 start | stop | status | restart

/etc/init.d/ 太长,RedHat 为我们提供 service,ta 会自动去 /etc/init.d/ 下找到服务名。其他 Linux 发行版本可能没有。

service --status-all



独立服务的自启动。
  • chkconfig [–level 运行级别] [独立服务名] [on | off]

–level 默认 2345。

[root@localhost ~]# chkconfig | grep sshd
sshd           	0:off	1:off	2:on	3:on	4:on	5:on	6:off
[root@localhost ~]# chkconfig --level 2345 sshd on
  • 修改 /etc/rc.d/rc/local 文件。
[root@localhost ~]# ll /etc/rc.local 
lrwxrwxrwx. 1 root root 13 Feb 18 07:44 /etc/rc.local -> rc.d/rc.local

在系统启动输入用户名密码之前执行其中的命令。

在其中写入要执行的命令。

所以也可以管理源码包。

/etc/rc.d/init.d/sshd start

[root@localhost ~]# vim /etc/rc.d/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

touch ——> 摸。重新理解 ——>

如果文件不存在,新建。
如果文件存在,修改时间。

  • 使用 ntsysv 命令管理自启动。

图形界面。(类似 setup)。RedHat 专有。

在这里插入图片描述



基于 xinetd 服务管理。
安装 xinetd 和 telnet。

telnet ——> 不安全。现在使用 ssh。

[root@localhost ~]# yum install xinetd

再次使用 chkconfig 会显示

xinetd based services:
	chargen-dgram: 	off
	chargen-stream:	off
	daytime-dgram: 	off
	daytime-stream:	off
	discard-dgram: 	off
	discard-stream:	off
	echo-dgram:    	off
	echo-stream:   	off
	tcpmux-server: 	off
	time-dgram:    	off
	time-stream:   	off

  • 所有基于 xinetd 的服务不直接占用内存,由 xinetd 服务管理调用。


telnet。
[root@localhost ~]# yum install telnet
[root@localhost ~]# yum install telnet-server
[root@localhost ~]# chkconfig | grep telnet
	telnet:        	off

不能直接使用 service 管理 telnet。
因为 ta 是基于 xinetd 的服务,由 xinetd 管理。

[root@localhost ~]# service telnet restart
telnet: unrecognized service
[root@localhost ~]# vim /etc/xinetd.d/telnet
    disable         = no					# 服务启动。
# default: on
# description: The telnet server serves telnet sessions; it uses \
#       unencrypted username/password pairs for authentication.
service telnet		# 服务的名称。
{
        flags           = REUSE		# 设定 TCP/IP socket 可重用。
        socket_type     = stream	# 允许 TCP 协议数据包。
        wait            = no				# 允许多个连接同时连接。
        user            = root			# 启动服务的用户为 root。
        server          = /usr/sbin/in.telnetd	# 服务的启动程序。
        log_on_failure  += USERID		# 登录失败后,记录用户 id。
        disable         = yes					# 服务不启动。
}

~                                                                                 
~                                                                                 
"/etc/xinetd.d/telnet" 14L, 305C                                1,1
  • 重启 xinetd 服务。
[root@localhost ~]# service xinetd restart
Stopping xinetd:                                           [FAILED]
Starting xinetd:                                           [  OK  ]

[root@localhost ~]# netstat -tlun

23 端口 ok。



xinetd 服务自启动。
  • chkconfig tenet on

  • ntsysv

xinet 的启动和自启动相同状态。



源码包安装服务的管理。

源码包启动。
  • 使用绝对路径,调用启动脚本来启动。不同的源码包启动脚本不同。可以查看源码包的安装说明,查看启动脚本的方法。


源码包自启动。
[root@localhost ~]# vim /etc/rc.d/rc.local

中加入

/usr/local/apache2/bin/apachectl start



让源码包服务能被管理命令(service)管理自启动。
  • 让源码包的 apache 服务能被 service 命令管理启动。

ln -s /usr/local/apache2/bin/apachectl /etc/init.d/apache

// service 命令归根结底就是去 /etc/init.d/ 下查找命令。



让源码包服务能被 chkconfig 与 ntsysv 命令管理自启动。
[root@localhost ~]# vim /etc/init.d/sshd

# 符号不能删除。

# chkconfig: 2345 55 25
# 指定 sshd 脚本可以被 chkconfig 命令管理。

config: 运行级别 启动顺序 关闭顺序

在启动级别 3 下的运行级别的
启动顺序(Kxx)和关闭顺序(Sxx)。

[root@localhost ~]# vim /etc/rc.d/rc3.d/
K10saslauthd         S07iscsid            S25netfs
K50vsftpd            S08ip6tables         S26udev-post
K74ntpd              S08iptables          S55sshd
K75ntpdate           S10network           S56xinetd
K87multipathd        S11auditd            S80postfix
K87restorecond       S12rsyslog           S90crond
K89netconsole        S13iscsi             S99local
K89rdisc             S15mdmonitor         
S02lvm2-monitor      S25blk-availability  
#!/bin/bash
#
# sshd          Start up the OpenSSH server daemon
#
# chkconfig: 2345 55 25
# description: SSH is a protocol for secure remote shell access. \
#              This service starts up the OpenSSH server daemon.
#
# processname: sshd
# config: /etc/ssh/ssh_host_key
# config: /etc/ssh/ssh_host_key.pub
# config: /etc/ssh/ssh_random_seed
# config: /etc/ssh/sshd_config
# pidfile: /var/run/sshd.pid

### BEGIN INIT INFO

  • 加入 chkconfig。
chkconfig --add sshd

chkconfig --list

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lyfGeek

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值