下载安装包

wget https://download.redis.io/releases/redis-6.2.4.tar.gz
tar -xvf redis-6.2.4.tar.gz
mv redis-6.2.4 /usr/local/redis
cd /usr/local/redis/
yum -y install gcc gcc+ 
make MALLOC=libc
make install

创建多实例(如果是单实例就不需要了)

 mkdir -p /data/redis/redis-6379
 mkdir -p /data/redis/redis-6389
 mkdir -p /data/redis/redis-6399
 
 cp /usr/local/redis/redis.conf /data/redis/redis-6379
 cp /usr/local/redis/redis.conf /data/redis/redis-6389
 cp /usr/local/redis/redis.conf /data/redis/redis-6399

修改对应的配置文件为自己的端口

我配置了密码,所以下面的启动服务service里面添加了密码,这种方式如果改密码就不适用了,可以自己写一个通过kill进程来停掉redis的方式

  • 6379配置
bind 0.0.0.0
protected-mode no
port 6379
dir /data/redis/redis-6379/
pidfile /var/run/redis_6379.pid
daemonize yes
requirepass QWERASDF
  • 6389
bind 0.0.0.0
protected-mode no
port 6389
dir /data/redis/redis-6389/
pidfile /var/run/redis_6389.pid
daemonize yes
requirepass QWERASDF
  • 6399
bind 0.0.0.0
protected-mode no
port 6399
dir /data/redis/redis-6399/
pidfile /var/run/redis_6399.pid
daemonize yes
requirepass QWERASDF

服务启动配置文件

  • 6379
vim /usr/lib/systemd/system/redis6379.service
[Unit]
Description=redis
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/redis/src/redis-server /data/redis/redis-6379/redis-6379.conf
ExecReload=/usr/local/redis/src/redis-cli  -a "QWERASDF" -p 6379 shutdown | /usr/local/redis/src/redis-server /data/redis/redis-6379/redis-6379.conf
ExecStop=/usr/local/redis/src/redis-cli -a "QWERASDF" -p 6379 shutdown
[Install]
WantedBy=multi-user.target
  • 6389
vim /usr/lib/systemd/system/redis6389.service
[Unit]
Description=redis
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/redis/src/redis-server /data/redis/redis-6389/redis-6389.conf
ExecReload=/usr/local/redis/src/redis-cli  -a "QWERASDF" -p 6389 shutdown | /usr/local/redis/src/redis-server /data/redis/redis-6389/redis-6389.conf
ExecStop=/usr/local/redis/src/redis-cli -a "QWERASDF" -p 6389 shutdown
[Install]
WantedBy=multi-user.target
  • 6399
vim /usr/lib/systemd/system/redis6399.service
[Unit]
Description=redis
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/redis/src/redis-server /data/redis/redis-6399/redis-6399.conf
ExecReload=/usr/local/redis/src/redis-cli  -a "QWERASDF" -p 6399 shutdown | /usr/local/redis/src/redis-server /data/redis/redis-6399/redis-6399.conf
ExecStop=/usr/local/redis/src/redis-cli -a "QWERASDF" -p 6399 shutdown
[Install]
WantedBy=multi-user.target

修改系统配置,不然redis起不来

echo "vm.overcommit_memory=1" >> /etc/sysctl.conf
sysctl -p

启动服务

systemctl daemon-reload
systemctl start redis6379
systemctl start redis6389
systemctl start redis6399

测试

redis-cli --host 127.0.0.1 --port 6379
redis-cli --host 127.0.0.1 --port 6389
redis-cli --host 127.0.0.1 --port 6399