zhmg23

我们是如此的不同
资深运维工程师互荐群: 102123162

How to install redis server on CentOS 7/RHEL 7

1、配置yum源

yum install wget

wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-9.noarch.rpm

rpm -ivh epel-release-7-9.noarch.rpm

yum -y update

注:此方法安装的版本为   redis_version:3.2.3


2、安装redis

yum -y install redis 


安装文件分布情况

/etc/logrotate.d/redis

/etc/redis-sentinel.conf

/etc/redis.conf

/etc/systemd/system/redis-sentinel.service.d

/etc/systemd/system/redis-sentinel.service.d/limit.conf

/etc/systemd/system/redis.service.d

/etc/systemd/system/redis.service.d/limit.conf



3、启动redis

# systemctl start redis.service


# systemctl status redis.service

● redis.service - Redis persistent key-value database

   Loaded: loaded (/usr/lib/systemd/system/redis.service; disabled; vendor preset: disabled)

  Drop-In: /etc/systemd/system/redis.service.d

           └─limit.conf

   Active: active (running) since 五 2017-06-16 14:37:43 CST; 1min 11s ago

 Main PID: 32675 (redis-server)

   CGroup: /system.slice/redis.service

           └─32675 /usr/bin/redis-server 127.0.0.1:6379


4、常用命令

启动:systemctl start redis.service

停止:systemctl stop redis.service

重启:systemctl restart redis.service

查看状态:systemctl status redis.service

设置开启启动:systemctl enable redis.service

禁止开机启动:systemctl disable redis.service


5、测试安装

# redis-cli ping 

PONG

返回如上,证明成功。


6、配置启动多个实例


# cp /etc/redis.conf   /etc/redis6379.conf 

# vim /etc/redis6379.conf 

修改为如下参数

pidfile /var/run/redis6379.pid

logfile /var/log/redis/redis6379.log

dbfilename dump6379.rdb

dir /data/redis/6379

daemonize yes

appendfilename "appendonly6379.aof"

#bind 127.0.0.1


通过sed,分别拷贝6380、6390配置文件

# sed  's/6379/6380/g' /etc/redis6379.conf > /etc/redis6380.conf

# sed  's/6379/6390/g' /etc/redis6379.conf > /etc/redis6390.conf


建立6379、6380、6390数据存储目录

# mkdir -p /data/redis/{6379,6380,6390}


配置启动文件

# cd  /usr/lib/systemd/system

# cp redis.service  redis6379.service


# vi /usr/lib/systemd/system/redis6379.service

[Unit]

Description=Redis persistent key-value database

After=network.target


[Service]

ExecStart=/usr/bin/redis-server /etc/redis6379.conf --daemonize no

ExecStop=/usr/bin/redis-shutdown

User=redis

Group=redis


[Install]

WantedBy=multi-user.target


配置6380、6390启动文件

# sed  's/6379/6380/g' /usr/lib/systemd/system/redis6379.service  > /usr/lib/systemd/system/redis6380.service 

# sed  's/6379/6390/g' /usr/lib/systemd/system/redis6379.service  > /usr/lib/systemd/system/redis6390.service 


修改运行用户权限目录

# chown -R redis:  /data/redis  -R

# chown redis: /etc/redis*


优化

# vim /etc/sysctl.conf

vm.overcommit_memory = 1

net.core.somaxconn=512


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


启动

# systemctl  start  redis6379

# systemctl  start  redis6380

# systemctl  start  redis6390


注:如果通过上面的方式无法启动成功,也可以通过命令手动进行启动

$ redis-server  /etc/redis6379.conf 

$ redis-server  /etc/redis6380.conf 

$ redis-server  /etc/redis6390.conf 

如果要停止

$ redis-cli  -p 6380

127.0.0.1:6380> SHUTDOWN




评论