美文网首页
编译安装 Redis

编译安装 Redis

作者: Alexander_Zz | 来源:发表于2019-04-02 15:40 被阅读0次

    ~]# yum install -y vim lrzsz tree screen psmisc lsof tcpdump wget ntpdate gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel net-tools iotop bc zip unzip zlib-devel bash-completion nfs-utils automake libxml2 libxml2-devel libxslt libxslt-devel perl perl-ExtUtils-Embed
    ~]# cd /usr/local/src
    ~]# wget http://download.redis.io/releases/redis-4.0.14.tar.gz
    ~]# tar xf redis-4.0.14.tar.gz
    ~]# cd redis-4.0.14
    ~]# make PREFIX=/usr/local/redis install
    
    • 报错问题


      image.png
    • 解决方法
      README 中有一段话


      image.png

      安装时添加 MALLOC=libc


    • 启动 Redis
    ~]# ln -s /usr/local/redis/bin/* /usr/local/sbin/
    ~]# mkdir /usr/local/redis/etc
    ~]# cp /usr/local/src/redis-4.0.14/redis.conf /usr/local/redis/etc/
    ~]# redis-server /usr/local/redis/etc/redis.conf
    
    • 报错问题


      image.png
    • 解决办法
    # 第一个问题
    ~]# vim /usr/local/redis/etc/redis.conf
    tcp-backlog 128
    # 或者修改 /etc/sysctl.conf
    ~]# vim /etc/sysctl.conf
    net.core.somaxconn = 512
    ~]# sysctl -p
    net.core.comaxconn = 512
    # 第二个问题
    ~]# vim /etc/sysctl.conf
    vm.overcommit_memory = 1
    ~]# sysctl -p
    sysctl vm.overcommit_memory = 1
    # 第三个问题
    ~]# echo never > /sys/kernel/mm/transparent_hugepage/enabled
    ~]# vim /etc/rc.d/rc.local
    echo never > /sys/kernel/mm/transparent_hugepage/enabled
    ~]# chmod a+x /etc/rc.d/rc.local
    ~]# reboot
    # 重启查看 Redis 启动状态
    ~]# vim /usr/lib/systemd/system/redis.service
    
    [Unit]
    Description=Redis persistent key-value database
    After=network.target
    After=network-online.target
    Wants=network-online.target
    
    [Service]
    RuntimeDirectory=redis
    RuntimeDirectoryMode=0755
    Type=notify
    User=redis
    Group=redis
    ExecReload=/bin/kill -s HUP $MAINPID
    ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf --supervised systemd
    # --supervised systemd 表示交由 systemd 代为监听
    ExecStop=/bin/kill -s QUIT $MAINPID
    
    [Install]
    WantedBy=multi-user.target
    
    ~]# systemctl daemon-reload
    ~]# mkdir /usr/local/redis/{logs,data,run} -pv
    ~]# groupadd -g 2001 redis && useradd -u 2001 -g 2001 redis
    ~]# chown redis.redis /usr/local/redis -R
    ~]# cp redis.conf /usr/local/redis/etc/redis.conf
    ~]# vim /usr/local/redis/etc/redis.conf
    
    bind 172.18.33.101   # 按需修改监听地址
    port 6379    # 按需修改监听端口
    pidfile /usr/local/run/redis_6379.pid   # 按需修改 pid 存放位置
    logfile "/usr/local/redis/logs/redis_6379.log"   # 按需修改日志存放位置
    always-show-logo no   # 启动时不显示 logo 节省日志大小
    dbfilename dump_6379.rdb   # 按需修改 rdb 快照名称
    dir /usr/local/redis/data/   # 按需修改快照存放位置
    requirepass 123456   # 按需修改登录密码
    

    相关文章

      网友评论

          本文标题:编译安装 Redis

          本文链接:https://www.haomeiwen.com/subject/mqsgbqtx.html