检查GCC环境
# 检查是否有GCC环境
yum list installed | grep gcc
# 没有则安装
yum -y install gcc gcc-c++ kernel-devel
下载Redis
https://redis.io/download/#redis-downloads
# 下载命令
wget https://github.com/redis/redis/archive/7.2.4.tar.gz
# 解压
tar -zxvf redis-******.tar.gz
编译 / 安装
# 编译
make
# 安装
make install PREFIX=/usr/local/redis/
# 复制配置文件
cp ~/redis-******/redis.conf /usr/local/redis
编辑配置文件
vim /usr/local/redis/redis.conf
#protected-mode yes改为
protected-mode no
#bind 127.0.0.1改为
bind 0.0.0.0
#port 6379改为
port 6349
#requirepass foobared改为
requirepass 123456
配置启动文件
# 文件
vim /lib/systemd/system/redis.service
# 在文件中写入以下内容
[Unit]
Description=Redis Server
After=network.target
[Service]
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.target
启动Redis
# 重载系统服务
systemctl daemon-reload
# 启动Redis
systemctl start redis.service
常用操作命令
# 开机自启
systemctl enable redis.service
# 取消开机自启
systemctl disable redis.service
# 启动服务
systemctl start redis.service
# 关闭服务
systemctl stop redis.service
# 重启服务
systemctl restart redis.service
# 查看服务状态
systemctl status redis.service