目录
临时开关服务命令
-
语法
-
centos6
-
service 服务名 start 开启服务
-
service 服务名 stop 关闭服务
-
service 服务名 restart 重启服务
-
service 服务名 status 查看服务状态
-
-
centos7
-
systemctl start 服务名 开启服务
-
systemctl stop 服务名 关闭服务
-
systemctl restart 服务名 重启服务
-
systemctl status 服务名 查看服务
-
systemctl --type service 看正在运行的服务
-
-
-
实操
-
1查看网络服务状态
systemctl status network.service
-
2关闭服务
systemctl stop network.service
-
3启动服务
systemctl start network.service
-
4重启服务
systemctl restart network.service
-
5查看所有服务
systemctl --type service
-
-
注意事项
.service 后缀可以省略不写
开启和关闭不是永久的,一旦重启电脑,会恢复默认设置可以
vim /etc/sysconfig/network- scripts/ifconfg- ens33
里面有一个
ONBOOT = "yes"
表示网络是默认开机启动永久开关服务命令
-
语法
-
centos6
-
chkconfig 查看所有服务自启配置
-
chkconfig 服务名 off 关闭服务自启
-
chkconfig 服务名 on 开启服务自启
-
chkconfig 服务名 --list 查看服务开启启动状态
-
-
centos7
-
systemctl enable 服务名 打开自启
-
systemctl disable 服务名 关闭自启
-
systemctl is-enable 服务名 查看服务是否自启
-
systemctl list-unit-files 查看所有服务自启配置
-
-
-
实操
-
1 关闭防火墙自动启动
systemctl status firewalld 查看防火墙 systemctl disable firewalld 关闭防火墙自启
-
2 开启防火墙自启
systemctl enable firewalld
-
3 查看防火墙是否自启
systemctl is-enable firewalld
-
4 关闭网络管理器服务
查看服务 systemctl status NetworkManager.service 停止服务 systemctl stop NetworkManager 查看自启动 systemctl is-enable NetworkManager 关闭自动动 systemctl disable NetworkManager
为什么关闭网络管理器服务?
答:如果挂起客户机,相当于将linux内存磁盘等等给固定住了,但是网络时间需要慢慢变化,所以就容易将网络给锁住然后启动不起来,所以直接就关闭网络管理器服务。
-
Linux系统又其中运行级别(runlevel):
-
-
常用的是级别3和5(Centos7中只有两个级别:3和5)
-
运行级别0:系统停机状态,系统默认运行级别不能设置为0,否则不能正常启动
-
运行级别1:单用户工作状态,root权限,用于系统维护,禁止远程登录
-
运行级别2:多用户工作状态(没有NFS),不支持网络
-
运行级别3:完全的多用户状态(有NFS),登录后进入控制台命令行模式
-
运行级别4:系统未使用,保留
-
运行级别5:X11控制台,保留
-
运行级别6:系统正常关闭并重启,默认运行级别不能设置为6,否则不能正常启动。