1、su - root #切换root
2、touch /etc/systemd/system/redis.service #新建启动文件
3、vim /etc/systemd/system/redis.service #编辑文件 设置如下内容
[Unit]
Description=redis-server #描述服务
After=network.target #描述服务类别
[Service] #服务运行参数的设置
Type=forking #后台运行的形式
ExecStart=/usr/local/redis/redis-server /usr/local/redis/redis.conf #服务的具体运行命令 ,依据自己的路径进行相应的修改
PrivateTmp=true #给服务分配独立的临时空间
[Install] #运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3
WantedBy=multi-user.target
4、运行
systemctl stop redis.service #停止服务
systemctl start redis.service #开启服务
systemctl enable redis.service #设置开机自启动
reboot #重启服务器
5、常用命令
systemctl start redis.service #启动redis服务
systemctl enable redis.service #设置开机自启动
systemctl disable redis.service #停止开机自启动
systemctl status redis.service #查看服务当前状态
systemctl restart redis.service #重新启动服务
systemctl list-units --type=service #查看所有已启动的服务