(0基础学Linux系列)2.15 Linux服务管理

网友投稿 561 2022-08-24

(0基础学Linux系列)2.15 Linux服务管理

(0基础学Linux系列)2.15 Linux服务管理

1.1 什么是systemd

Systemd(System Daemon)是CentOS7系统中的系统管理守护进程、工具和库的集合,用于取代早期的init进程。Systemd的功能是用于集中管理和配置Linux系统。

systemd是CentOS7系统中启动的第一个进程(PID等于1),其他所有进程都是他的子进程。

C6:服务启动方式

# /etc/init.d/network restart Restarting network (via systemctl): [ OK ] # service network restart Restarting network (via systemctl): [ 确定 ]

1.2 systemd相关路径文件

路径 描述
/usr/lib/systemd/system 启动服务程序所在的路径
/etc/systemd/system 不同运行级别启动文件路径
/etc/systemd/system/multi-user.target.wants 开机自启文件所在路径

1.3 systemd管理服务相关命令

1)常用命令

systemctl命令 作用
start 启动服务
stop 停止服务
restart 重启服务
reload 重新加载配置
status 查看服务运行状态

2)使用实例:

# 启动crond服务 systemctl start crond # 停止crond服务 systemctl stop crond # 重启crond服务 systemctl restart crond # 重新加载配置crond systemctl reload crond # 查看crond服务运行状态 systemctl status crond

3)运行状态描述

状态 描述
loaded 服务单元的配置文件已经被处理
active(running) 服务持续运行
inactive (dead) 服务停止状态
enabled 服务设定为开机运行
disabled 服务设定为开机不运行

1.4 systemd服务开机自启

1)常用命令

systemctl命令 作用
enable 开机自动启动
disable 开机不自动启动

2)手工设置开机自启动

在 /etc/systemd/system/multi-user.target.wants/ 目录下设置快捷方式

# ln -s /usr/lib/systemd/system/crond.service /etc/systemd/system/multi-user.target.wants/crond.service # ls -l /etc/systemd/system/multi-user.target.wants/|grep crond # systemctl status crond

3)手工设置开机停止启动

删除在multi-user.target.wants里的快捷方式

# rm -f /etc/systemd/system/multi-user.target.wants/crond.service # ls -l /etc/systemd/system/multi-user.target.wants/|grep crond # systemctl status crond

1.5 linux服务器 开机自启动服务优化

1)需要保留的服务

除下方服务外,其他的根据需要开启

服务名称 服务作用
rsyslog.service 日志系统
sshd.service 远程连接SSHD
sysstat.service 性能监控
network 网络服务(使用chkconfig开启)

2)处理方法

# systemctl list-unit-files|egrep -v "network.ta|rsyslog|sshd\.|sysstat|static"|awk '{print "systemctl disable "$1}'|bash # systemctl list-unit-files|grep enabled 网络服务的开机自启动 # chkconfig network on # chkconfig --list|grep network

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Maven技术解析(maven详解)
下一篇:Git/GitHub学习第一天(第一次git)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~