zoukankan      html  css  js  c++  java
  • redis编译安装

    1.编译安装
     
    准备工作
    # yum install gcc gcc++ make -y
     
    1.1获取redis安装包并进行安装
    # wget http://download.redis.io/releases/redis-4.0.14.tar.gz
    # tar xzf redis-4.0.14.tar.gz
    # cd redis-4.0.14
    # make PREFIX=/usr/local/redis install
    # mkdir -pv /usr/local/redis/etc
    # cp redis.conf /usr/local/redis/etc/
    1.2前台启动redis
    # /usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
    3824:C 13 Feb 10:51:23.699 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
    3824:C 13 Feb 10:51:23.699 # Redis version=4.0.14, bits=64, commit=00000000, modified=0, pid=3824, just started
    3824:C 13 Feb 10:51:23.699 # Configuration loaded
    3824:M 13 Feb 10:51:23.700 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                    _._                                                  
               _.-``__ ''-._                                             
          _.-``    `.  `_.  ''-._           Redis 4.0.14 (00000000/0) 64 bit
      .-`` .-```.  ```/    _.,_ ''-._                                   
    (    '      ,       .-`  | `,    )     Running in standalone mode
    |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
    |    `-._   `._    /     _.-'    |     PID: 3824
      `-._    `-._  `-./  _.-'    _.-'                                   
    |`-._`-._    `-.__.-'    _.-'_.-'|                                  
    |    `-._`-._        _.-'_.-'    |           http://redis.io        
      `-._    `-._`-.__.-'_.-'    _.-'                                   
    |`-._`-._    `-.__.-'    _.-'_.-'|                                  
    |    `-._`-._        _.-'_.-'    |                                  
      `-._    `-._`-.__.-'_.-'    _.-'                                   
          `-._    `-.__.-'    _.-'                                       
              `-._        _.-'                                           
                  `-.__.-'                               
     
    1.3验证 
    # /usr/local/redis/bin/redis-cli
    redis> set foo bar
    OK
    redis> get foo
    "bar"
     
     
    1.4解决当前的警告提示:
    1.4.1.tcp-backlog:
    Thebacklogargument defines the maximum length to which the queue of pending connections  forsockfdmay grow. If a connection request arrives when the queue is full, the client may receive  an error with an indication ofECONNREFUSEDor, if the underlying protocol supports  retransmission, the request may be ignored so that a later reattempt at connection succeeds.
    backlog参数控制的是三次握手的时候server端收到client ack确认号之后的队列值。
     
     
    # echo 'net.core.somaxconn = 512' >>/etc/sysctl.conf
    # sysctl -p
     
     
    1.4.2.vm.overcommit_memory:
    0、表示内核将检查是否有足够的可用内存供应用进程使用;如果有足够的可用内存,内存申请允许;否则,内存申请失败,并把错误返回给应用进程。
    1、表示内核允许分配所有的物理内存,而不管当前的内存状态如何。
    2、表示内核允许分配超过所有物理内存和交换空间总和的内存
    # echo 'vm.overcommit_memory = 1' >>/etc/sysctl.conf
    # sysctl -p
    1.4.3.transparenthugepage:
    开启大页内存动态分配,需要关闭让redis 负责内存管理。
    echo never > /sys/kernel/mm/transparent_hugepage/enabled
     
    再次启动redis:
    将以上配置同步到其他redis 服务器。redis服务器报错问题都解决了。
     
    2编译安装后的一些优化操作
     
    2.1编辑redis服务启动脚本:
    # cat  /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]
    #ExecStart=/usr/bin/redis-server /etc/redis.conf --supervised systemd
    ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf  --supervised systemd
    ExecReload=/bin/kill -s HUP $MAINPID
    ExecStop=/bin/kill -s QUIT $MAINPID
    Type=notify
    User=redis
    Group=redis
    RuntimeDirectory=redis
    RuntimeDirectoryMode=0755
    [Install]
    WantedBy=multi-user.target
    2.2创建redis 用户和数据目录:
    # groupadd  -g 1001 redis && useradd   -u 1001 -g 1001 redis -s /sbin/nologin
    # mkdir -pv /usr/local/redis/{etc,logs,data,run}
    # chown redis.redis -R  /usr/local/redis/ #注意目录权限
    2.3:验证redis 启动:
    # systemctl daemon-reload
    # systemctl start redis
    # systemctl status redis
    ● redis.service - Redis persistent key-value database
       Loaded: loaded (/usr/lib/systemd/system/redis.service; disabled; vendor preset: disabled)
       Active: active (running) since Thu 2020-02-13 11:12:26 CST; 5s ago
    Main PID: 3986 (redis-server)
       CGroup: /system.slice/redis.service
               └─3986 /usr/local/redis/bin/redis-server 127.0.0.1:6379
     
     
    Feb 13 11:12:26 redis-vm1.novalocal redis-server[3986]: |    `-._`-._        _.-'_.-'    |           http://redis.io
    Feb 13 11:12:26 redis-vm1.novalocal redis-server[3986]: `-._    `-._`-.__.-'_.-'    _.-'
    Feb 13 11:12:26 redis-vm1.novalocal redis-server[3986]: |`-._`-._    `-.__.-'    _.-'_.-'|
    Feb 13 11:12:26 redis-vm1.novalocal redis-server[3986]: |    `-._`-._        _.-'_.-'    |
    Feb 13 11:12:26 redis-vm1.novalocal redis-server[3986]: `-._    `-._`-.__.-'_.-'    _.-'
    Feb 13 11:12:26 redis-vm1.novalocal redis-server[3986]: `-._    `-.__.-'    _.-'
    Feb 13 11:12:26 redis-vm1.novalocal redis-server[3986]: `-._        _.-'
    Feb 13 11:12:26 redis-vm1.novalocal redis-server[3986]: `-.__.-'
    Feb 13 11:12:26 redis-vm1.novalocal redis-server[3986]: 3986:M 13 Feb 11:12:26.149 # Server initialized
    Feb 13 11:12:26 redis-vm1.novalocal redis-server[3986]: 3986:M 13 Feb 11:12:26.150 * Ready to accept connections
    # netstat -tnlp
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
    tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      3986/redis-server 1
    tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      3314/sshd           
    tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      3281/master         
    tcp6       0      0 :::22                   :::*                    LISTEN      3314/sshd           
    tcp6       0      0 ::1:25                  :::*                    LISTEN      3281/master
    # ps -ef | grep redis
    redis     4286     1  0 11:38 ?        00:00:00 /usr/local/redis/bin/redis-server 127.0.0.1:6379
    # /usr/local/redis/bin/redis-cli
    127.0.0.1:6379> info
    # Server
    redis_version:4.0.14
    redis_git_sha1:00000000
    redis_git_dirty:0
    redis_build_id:442b337a2f108655
    redis_mode:standalone
    os:Linux 3.10.0-957.el7.x86_64 x86_64
    arch_bits:64
    multiplexing_api:epoll
    atomicvar_api:atomic-builtin
    gcc_version:4.8.5
    process_id:3986
    run_id:3e87c0ea4a1e1dafe1379933bd713f6472e356ec
    tcp_port:6379
    uptime_in_seconds:119
    uptime_in_days:0
     
    2.4使用客户端连接redis:
    #/usr/local/redis/bin/redis-cli  -h  IP/HOSTNAME -p PORT -a PASSWORD
    2.2.2.8:创建命令软连接:
    # ln -sv /usr/local/redis/bin/redis-* /usr/bin/
    ‘/usr/bin/redis-benchmark’ -> ‘/usr/local/redis/bin/redis-benchmark’
    ‘/usr/bin/redis-check-aof’ -> ‘/usr/local/redis/bin/redis-check-aof’
    ‘/usr/bin/redis-check-rdb’ -> ‘/usr/local/redis/bin/redis-check-rdb’
    ‘/usr/bin/redis-cli’ -> ‘/usr/local/redis/bin/redis-cli’
    ‘/usr/bin/redis-sentinel’ -> ‘/usr/local/redis/bin/redis-sentinel’
    ‘/usr/bin/redis-server’ -> ‘/usr/local/redis/bin/redis-server’
    2.5编译安装后的命令:
    [root@redis-s1 ~]# ll /usr/local/redis/bin/
    total 32656
    -rwxr-xr-x 1 redis redis 4365488 Dec 13 09:21 redis-benchmark #redis性能测试工具
    -rwxr-xr-x 1 redis redis 8088920 Dec 13 09:21 redis-check-aof #AOF文件检查工具
    -rwxr-xr-x 1 redis redis 8088920 Dec 13 09:21 redis-check-rdb #RDB文件检查工具
    -rwxr-xr-x 1 redis redis 4800752 Dec 13 09:21 redis-cli #redis #客户端工具
    lrwxrwxrwx 1 redis redis   12 Dec 13 09:21 redis-sentinel -> redis-server #哨兵,软连接到
    server
    -rwxr-xr-x 1 redis redis 8088920 Dec 13 09:21  #redis-server #redis 服务端
     
    2.6修改配置文件/usr/local/redis/etc/redis.conf以便客户端远程连接
    bind 0.0.0.0#监听地址,可以用空格隔开后多个监听IP,默认配置是127.0.0.1,远程客户端无法连接redis服务
    # redis-cli -h 172.16.99.127 -p 6379
    172.16.99.127:6379> set foo bar
    OK
    172.16.99.127:6379> get foo
    "bar"
     
  • 相关阅读:
    Generate Parentheses
    Length of Last Word
    Maximum Subarray
    Count and Say
    二分搜索算法
    Search Insert Position
    Implement strStr()
    Remove Element
    Remove Duplicates from Sorted Array
    Remove Nth Node From End of List
  • 原文地址:https://www.cnblogs.com/dexter-wang/p/12303007.html
Copyright © 2011-2022 走看看