systemctl的使用及配置(centos7)

一.设置开机自启动

1.创建一个服务

[root@MiWiFi-R3-srv ~]# vim /usr/lib/systemd/system/nexus.service

2.填写相关内容


[Unit]
Description=nexus

[Service]
Type=forking
ExecStart=/usr/local/nexus/nexus-3.7.1-02/bin/nexus start
ExecReload=/usr/local/nexus/nexus-3.7.1-02/bin/nexus restart
ExecStop=/usr/local/nexus/nexus-3.7.1-02/bin/nexus stop

[Install]
WantedBy=multi-user.target

3.将服务加入开机启动

[root@MiWiFi-R3-srv ~]# systemctl enable nexus.service

4.重新加载配置文件

[root@MiWiFi-R3-srv ~]# systemctl daemon-reload

注: 到这一步,开机自启动就设置完成了!

二.常用操作命令

#启动服务
systemctl start nexus.service

#停止服务
systemctl stop nexus.service

#重启服务
systemctl restart nexus.service

#查看服务状态
systemctl status nexus.service

#禁止服务开机启动
systemctl disable nexus.service

#设置服务开机启动
systemctl enable nexus.service

三.查询操作命令

应用举例:

#查看网络服务是否启动
systemctl is-active network.service

#检查网络服务是否设置为开机启动
systemctl is-enable network.service

#停止cups服务
systemctl stop cups.service

#注销cups服务
systemctl mask cups.service

#查看cups服务状态
systemctl status cups.service

#取消注销cups服务
systemctl unmask cups.service

四.系统操作命令

systemctl poweroff  系统关机
systemctl reboot    重新启动
systemctl suspend   进入睡眠模式
systemctl hibernate 进入休眠模式
systemctl rescue    强制进入救援模式
systemctl emergency 强制进入紧急救援模式

五.关闭防火墙firewall操作命令

systemctl stop firewalld.service
systemctl disable firewalld.service

反馈与建议


感谢你阅读这篇博客。如果您喜欢这篇博客就请关注我和朋友一起分享吧!

posted @ 2018-01-13 19:24  PengTdy  阅读(2296)  评论(0编辑  收藏  举报