Linux系统服务控制 systemctl chkconfig ntsysv 运行级别切换

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说明
0poweroff.target关机状态 使用该级别会关机
1rescue.target单用户模式 不需要密码即可登录系统 用于多系统维护
2multi-user.target用户定义/域特定运行级别。默认等同于3(CentOS6中不开启网络)
3multi-user.target字符界面的完整多用户模式,大多数服务器主机运行在此级别
4multi-user.target用户定义/域特定运行级别。默认等同于3
5graphical.target图形界面的多用户模式,提供了图形桌面操作环境
6reboot.target重新启动,使用该级别时将会重启主机
init 0 systemctl isolate poweroff.targetsystemctl poweroffpoweroff 关机
init 1systemctl isolate rescue.target  切换单用户模式
init 3systemctl isolate multi-user.target切换字符界面多用户模式
init 5systemctl isolate graphical.target切换图形界面多用户模式
init 6systemctl isolate reboot.targetsystemctl rebootreboot重启

获取当前运行级别

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 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值