一、目标
在centos7.9上部署安装redis-7.2.3
二、步骤
官网
https://redis.io/download/
1、下载合适版本的redis
wget https://github.com/redis/redis/archive/7.2.3.tar.gz --no-check-certificate
如果这个链接失效,自行去官网找个合适的版本
2、安装redis
yum install gcc-c++ -y
tar -zxf 7.2.3.tar.gz
cd redis-7.2.3/
make
make install PREFIX=/usr/local/redis
3、修改redis配置
cp redis.conf /usr/local/redis/bin/
sed -i 's/# requirepass foobared/requirepass mypwd123/g' /usr/local/redis/bin/redis.conf
sed -i '/^\s*#/!s/127\.0\.0\.1/0\.0\.0\.0/g' /usr/local/redis/bin/redis.conf
sed -i 's/daemonize no/daemonize yes/g' /usr/local/redis/bin/redis.conf
注:
● 给redis设置密码mypwd123
● 设置所有主机都能访问redis
● 开启redis即后台启动,默认是前台启动。
4、测试启动redis
cd /usr/local/redis/bin/
./redis-server ./redis.conf
./redis-cli
keys * #会报错,因为给redis设置了密码
auth mypwd123
keys * #不报错,因为上面登录了
5、创建redis启动服务脚本
cat << EOF > /usr/lib/systemd/system/redis.service
[Unit]
Description=redis-server
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
6、杀掉刚才测试启动的redis
kill `ps -ef |grep redis |head -n 1 |awk '{print $2}'`
7、使用systemd启动redis,并设置开机自启
systemctl daemon-reload
systemctl enable redis --now
8、测试是否启动成功
systemctl status redis
ss -ntl |grep 6379