1、下载
wget https://download.redis.io/releases/redis-6.2.2.tar.gz
2、解压
tar xzf redis-6.2.2.tar.gz
3、编译
make
make install
4、修改配置文件
vim redis.conf
关闭IP绑定 #bind 127.0.0.1
关闭保护模式 protected-mode no
开启后台运行 daemonize yes
5、启动redis
redis-server redis.conf
6、、进入redis客户端
redis-cli -p 6379
ping
7、关闭redis
redis-cli -p 6379 shutdown
8、设置开机自启动
vi /lib/systemd/system/redis.service
[Unit]
#Description:描述服务
Description=Redis
#After:描述服务类别
After=network.target
#服务运行参数的设置
[Service]
#Type=forking是后台运行的形式
Type=forking
#ExecStart为服务的具体运行命令,路径必须是绝对路径
ExecStart=/usr/local/bin/redis-server /usr/local/redis/redis-6.2.2/redis.conf#ExecReload为重启命令 ,路径必须是绝对路径
ExecReload=/usr/local/bin/redis-server -s reload#ExecStop为停止命令 ,路径必须是绝对路径
ExecStop=/usr/local/bin/redis-server -s stop#PrivateTmp=True表示给服务分配独立的临时空间
PrivateTmp=true#运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl start redis.service
systemctl enable redis.service
#启动redis服务 systemctl start redis.service
————————————————
#停止redis服务 systemctl stop redis.service
————————————————
#重新启动服务 systemctl restart redis.service
————————————————
#查看服务当前状态 systemctl status redis.service
————————————————
#设置开机自启动 systemctl enable redis.service
————————————————
#停止开机自启动 systemctl disable redis.service