0
点赞
收藏
分享

微信扫一扫

systemd管理服务

什么是systemd

systemd即为system daemon守护进程,systemd主要解决上文的问题而诞生,systemd的目标是,为系统的启动和管理提供一套完整的解决方案。(系统的守护进程)

systemd管理服务_nginx

systemd的优势

1.最新系统都采用systemd管理(RedHat7,CentOS7,Ubuntu15...) 2.CentOS7 支持开机并行启动服务,显著提高开机启动效率 3.CentOS7关机只关闭正在运行的服务,而CentOS6,全部都关闭一次。 4.CentOS7服务的启动与停止不在使用脚本进行管理,也就是/etc/init.d下不在有脚本。 5.CentOS7使用systemd解决原有模式缺陷,比如原有service不会关闭程序产生的子进程。

systemd相关配置文件

# 系统中所有服务启动脚本存放路径
C7:
/usr/lib/systemd/system/
nginx.service

C6:
/etc/init.d/

# 系统运行级别相关目录
C7:
/etc/systemd/system

C6:
ll /etc/rc*.d -d
lrwxrwxrwx. 1 root root 10 May 710:46 /etc/rc0.d -> rc.d/rc0.d
lrwxrwxrwx. 1 root root 10 May 710:46 /etc/rc1.d -> rc.d/rc1.d
lrwxrwxrwx. 1 root root 10 May 710:46 /etc/rc2.d -> rc.d/rc2.d
lrwxrwxrwx. 1 root root 10 May 710:46 /etc/rc3.d -> rc.d/rc3.d
lrwxrwxrwx. 1 root root 10 May 710:46 /etc/rc4.d -> rc.d/rc4.d
lrwxrwxrwx. 1 root root 10 May 710:46 /etc/rc5.d -> rc.d/rc5.d
lrwxrwxrwx. 1 root root 10 May 710:46 /etc/rc6.d -> rc.d/rc6.d

# 默认运行级别需要开机自启的服务存放目录
C7:
/etc/systemd/system/multi-user.target.wants/
auditd.service -> /usr/lib/systemd/system/auditd.service
crond.service -> /usr/lib/systemd/system/crond.service
irqbalance.service -> /usr/lib/systemd/system/irqbalance.service
NetworkManager.service -> /usr/lib/systemd/system/NetworkManager.service
nfs-client.target -> /usr/lib/systemd/system/nfs-client.target
nginx.service -> /usr/lib/systemd/system/nginx.service
postfix.service -> /usr/lib/systemd/system/postfix.service
remote-fs.target -> /usr/lib/systemd/system/remote-fs.target
rhel-configure.service -> /usr/lib/systemd/system/rhel-configure.service
rpcbind.service -> /usr/lib/systemd/system/rpcbind.service
rsyslog.service -> /usr/lib/systemd/system/rsyslog.service
sshd.service -> /usr/lib/systemd/system/sshd.service
sysstat.service -> /usr/lib/systemd/system/sysstat.service
tuned.service -> /usr/lib/systemd/system/tuned.service
vmtoolsd.service -> /usr/lib/systemd/system/vmtoolsd.

C6:
/etc/rc3.d/
K01smartd -> ../init.d/smartd
K10psacct -> ../init.d/psacct
K10saslauthd -> ../init.d/saslauthd
K15svnserve -> ../init.d/svnserve
K50netconsole -> ../init.d/netconsole
K74ntpd -> ../init.d/ntpd
K75ntpdate -> ../init.d/ntpdate
K75quota_nld -> ../init.d/quota_nld
K87restorecond -> ../init.d/restorecond
K89rdisc -> ../init.d/rdisc
K99rngd -> ../init.d/rngd
S01sysstat -> ../init.d/sysstat
S02lvm2-monitor -> ../init.d/lvm2-monitor
S08ip6tables -> ../init.d/ip6tables
S08iptables -> ../init.d/iptables
S10network -> ../init.d/network
S11auditd -> ../init.d/auditd
S12rsyslog -> ../init.d/rsyslog
S13cpuspeed -> ../init.d/cpuspeed
S13irqbalance -> ../init.d/irqbalance
S15mdmonitor -> ../init.d/mdmonitor
S20kdump -> ../init.d/kdump
S22messagebus -> ../init.d/messagebus
S25blk-availability -> ../init.d/blk-availability
S25netfs -> ../init.d/netfs
S26acpid -> ../init.d/acpid
S26haldaemon -> ../init.d/haldaemon
S26udev-post -> ../init.d/udev-post
S55sshd -> ../init.d/sshd
S80postfix -> ../init.d/postfix
S82abrt-ccpp -> ../init.d/abrt-ccpp
S82abrtd -> ../init.d/abrtd
S90crond -> ../init.d/crond
S95atd -> ../init.d/atdS
99local -> ../rc.local

systemd管理服务的命令

# 1.启动服务
C6:
/etc/init.d/ 服务名 start
service 服务名 start

C7:
systemctl start 服务名
service 服务名 start

# 2.停止服务
C6:
/etc/init.d/ 服务名 stop
service 服务名 stop

C7:
systemctl stop 服务名
service 服务名 stop

# 3.服务重启
C6:
/etc/init.d/ 服务名 restart
service 服务名 restart

C7:
systemctl restart 服务名
service 服务名 restart

# 4.服务重新加载
C6:
/etc/init.d/ 服务名 reload
service 服务名 reload

C7:
systemctl restart 服务名
service 服务名 reload

# 5.检查服务的启动状态
C6:
/etc/init.d/sshd status
openssh-daemon (pid 1508) is running…

C7:
systemctl status sshd/

# 6.判断服务是否在运行
[root@cyr <sub>]# systemctl is-active sshd
active
[root@cyr </sub>]# systemctl stop sshd
[root@cyr ~]# systemctl is-active sshd
inactive

# 7.禁用某个服务
systemctl mask crond

# 8.取消禁用某个服务
systemctl unmask crond

开机自启服务管理

# 1.查看开机自启的服务有哪些
C6:
chkconfig

C7:
systemctl list-unit-files

# 2.设置开机自启动
C6:
[root@localhost <sub>]# chkconfig sshd on (默认 2 3 4 5 运行级别都自启)
[root@localhost </sub>]# chkconfig |grep sshd
sshd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@localhost <sub>]# chkconfig sshd on
[root@localhost </sub>]# chkconfig |grep sshd
sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@localhost <sub>]# chkconfig sshd off
[root@localhost </sub>]# chkconfig |grep sshd
sshd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@localhost <sub>]# chkconfig sshd --level 3 on
[root@localhost </sub>]# chkconfig |grep sshd
sshd 0:off 1:off 2:off 3:on 4:off 5:off 6:off

C7:
systemctl enable sshd

# 3.关闭开机自启
C6:
chkconfig sshd off

C7:
systemctl disable sshd

# 4.查看指定服务是否开机自启
C6:
chkconfig --list sshd
sshd 0:off 1:off 2:off 3:on 4:off 5:off 6:off

C7:
[root@cyr ~]# systemctl is-enabled nginx
enabled:允许开机自启
disabled:不允许开机自启

# 5.如果启动脚本被修改需从新加载启动脚本
C7:
systemctl daemon-reload


举报

相关推荐

0 条评论