ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
## 控制系统服务的默认工具不同 ### 1. 在centos6中,默认使用的服务启动方式 是service >[success] service命令是Redhat Linux兼容的发行版中用来控制系统服务的实用工具,它以启动、停止、重新启动和关闭系统服务,还可以显示所有系统服务的当前状态。 #### service 的特点 1.服务名:自动要控制的服务名,即/etc/init.d目录下的脚本文件名; 2.控制命令:系统服务脚本支持的控制命令。 #### 实例: 1.当修改了主机名、ip地址等信息时,经常需要把网络重启使之生效。 ~~~ service network status 配置设备: lo eth0 当前的活跃设备: lo eth0 service network restart 正在关闭接口 eth0: [ 确定 ] 关闭环回接口: [ 确定 ] 设置网络参数: [ 确定 ] 弹出环回接口: [ 确定 ] 弹出界面 eth0: [ 确定 ] ~~~ 2.重启mysql ~~~ service mysqld status mysqld (pid 1638) 正在运行... service mysqld restart 停止 MySQL: [ 确定 ] 启动 MySQL: ~~~ ### 2. 在centos7中,默认使用的服务启动方式 是systemctl >[success] systemctl命令是系统服务管理器指令,它实际上将 service 和 chkconfig 这两个命令组合到一起。 #### 实例 当修改了主机名、ip地址等信息时,经常需要把网络重启使之生效。 ~~~ systemctl status network.service ~~~ 2.重启 apache ~~~ systemctl restart httpd.service ~~~ **systemctl常用命令** | 任务 | 旧指令 | 新指令 | | --- | --- | --- | | 使某服务自动启动 | chkconfig --level 3 httpd on | systemctl enable httpd.service | | 使某服务不自动启动 | chkconfig --level 3 httpd off | systemctl disable httpd.service | | 检查服务状态 |service httpd status | systemctl status httpd.service (服务详细信息) systemctl is-active httpd.service (仅显示是否 Active) | | 显示所有已启动的服务 | chkconfig --list | systemctl list-units --type=service | | 启动某服务 | service httpd start | systemctl start httpd.service | | 停止某服务 | service httpd stop | systemctl stop httpd.service | | 重启某服务 | service httpd restart | systemctl restart httpd.service | >[danger] 在centos中仍然支持service 的方式启动系统服务,但是需要自行编写启动脚本,因为systemctl的启动脚本与service的不同。