一、系統信息
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 配置指定服務 開機啓動設置完畢!