编译安装为redis官方推荐安装方式。
本例中使用linux版本为:CentOS Linux release 7.0.1406 (Core),Basic Web Server
一、安装依赖包
yum -y install gcc yum -y install libc
libc安装过程,出现Error:Nothing to do,但并没有影响到接下来的redis安装,通过whereis libc,发现libc已经存在。
二、下载redis安装包
1、通过https://redis.io/download/下载redis最新稳定版本
2、使用wget获取redis-stable版本
wget http://download.redis.io/redis-stable.tar.gz
通过http://download.redis.io/redis-stable.tar.gz获取到的版本始终为当前的最新文档版本。
以上两种方式获取到的版本是相同的。本例以下载redis-5.0.4.tar.gz为例
3、将redis-5.0.4上传到linux上某位置,解压到/usr/local下
tar -zxvf redis-5.0.4.tar.gz mv redis-5.0.4 /usr/local/redis
4、进入到redis-5.0.4目录
cd /usr/local/redis/
5、安装
make && make install
当执行make install之后,在/usr/local/bin下将出现一些redis脚本
/usr/local/bin为环境变量,其下的脚本可以直接使用,故make进行安装,make install为设置环境变量
6、执行测试(可选)
执行make test之前需要安装tcl
yum -y install tcl make test
make test出现如下异常
vim tests/unit/memefficiency.tcl
将150和100的值改大点,如1500,1000,重新执行make test
7、拷贝配置文件
cp redis.conf /etc/
8、修改配置
新建日志地址
mkdir -p /usr/local/redis/logs touch /usr/local/redis/logs/redis.log
vim /etc/redis.config
logfile "/usr/local/redis/logs/redis.log" daemonize yes #bind 127.0.0.1 ##注释掉,允许所有其他ip访问,真实使用最好坐下限制,只允许某些主机访问
9、设置开机启动
vim /usr/lib/systemd/system/redis.service
添加如下内容
[Unit] Description=Redis persistent key-value database After=network.target After=network-online.target Wants=network-online.target [Service] ExecStart=/usr/local/bin/redis-server /etc/redis.conf --protected-mode no ExecStop=/usr/local/bin/redis-cli shutdown #Restart=always Type=forking #User=redis #Group=redis RuntimeDirectory=redis RuntimeDirectoryMode=0755 [Install] WantedBy=multi-user.target
上述配置中Restart为always,则使用kill或者kill -9命令无法停止redis,只有通过开机命令停止,Type必须为forking,不能为notify
若去掉always
使配置生效
systemctl enable redis
systemctl daemon-reload
10、启动redis
systemctl start redis
原文:https://www.cnblogs.com/qq931399960/p/10584877.html