CentOS7 安装 Redis-6.2.1

2024-08-07 13:17:56 浏览数 (1)

下载安装包

代码语言:javascript复制
https://download.redis.io/releases/redis-6.2.1.tar.gz

安装依赖包

代码语言:javascript复制
yum install gcc

解压、安装

代码语言:javascript复制
tar xf redis-6.2.1.tar.gz
cd redis-6.2.1
make PREFIX=/usr/local/redis install

修改参数

代码语言:javascript复制
vim /etc/sysctl.conf

net.core.somaxconn = 512
vm.overcommit_memory = 1
代码语言:javascript复制
chmod  x /etc/rc.d/rc.local
vim /etc/rc.d/rc.local

echo never > /sys/kernel/mm/transparent_hugepage/enabled

修改配置文件

代码语言:javascript复制
mkdir /usr/local/redis/conf
cp redis-6.2.1/redis.conf /usr/local/redis/conf/
vim /usr/local/redis/conf/redis.conf

daemonize yes
requirepass 123456
bind 192.168.1.100

创建启动脚本

代码语言:javascript复制
vim /usr/lib/systemd/system/redis.service

[Unit]
Description=Redis persistent key-value database
After=network.target
After=network-online.target
Wants=network-online.target

[Service]
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/conf/redis.conf --supervised systemd
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -S QUIT $MAINPID
Type=notify
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=0755

[Install]
WantedBy=multi-user.target

创建用户并设置权限

代码语言:javascript复制
useradd redis -s /sbin/nologin
chown -R redis.redis /usr/local/redis
ln -sv /usr/local/redis/bin/redis-* /usr/bin/

启动服务

代码语言:javascript复制
systemctl daemon-reload
systemctl enable redis
systemctl start redis

连接redis

代码语言:javascript复制
redis-cli -h 127.0.0.1 -p 6379 -a 123456

0 人点赞