systemctl工具
systemctl 控制类型 服务名称
控制类型
start 启动
stop 停止
restart 重启
reload 重新加载
status 查看服务状态
使用systemctl前确保 /lib/systemd/system/ 中有相关的.service文件
防火墙位置 /lib/systemd/system/firewalld.service
systemctl start firewalld.service
启动
systemctl stop firewalld.service
关闭
systemctl restart firewalld.service
重启
systemctl status firewalld
状态
systemctl is-active firewalld
状态 是否启动
systemctl is_enabled firewalld.service
是否开机自启
systemctl disable firewalld.service
禁止开机自启
systemctl enable firewalld.service
设置开机自启
systemctl enable --now firewalld
关闭时,设置开机自启同时start启动服务
systemctl disable --now firewalld
开启时,设置禁止自启同时stop停止服务
chkconfig工具
cd /etc/init.d/
ls
通过service命令重启网卡(调用上方/etc/init.d/network 脚本)
service network restart
使用systemctl前确保 /lib/systemd/system/ 中有相关的.service文件
且用chkconfig --add加入到系统管理中
1.可以在/etc/init.d/创建脚本
vim firewall
2.写入代码,结构参考已存在的network脚本
2345代表系统级别2345(单用户 多用户 图形界面)自动启动
10开机第十个启动
90关机第90个停止
若要更改系统级别对应的开机自启
chkconfig --level 35 firewall off 更改刚才的脚本 关闭系统级别3.5的自动启动 chkconfig --level 35 firewall on 更改刚才的脚本 开启系统级别3.5的自动启动
3.添加执行权限
chmod +x firewall
4.chkconfig添加脚本
chkconfig --add firewall
5.即可使用service管理服务
service firewall restart
显示chkconfig目前可管理的
chkconfig --list
0 1 2 3 4 5 6 开关 代表对应的系统级别开机是否自动启动
如network 5:开 代表开机若进入图形界面,自动启动服务
ntsysv系统服务管理工具
图形化设置自启动服务
TAB键切换确定取消
↑↓切换选项
ntsysv
运行级别切换
运行级别 | systemd的target | 说明 |
---|---|---|
0 | poweroff.target | 关机状态 使用该级别会关机 |
1 | rescue.target | 单用户模式 不需要密码即可登录系统 用于多系统维护 |
2 | multi-user.target | 用户定义/域特定运行级别。默认等同于3(CentOS6中不开启网络) |
3 | multi-user.target | 字符界面的完整多用户模式,大多数服务器主机运行在此级别 |
4 | multi-user.target | 用户定义/域特定运行级别。默认等同于3 |
5 | graphical.target | 图形界面的多用户模式,提供了图形桌面操作环境 |
6 | reboot.target | 重新启动,使用该级别时将会重启主机 |
init 0 | systemctl isolate poweroff.target | systemctl poweroff | poweroff | 关机 |
init 1 | systemctl isolate rescue.target | 切换单用户模式 | ||
init 3 | systemctl isolate multi-user.target | 切换字符界面多用户模式 | ||
init 5 | systemctl isolate graphical.target | 切换图形界面多用户模式 | ||
init 6 | systemctl isolate reboot.target | systemctl reboot | reboot | 重启 |
获取当前运行级别
runlevel
获取系统默认运行级别
systemctl get-default
设置系统默认运行级别(开机进入设置的运行级别)
systemctl set-default multi-user.target
systemctl set-default graphical.target
或者以更改软链接方式
ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
ln -s创建软链接 -f强制
软链接方式设置运行级别的原理 更改是 /etc/systemd/system/default.target软链接指向的文件到对应需要设置的运行级别上
补充
永久修改主机名
hostnamectl set-hostname newname
查看主机名的状态
hostnamectl status
hostnamectl
设置系统语言为中文
localectl set-locale LANG=zh_CN.utf8
查看当前系统使用的语言
localectl [status]
查看系统启动耗时
systemd-analyze