记一次 Centos7.x 配置指定服务 开机启动

一、系统信息

1、系统 Centos7.x   镜像下载地址:

http://archive.kernel.org/centos-vault/7.4.1708/isos/x86_64/

虚拟机安装过程参考:

https://blog.csdn.net/llwy1428/article/details/89328381

2、VMware 版本:VMware Workstation Pro15

3、工具:xshell5

二、配置过程

1、本文以已搭建好的 Redis 环境为例

参考:

https://blog.csdn.net/llwy1428/article/details/106730436

2、创建、编辑文件

[root@localhost ~]# vim /usr/lib/systemd/system/redis.service

写入以下内容

[Unit]
Description=Redis Server
After=network.target

[Service]
Type=forking
ExecStart=/opt/redis/bin/redis-server /opt/redis/redis.conf
ExecStop=/opt/redis/bin/redis-cli -p 6379 -a 123456 shutdown

[Install]
WantedBy=multi-user.target

保存并退出

说明:

 -p 6379      Redis 服务选择、配置的端口号

 -a 123456   Redis 服务设置的密码

 如果没有密码,可以不加参数 -a

3、服务的启动、重启、停止、开机启动/禁止

(1)启动服务

[root@localhost ~]# systemctl start redis

(2)停止服务

[root@localhost ~]# systemctl stop redis

(3)重启服务

[root@localhost ~]# systemctl restart redis

(4)设置服务开启启动

[root@localhost ~]# systemctl enable redis

(5)禁止服务开机启动

[root@localhost ~]# systemctl disable redis

 

 

至此,Centos7.x  配置指定服务  开机启动设置完毕!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章