系统:CentOS Linux release 7.7.1908 (Core)
软件:redis-6.2.1
安装步骤:
mkdir -p /usr/local/soft/package
cd /usr/local/soft/package
#下载安装包,解压
wget https://download.redis.io/releases/redis-6.2.1.tar.gz
#国内镜像
#wget https://repo.huaweicloud.com/redis/redis-6.2.1.tar.gz
tar -xzvf redis-6.2.1.tar.gz
mv redis-6.2.1 ..
cd ../redis-6.2.1
#编译依赖安装
yum -y install cpp binutils glibc glibc-kernheaders glibc-common glibc-devel gcc make gcc-c++ libstdc++-devel tcl
#编译链接安装
make
#创建软连接
ln -s /usr/local/soft/redis-6.2.1/src/redis-server /usr/local/bin/redis-server
ln -s /usr/local/soft/redis-6.2.1/src/redis-cli /usr/local/bin/redis-cli
配置修改
mkdir /etc/redis
cp /usr/local/soft/redis-6.2.1/redis.conf /etc/redis/redis_6379.conf
vim /etc/redis/redis_6379.conf
#常用配置 按需修改
#端口 默认6379
port 6379
#绑定地址 默认127.0.0.1 -::1
bind 127.0.0.1 -::1 #仅允许本机连接
bind * -::* #允许所有机器连接 生产勿用
#设置连接密码 默认不需要密码
requirepass 密码
#是否允许后台启动(守护进程) 默认no
daemonize yes
#pid文件位置 默认/var/run/redis_6379.pid
pidfile /var/run/redis_6379.pid
启动redis
#若没有设置后台启动 将占用控制台
redis-server /etc/redis/redis_6379.conf
启动客户端
redis-cli
redis> set foo bar
#>>OK
redis> get foo
#>>"bar"
服务注册
vim /etc/systemd/system/redis.service
#添加以下内容:
'''
[Unit]
Description=redis
After=network.target
[Service]
Type=forking
PIDFile=/var/run/redis_6379.pid
ExecStart=/usr/local/soft/redis-6.2.1/src/redis-server /etc/redis/redis_6379.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
'''
#查询服务状态
systemctl status redis
#启动服务
systemctl start redis
#停止服务
systemctl stop redis
#重启服务
systemctl restart redis
#设置服务开机启动
systemctl enable redis
#关闭服务开机启动
systemctl disable redis