下载安装包
代码语言: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