CentOS 7 安装Redis

Posted zhangbyes

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS 7 安装Redis相关的知识,希望对你有一定的参考价值。

CentOS 7 安装Redis

  1. 安装依赖等

     [[email protected] ~]# yum install -y wget gcc
  2. 下载redis-5.0.3.tar.gz并安装

     [[email protected] ~]# wget http://download.redis.io/releases/redis-5.0.3.tar.gz
     [[email protected] ~]# tar -zxvf redis-5.0.3.tar.gz
     [[email protected] ~]# cd redis-5.0.3
     [[email protected] redis-5.0.3]# make MALLOC=libc
  3. 安装Redis服务

     [[email protected] redis-5.0.3]# ./utils/install_server.sh

    启动Redis服务安装

     Welcome to the redis service installer
     This script will help you easily set up a running redis server
    
     Please select the redis port for this instance: [6379]    # 确认
     Selecting default: 6379
     Please select the redis config file name [/etc/redis/6379.conf]  # 确认
     Selected default - /etc/redis/6379.conf
     Please select the redis log file name [/var/log/redis_6379.log]   # 确认
     Selected default - /var/log/redis_6379.log
     Please select the data directory for this instance [/var/lib/redis/6379]  # 确认
     Selected default - /var/lib/redis/6379
     Please select the redis executable path [/usr/local/bin/redis-server]   # 确认
     Selected config:
     Port           : 6379
     Config file    : /etc/redis/6379.conf
     Log file       : /var/log/redis_6379.log
     Data dir       : /var/lib/redis/6379
     Executable     : /usr/local/bin/redis-server
     Cli Executable : /usr/local/bin/redis-cli
     Is this ok? Then press ENTER to go on or Ctrl-C to abort.    # 确认
     Copied /tmp/6379.conf => /etc/init.d/redis_6379
     Installing service...
     Successfully added to chkconfig!
     Successfully added to runlevels 345!
     Starting Redis server...
     Installation successful!

    修改服务名称

     [[email protected] ~]# mv /etc/init.d/redis_6379 /etc/init.d/redis
  4. 配置Redis.conf

     [[email protected] ~]# vi /etc/redis/6379.conf

    配置Redis.conf

     # bind增加当前服务器内网IP
     bind 10.0.0.120 127.0.0.1 
    
     # 将backlog增大
     tcp-backlog 2000    
    
     # 关闭存盘策略
     # save 900 1
     # save 300 10
     # save 60 10000
    
     # 修改showlog策略
     slowlog-log-slower-than 5000
     slowlog-max-len 500
    
     # 关闭hash-max-ziplist压缩
     # hash-max-ziplist-entries 512
     # hash-max-ziplist-value 64
  5. 重启服务

     [[email protected] ~]# service redis restart
     Stopping ...
     Redis stopped
     Starting Redis server...
  6. 测试服务是否正常运行

     [[email protected] ~]# redis-cli
     127.0.0.1:6379> set a 123456
     OK
     127.0.0.1:6379> get a
     "123456"
     127.0.0.1:6379> exit
  7. 防火墙

     [[email protected] ~]# vim /etc/sysconfig/iptables

    在22端口下增加开放6379端口号

     -A INPUT -p tcp -m state --state NEW -m tcp --dport 6379 -j ACCEPT

    重新启动防火墙服务

     [[email protected] ~]# systemctl restart iptables

以上是关于CentOS 7 安装Redis的主要内容,如果未能解决你的问题,请参考以下文章

如何在 CentOS 7 上安装 Redis 服务器

如何在 CentOS 7 上安装 Redis 服务器

如何在 CentOS 7 上安装 Redis 服务器

如何在 CentOS 7 上安装 Redis 服务器

CentoS 7系统安装redis教程

CentoS 7系统安装redis教程