美文网首页REDIS
1.Redis的编译安装与初始化

1.Redis的编译安装与初始化

作者: Stone_説 | 来源:发表于2020-07-26 17:11 被阅读0次

    1.解决依赖关系

    [root@node10 ~]# yum install gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel net-tools vim iotop bc zip unzip zlib-devel lrzsz tree screen lsof tcpdump wget ntpdate
    

    2.安装

    [root@node10 redis-4.0.14]# tar xvf redis-4.0.14.tar.gz 
    [root@node10 redis-4.0.14]# cd redis-4.0.14
    [root@node10 redis-4.0.14]# pwd
    /usr/local/src/redis-4.0.14
    [root@node10 redis-4.0.14]# mkdir -p /apps/redis
    [root@node10 redis-4.0.14]# make
    [root@node10 redis-4.0.14]# make PREFIX=/apps/redis install
    [root@node10 redis-4.0.14]# ll /apps/redis/bin/
    [root@node10 redis-4.0.14]# mkdir /apps/redis/etc
    [root@node10 redis-4.0.14]# cp redis.conf /apps/redis/etc/
    [root@node10 redis-4.0.14]# grep "^[a-Z]" /apps/redis/etc/redis.conf 
    [root@node10 redis-4.0.14]# /apps/redis/bin/redis-server  -h
    [root@node10 redis-4.0.14]# vim /apps/redis/etc/redis.conf 
    [root@node10 redis-4.0.14]# /apps/redis/bin/redis-server /apps/redis/etc/redis.conf
    

    报警提示:

    10401:M 07 Jul 00:15:14.743 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
    10401:M 07 Jul 00:15:14.743 # Server initialized
    10401:M 07 Jul 00:15:14.743 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
    10401:M 07 Jul 00:15:14.743 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
    10401:M 07 Jul 00:15:14.743 * Ready to accept connections
    10401:M 07 Jul 00:30:15.091 * 1 changes in 900 seconds. Saving...
    10401:M 07 Jul 00:30:15.110 * Background saving started by pid 10431
    10431:C 07 Jul 00:30:15.131 * DB saved on disk
    10431:C 07 Jul 00:30:15.132 * RDB: 6 MB of memory used by copy-on-write
    10401:M 07 Jul 00:30:15.211 * Background saving terminated with success
    

    3.解决当前警告

    [root@node10 redis-4.0.14]# vim /etc/sysctl.conf 
    [root@node10 redis-4.0.14]# sysctl -p
    net.core.somaxconn = 512
    vm.overcommit_memory = 1
    [root@node10 redis-4.0.14]# vim /etc/rc.d/rc.local 
    [root@node10 redis-4.0.14]# cat /etc/rc.d/rc.local 
    echo never > /sys/kernel/mm/transparent_hugepage/enabled
    [root@node10 redis-4.0.14]# chmod a+x /etc/rc.d/rc.local 
    [root@node10 redis-4.0.14]# reboot
    [root@node10 ~]# /apps/redis/bin/redis-server /apps/redis/etc/redis.conf                                           
    3672:M 07 Jul 00:55:11.093 # Server initialized
    3672:M 07 Jul 00:55:11.093 * Ready to accept connections
    

    4.增加启动脚本

    [root@node10 ~]# vim /usr/lib/systemd/system/redis.service
    [root@node10 ~]# useradd redis -s /sbin/nologin 
    [root@node10 ~]# chown redis.redis /apps/redis/ -R
    [root@node10 ~]# ss -ntl            
    [root@node10 ~]# systemctl start redis
    [root@node10 ~]# ss -ntl
    State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
    LISTEN     0      511     127.0.0.1:6379                        *:*                                
    [root@node10 ~]# systemctl stop redis
    [root@node10 ~]# ss -ntl            
    [root@node10 ~]# systemctl start redis
    [root@node10 ~]# ss -ntl
    State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
    LISTEN     0      511     127.0.0.1:6379                        *:*                              
    [root@node10 ~]# ps -ef |grep redis
    redis      3758      1  0 01:00 ?        00:00:00 /apps/redis/bin/redis-server 127.0.0.1:6379
    root       3764   3654  0 01:00 pts/0    00:00:00 grep --color=auto redis
    [root@node10 ~]# ln -sv /apps/redis/bin/redis-* /usr/bin/
    ‘/usr/bin/redis-benchmark’ -> ‘/apps/redis/bin/redis-benchmark’
    ‘/usr/bin/redis-check-aof’ -> ‘/apps/redis/bin/redis-check-aof’
    ‘/usr/bin/redis-check-rdb’ -> ‘/apps/redis/bin/redis-check-rdb’
    ‘/usr/bin/redis-cli’ -> ‘/apps/redis/bin/redis-cli’
    ‘/usr/bin/redis-sentinel’ -> ‘/apps/redis/bin/redis-sentinel’
    ‘/usr/bin/redis-server’ -> ‘/apps/redis/bin/redis-server’
    

    5.验证

    [root@node10 ~]# redis-cli
    127.0.0.1:6379> set foo bar
    OK
    127.0.0.1:6379> get foo
    "bar"
    127.0.0.1:6379> ping
    PONG
    

    相关文章

      网友评论

        本文标题:1.Redis的编译安装与初始化

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