1、上传Redis安装压缩包到服务器/opt目录上
2、redis是由C语言编写,运行需要C环境,安装gcc等
yum install -y gcc gcc-c++ tcl
3、创建redis用户组和用户
groupadd redis
useradd redis -g redis -s /sbin/nologin
4、解压
cd /opt tar -zxvf redis-4.0.14.tar.gz
5、编译、指定目录安装
cd redis-4.0.14 make MALLOC=libc make PREFIX=/opt/redis install
6、配置Redis环境变量
echo "export PATH=/opt/redis/bin:\$PATH" >> /etc/profile source /etc/profile
7、创建Redis存放日志、数据的目录
mkdir -pv /opt/redis/logs /opt/redis/data
8、修改redis.conf配置文件,下面“内网ip”根据实际修改
cp /opt/redis-4.0.14/redis.conf /opt/redis/ sed -i 's/bind 127.0.0.1/bind 内网ip/g' /opt/redis/redis.conf sed -i 's/daemonize no/daemonize yes/g' /opt/redis/redis.conf sed -i "s#^logfile.*#logfile /opt/redis/logs/redis.log#" /opt/redis/redis.conf sed -i "s#^dir ./#dir /opt/redis/data#" /opt/redis/redis.conf
9、修改Redis所属权限
chown -R redis:redis /opt/redis
10、配置redis系统服务启动
vim /usr/lib/systemd/system/redis.service
编辑内容如下后保存:
[Unit] Description=Redis Server Manager After=syslog.target After=network.target [Service] Type=simple User=redis Group=redis PIDFile=/var/run/redis_6379.pid ExecStart=/opt/redis/bin/redis-server /opt/redis/redis.conf --daemonize no ExecStop=/opt/redis/bin/redis-cli shutdown Restart=always [Install] WantedBy=multi-user.target
11、重新加载新的服务、设置Redis开机自启、启动服务、查看启动状态
systemctl daemon-reload
systemctl enable redis
systemctl start redis
systemctl status redis
备注:
Redis默认端口号6379不允许进行远程连接,需要在防火墙中设置6379允许远程连接。
可参考此文章开启:https://www.cnblogs.com/gdjlc/p/15740783.html