一 安装redis
1 创建redis的安装目录
利用以下命令,切换到/usr/local路径
cd /usr/local
键入以下命令,新建一个redis目录,用于放置redis软件。
mkdir redis
2 下载并解压安装redis
至redis官网下载最新版本redis:https://redis.io/download
3. 修改redis.conf
vi redis.conf
将daemonize no修改为daemonize yes
Port 6379修改端口
保存退出
./src/redis-server redis.conf
关闭redis进程
使用ps aux | grep redis查看redis进程
[root@aaa]# ps aux | grep redis
root 20517 0.1 0.1 141884 1656 ? Ssl 09:12 0:09 ./src/redis-server 127.0.0.1:6379
root 29815 0.0 0.0 112644 968 pts/0 R+ 11:31 0:00 grep --color=auto redis
然后用kill -9 20517结束redis进程
4. 将redis加入到systemctl控制
在/usr/lib/systemd/system 增加文件 redis.service 754权限
Vi redis.service
[Unit]
Description=Redis
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/redis/src/redis-server /usr/local/redis/redis.conf
ExecStop=kill -INT `cat /tmp/redis.pid`
User=root
Group=root
[Install]
WantedBy=multi-user.target
保存退出
启动redis服务
systemctl start redis.service
设置开机自启动
systemctl enable redis.service
停止开机自启动
systemctl disable redis.service
查看服务当前状态
systemctl status redis.service
重新启动服务
systemctl restart redis.service