Redis教程

CentOS7系统源码安装Redis多实例

本文主要是介绍CentOS7系统源码安装Redis多实例,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

下载安装包

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

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

  • 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 -p 6379 shutdown | /usr/local/redis/src/redis-server /data/redis/redis-6379/redis-6379.conf
ExecStop=/usr/local/redis/src/redis-cli -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 -p 6379 shutdown | /usr/local/redis/src/redis-server /data/redis/redis-6389/redis-6389.conf
ExecStop=/usr/local/redis/src/redis-cli -p 6379 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 -p 6379 shutdown | /usr/local/redis/src/redis-server /data/redis/redis-6399/redis-6399.conf
ExecStop=/usr/local/redis/src/redis-cli -p 6379 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
这篇关于CentOS7系统源码安装Redis多实例的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!