cd /usr/local wget https://download.redis.io/releases/redis-5.0.14.tar.gz
解压
tar -zxvf redis-5.0.14.tar.gz mv -f redis-5.0.14 redis
编译
cd /usr/local/redis make
安装gcc依赖
yum -y install gcc automake autoconf libtool make
安装
make install PREFIX=/usr/local/redis
Prefix:指定安装路径
如果执行make命令报错:致命错误:jemalloc/jemalloc.h: 没有那个文件或目录,则需要在make指定分配器为libc。执行下面命令即可正常编译:
make MALLOC=libc
vim /usr/local/redis/redis.conf
绑定 ip,如果绑定的是 127.0.0.1 则只能在服务器内部访问,因为是需要外部访问 redis,所以这里注释 bind。
Redis 默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程,在这里设置为no。
关闭保护模式,否则外部ip无法连接
访问密码验证
/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf
nohup /usr/local/redis/bin/redis-server /usr/local/redis/redis.conf >redis.log 2>&1 &
ps -ef|grep redis
redis默认监听端口是6379
systemctl status firewalld
firewall-cmd --zone=public --add-port=6379/tcp --permanent
firewall-cmd --reload
firewall-cmd --zone=public --query-port=6379/tcp
创建pid文件
touch /usr/local/redis/redis.pid
注意,这里要用守护进程的方式启动,要把 /usr/local/redis-5.0.14/redis.conf 的 daemonize 改为 yes
修改pid文件路径
pidfile /usr/local/redis/redis.pid
配置日志文件路径
mkdir /usr/local/redis/logs touch /usr/local/redis/logs/redis.log
logfile "/usr/local/redis/logs/redis.log"
touch /usr/lib/systemd/system/redis.service vim /usr/lib/systemd/system/redis.service
[Unit] Description=Redis After=syslog.target network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/usr/local/redis/redis.pid ExecStart=/usr/local/redis/src/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
通过 systemctl 来启动 redis
systemctl daemon-reload systemctl status redis systemctl start redis systemctl stop redis systemctl restart redis ps -ef | grep redis
通过 systemctl 来设置 redis开机启动
systemctl enable redis