centos7安装Redis

1.安装gcc依赖

yum install -y gcc 

2.下载及解压

wget wget http://download.redis.io/releases/redis-6.2.5.tar.gz

tar -zxvf redis-6.2.5.tar.gz

3.编译

cd redis-6.2.5

make

4.安装,带上安装目录

make install PREFIX=/usr/local/redis

5.启动

cp redis-6.2.5/redis.conf /usr/local/redis/bin/

存储持久化

修改 redis.conf 文件,把 daemonize no 改为 daemonize yes

vim redis.conf

搜索:/daemonize

启动

./redis-server redis.conf

6.设置开机启动

vi /etc/systemd/system/redis.service
[Unit]
Description=redis-server
After=network.target
 
[Service]
Type=forking
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target

7.设置开机自启

systemctl daemon-reload

systemctl start redis.service

systemctl enable redis.service

8.软连接测试

ln -s /usr/local/redis/bin/redis-cli /usr/bin/redis

9.附件

systemctl start redis.service   #启动redis服务

systemctl stop redis.service   #停止redis服务

systemctl restart redis.service   #重新启动服务

systemctl status redis.service   #查看服务当前状态

systemctl enable redis.service   #设置开机自启动

systemctl disable redis.service   #停止开机自启动

10.外部访问开启

vim /usr/local/redis/bin/redis.conf

centos7安装Redis_第1张图片

密码修改

修改redis.conf配置文件

requirepass foobared
requirepass 123 指定密码123

防火墙端口开放

firewall-cmd --zone=public --add-port=6379/tcp --permanent

 防火墙重启

firewall-cmd --reload

你可能感兴趣的:(linux,centos,运维)