1.获取安装包
wget http://download.redis.io/releases/redis-4.0.6.tar.gz
2.解压压缩包
tar -zxvf redis-4.0.6.tar.gz
3.安装依赖
yum install gcc
4.跳转到redis目录
cd redis-4.0.6
5.编译
make MALLOC=libc
6.安装
cd src && make prefix=/usr/local/redis install
(如果出现错误 You need tcl 8.5 or newer in order to run the Redis test)
解决:
wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
mkdir /usr/local/depend
sudo tar xzvf tcl8.6.1-src.tar.gz -C /usr/local/depend
cd /usr/local/depend/tcl8.6.1/unix/
./configure
make
make install
make test出现错误:
vim tests/integration/replication-2.tcl
- after 1000
+ after 10000
7.运行redis(会显示redis执行界面,但是不能进行其他操作,需要将其转换为后台运行)
cd /usr/local/redis/bin/
./redis-server
8.设置redis后台运行
(1)将redis.conf 复制到redis目录下
cp /usr/local/src/redis/redis-4.0.6/redis.conf /usr/local/redis/
(2)修改redis.conf ,将 daemonize no 改成 daemonize yes
(3)设置redis可以远程访问
将第70行的bind注释
第90行将protected-mode改为no
(4)指定redis.conf 运行 redis
/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf
9.查看redis进程
ps -aux | grep redis
10.使用systemctl管理redis
(1)在/lib/systemd/system目录下创建一个脚本文件redis.service,里面的内容如下:
[Unit]
Description=Redis
After=network.target
[Service]
Type=forking
PIDFile=/var/run/redis_6379.pid
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
(2) 创建软链接
ln -s /lib/systemd/system/redis.service /etc/systemd/system/multi-user.target.wants/redis.service
(3)查看是否成功建立
ll /etc/systemd/system/multi-user.target.wants/
(4)刷新配置
systemctl daemon-reload
11.启动redis
systemctl start redis
12.重启redis
systemctl restart redis
13.查看redis状态
systemctl status redis
14.设置开机自启
systemctl enable redis