一介闲人
一介闲人
yum update -y gcc make tcl
wget http://download.redis.io/releases/redis-7.0.0.tar.gz
## 解压缩
tar -vzxf redis-7.0.0.tar.gz
## 进入安装目录
cd redis-7.0.0/
## 安装
make
make install
## 启动服务
cd src
./redis-server
## 连接验证
./redis-cli
127.0.0.1:6379> ping
PONG
表示正常
## 复制配置文件
cp redis.conf /usr/local/etc/redis/redis.conf
## 编辑配置文件
vim /usr/local/etc/redis/redis.conf
配置项:
允许远程连接
bind * -::*
端口号,一般默认不用改
port 6379
懒加载,在后台运行
daemonize yes
设置连接密码
requirepass 123456
## 重启
ps -ef|grep redis
kill -9 xxx(查到的进程id)
./redis-server /usr/local/etc/redis/redis.conf
./redis-cli -h 127.0.0.1 -a 123456
127.0.0.1:6379> ping
PONG
表示正常
实现效果:
创建 systemd 服务文件
vi /etc/systemd/system/redis.service
按 i 进入编辑模式
[Unit]
Description=Redis Server
After=network.target
[Service]
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
ExecStop=/usr/local/bin/redis-cli -a "你的Redis密码" shutdown
Type=forking
Restart=on-failure
RestartSec=5s
PrivateTmp=true
[Install]
WantedBy=multi-user.target
重新加载 systemd 配置
systemctl daemon-reload
设置权限
chmod 644 /etc/systemd/system/redis.service
如果远程连接不上检查防火墙是否开放端口
查看防火墙状态
systemctl status firewalld
添加端口
firewall-cmd --zone=public --add-port=6379/tcp --permanent
重启防火墙
systemctl restart firewalld
查看开放端口列表
firewall-cmd --zone=public --list-ports
评论