CentOS安装Redis

Published on 2021-01-13 01:03 in 分类: 软件 with 狂盗一枝梅
分类: 软件

1.安装

# 1.下载安装包
wget http://download.redis.io/releases/redis-5.0.7.tar.gz
# 2.解压
tar -xzvf redis-5.0.7.tar.gz 
# 3.安装gcc
yum install gcc
# 4.安装tcl
 yum install tcl
# 5.编译
cd redis-5.0.7/
make MALLOC=libc
# 6.测试编译
make test
# 7.安装
mkdir -p /usr/local/soft/redis5
cd /usr/local/soft/redis5/
mkdir bin
mkdir conf
cd bin/
cp /usr/local/source/redis-5.0.7/src/redis-cli ./
cp /usr/local/source/redis-5.0.7/src/redis-server ./
cd ../conf/
cp /usr/local/source/redis-5.0.7/redis.conf ./

2.配置

修改vi redis.conf配置文件 修改四处地方:

bind 0.0.0.0

requirepass youpassword

# daemonize no
daemonize yes

# maxmemory <bytes>
maxmemory 128MB 

3.运行

/usr/local/soft/redis5/bin/redis-server /usr/local/soft/redis5/conf/redis.conf

4.检查端口是否在使用中

 netstat -anp | grep 6379

5.查看redis的当前版本

/usr/local/soft/redis5/bin/redis-server -v

6.用systemd方式启动和管理

vim /lib/systemd/system/redis.service

添加以下内容:

[Unit]Description=RedisAfter=network.target
[Service]Type=forkingPIDFile=/var/run/redis_6379.pidExecStart=/usr/local/soft/redis5/bin/redis-server /usr/local/soft/redis5/conf/redis.confExecReload=/bin/kill -s HUP $MAINPIDExecStop=/bin/kill -s QUIT $MAINPIDPrivateTmp=true
[Install]WantedBy=multi-user.target

7.重载系统服务

systemctl daemon-reload

8.管理redis

#启动
systemctl start redis    
#重启
systemctl restart redis    
#查看状态
systemctl status redis
#使开机启动
systemctl enable redis

9.docker安装redis

docker run -d --name redis -p 6379:6379 redis-test --requirepass 123456

参考文档:https://www.cnblogs.com/architectforest/p/12325230.html


#centos #redis #linux
目录