一、安装gcc依赖
[root@localhost /]# yum install -y gcc
二、下载并解压安装包
[root@localhost opt]# wget http://download.redis.io/releases/redis-6.0.9.tar.gz
[root@localhost opt]# tar -zxvf redis-6.0.9.tar.gz
三、cd切换到redis解压目录下,编译
[root@localhost local]# cd redis-6.0.9
[root@localhost redis-6.0.9]# make
四、安装并指定安装目录
[root@localhost redis-6.0.9]# make install PREFIX=/usr/local/redis
五、启动服务
5.1前台启动
[root@localhost redis-6.0.9]# cd /usr/local/redis/bin/
[root@localhost bin]# ./redis-server
5.2后台启动并设置密码
从 redis 的源码目录中复制 redis.conf 到 redis 的安装目录
[root@localhost bin]# cp /usr/local/redis-6.0.9/redis.conf /usr/local/redis/bin/
[root@localhost bin]# vim redis.conf
修改 redis.conf 文件中:daemonize no 改为 daemonize yes
修改redis.conf文件中:requirepass foobared取消注释(改为:requirepass 123456)
启动
[root@localhost bin]# ./redis-server redis.conf
六、设置开机启动
添加开机启动服务
[root@localhost bin]# vim /etc/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
设置开机启动
[root@localhost bin]# systemctl daemon-reload
[root@localhost bin]# systemctl start redis.service
[root@localhost bin]# systemctl enable redis.service
七、安装报错
7.1错误示例:
‘struct redisServer’ has no member named ‘server_cpulist’ redisSetCpuAff
7.2错误原因:
gcc版本问题,新版本的。redis6.0以上
7.3解决方式:
[root@localhost /]#yum -y install centos-release-scl
[root@localhost /]#yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
[root@localhost /]#scl enable devtoolset-9 bash
[root@localhost /]#echo “source /opt/rh/devtoolset-9/enable” >>/etc/profile