CentOS 7 安装Redis

CentOS 7 安装Redis

  1. 安装依赖等

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

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

     [root@localhost 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!

修改服务名称

    [root@localhost ~]# mv /etc/init.d/redis_6379 /etc/init.d/redis
  1. 配置Redis.conf

     [root@localhost ~]# 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
  1. 重启服务

     [root@localhost ~]# service redis restart
     Stopping ...
     Redis stopped
     Starting Redis server...
    
  2. 测试服务是否正常运行

     [root@localhost ~]# 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
    
  3. 防火墙

     [root@localhost ~]# vim /etc/sysconfig/iptables
    

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

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

重新启动防火墙服务

    [root@localhost ~]# systemctl restart iptables

posted on 2019-02-18 15:54  三尺微命  阅读(119)  评论(0)    收藏  举报

导航