今天又要维护新的服务器了,翻了一下网上Redis自动启动,结果配置一大堆,其实很多没什么用,也不好理解,所以干脆把我自己的记录给写这里给大家参考。
第一步:创建Redis启动服务
在系统开机启动项目录 /lib/systemd/system 目录添加 redis.service 文件
[root@iZ23evimvf8Z ~]# vi /lib/systemd/system/redis.service第二步:写入启动命令
[Unit]Description=The redis-server Process ManagerDocumentation=https://redis.io/After=network.target[Service]Type=forkingExecStart=/usr/local/redis/xqdsb/redis-server /usr/local/redis/redis.confExecStop=/usr/local/redis/xqdsb/redis-cli shutdown[Install]WantedBy=multi-user.target说明:大家要有自己的启动命令之后,改成自己的路径即可。
第三步:设置服务开机自启
[root@iZ23evimvf8Z ~]# systemctl enable redis第四步:使用命令
# 启动 nginx[root@iZ23evimvf8Z ~]# systemctl start redis# 停止[root@iZ23evimvf8Z ~]# systemctl stop redis# 查看redis运行状态[root@iZ23evimvf8Z ~]# systemctl status redis[root@iZ23evimvf8Z ~]# ps aux | grep redis第五:扩展了解
这个是用户启动项,意思是只有这个用户登陆的时候才启动:
/usr/lib/systemd/system/
这个是系统开机启动项,意思是开机就启动,不管哪个用户登录:
/lib/systemd/system/
查看所有的开机启动项:
systemctl list-unit-files |grep enabled
第六:安装Redis4.0
[root@iZbp1f0xuq9rc41s6gdvfyZ redis]# yum install gcc-c++[root@iZbp1f0xuq9rc41s6gdvfyZ local]# tar -zxvf nginx-1.14.0.tar.gz[root@iZbp1f0xuq9rc41s6gdvfyZ local]# mv redis-4.0.10 redis[root@iZbp1f0xuq9rc41s6gdvfyZ local]# make PREFIX=/usr/local/redis install[root@iZbp1f0xuq9rc41s6gdvfyZ local]# cd redis[root@iZbp1f0xuq9rc41s6gdvfyZ redis]# vi redis.conf修改redis.conf配置文件, daemonize yes 以后端模式启动