1.下载或上传安装包
安装包官方下载地址:https://download.redis.io/releases/
2.准备GCC编译环境
查看gcc编译器版本:
gcc -v
若不存在则执行:
yum install -y gcc
或参考服务器gcc离线安装指南
3.解压安装包并移至目标目录
本文以redis-7.0.8.tar.gz安装包,部署路径/home/redis为例,请读者根据实际情况修改
tar zvxf redis-7.0.8.tar.gz
mv redis-7.0.8 /home/redis
4.编译和安装
注:PREFIX表示编译安装的目录,默认为/usr/local/bin目录
cd /home/redis
make
make install PREFIX=/home/redis
5.添加环境变量
vim /etc/profile
在文末添加以下内容:
# REDIS_HOME
export REDIS_HOME=/home/redis
export PATH=$PATH:$REDIS_HOME/bin
刷新系统配置:
source /etc/profile
6.添加系统服务
vim /usr/lib/systemd/system/redis.service
添加如下内容:
[Unit]
Description=redis-server
After=network.target
[Service]
#Type=forking
ExecStart=/home/redis/bin/redis-server /home/redis/redis.conf
ExecStop=/home/redis/bin/redis-cli shutdown
PrivateTmp=true
[Install]
WantedBy=multi-user.target
赋权:
chmod 755 /usr/lib/systemd/system/redis.service
重载系统服务:
systemctl daemon-reload
7.启动Redis服务
systemctl start redis
8.配置Redis服务
vim /home/redis/redis.conf
(1)开启Redis远程访问服务
①注释bind 127.0.0.1这一行,取消指定网段访问
#bind 127.0.0.1 -::1
②将protected-mode设置为no
protected-mode no
(2)设置Redis后台运行
将daemonize的属性改为 yes
daemonize yes
(3)设置Redis密码
①在配置文件中找到 # requirepass foobared
②将foobared改为自己的密码,然后取消注释
requirepass ${REDIS_PASSWORD}
(4)设置Redis端口号(可选)
port 6379
(5)修改Redis系统服务
因Redis此时以daemon模式运行,可以将其配置为forking类型
vim /usr/lib/systemd/system/redis.service
将#Type=forking这一行取消注释,即:
[Unit]
Description=redis-server
After=network.target
[Service]
Type=forking
ExecStart=/home/redis/bin/redis-server /home/redis/redis.conf
ExecStop=/home/redis/bin/redis-cli shutdown
PrivateTmp=true
[Install]
WantedBy=multi-user.target
重载系统服务:
systemctl daemon-reload
9.重启Redis服务
systemctl restart redis
10.设置Redis开机自启动
systemctl enable redis
标签:bin,Redis,V10,redis,Centos7,systemctl,home,安装包
From: https://blog.csdn.net/qq_35394671/article/details/142485433