zoukankan      html  css  js  c++  java
  • redis3.2.12安装部署

    环境:

     1 [root@localhost ~]# cat /etc/redhat-release 
     2 CentOS Linux release 7.2.1511 (Core) 
     3 [root@localhost ~]# ifconfig ens33
     4 ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
     5         inet 192.168.112.120  netmask 255.255.255.0  broadcast 192.168.112.255
     6         inet6 fe80::20c:29ff:fe04:63d1  prefixlen 64  scopeid 0x20<link>
     7         ether 00:0c:29:04:63:d1  txqueuelen 1000  (Ethernet)
     8         RX packets 790483  bytes 907004420 (864.9 MiB)
     9         RX errors 0  dropped 0  overruns 0  frame 0
    10         TX packets 254709  bytes 35108598 (33.4 MiB)
    11         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    12 
    13 [root@localhost ~]# 

    安装相关依赖包

     1 [root@localhost ~]# yum install tcl
     2 Loaded plugins: fastestmirror
     3 Loading mirror speeds from cached hostfile
     4  * base: centos.ustc.edu.cn
     5  * epel: mirror01.idc.hinet.net
     6  * extras: mirrors.shu.edu.cn
     7  * remi-safe: mirrors.tuna.tsinghua.edu.cn
     8  * updates: mirrors.shu.edu.cn
     9 Resolving Dependencies
    10 --> Running transaction check
    11 ---> Package tcl.x86_64 1:8.5.13-8.el7 will be installed
    12 --> Finished Dependency Resolution
    13 
    14 Dependencies Resolved
    15 
    16 ========================================================================================================================================================================================================================================
    17  Package                                             Arch                                                   Version                                                          Repository                                            Size
    18 ========================================================================================================================================================================================================================================
    19 Installing:
    20  tcl                                                 x86_64                                                 1:8.5.13-8.el7                                                   base                                                 1.9 M
    21 
    22 Transaction Summary
    23 ========================================================================================================================================================================================================================================
    24 Install  1 Package
    25 
    26 Total download size: 1.9 M
    27 Installed size: 4.4 M
    28 Is this ok [y/d/N]: y
    29 Downloading packages:
    30 tcl-8.5.13-8.el7.x86_64.rpm                                                                                                                                                                                      | 1.9 MB  00:00:01     
    31 Running transaction check
    32 Running transaction test
    33 Transaction test succeeded
    34 Running transaction
    35   Installing : 1:tcl-8.5.13-8.el7.x86_64                                                                                                                                                                                            1/1 
    36   Verifying  : 1:tcl-8.5.13-8.el7.x86_64                                                                                                                                                                                            1/1 
    37 
    38 Installed:
    39   tcl.x86_64 1:8.5.13-8.el7                                                                                                                                                                                                             
    40 
    41 Complete!
    42 [root@localhost ~]# 
     1 [root@localhost redis-3.2.12]# pwd
     2 /root/tools/redis-3.2.12
     3 [root@localhost redis-3.2.12]# make && make install
     4 --------省略部分--------------------
     5     CC redis-check-rdb.o
     6     CC geo.o
     7     LINK redis-server
     8     INSTALL redis-sentinel
     9     CC redis-cli.o
    10     LINK redis-cli
    11     CC redis-benchmark.o
    12     LINK redis-benchmark
    13     INSTALL redis-check-rdb
    14     CC redis-check-aof.o
    15     LINK redis-check-aof
    16 
    17 Hint: It's a good idea to run 'make test' ;)
    18 
    19 make[1]: Leaving directory `/root/tools/redis-3.2.12/src'
    20 cd src && make install
    21 make[1]: Entering directory `/root/tools/redis-3.2.12/src'
    22 
    23 Hint: It's a good idea to run 'make test' ;)
    24 
    25     INSTALL install
    26     INSTALL install
    27     INSTALL install
    28     INSTALL install
    29     INSTALL install
    30 [root@localhost redis-3.2.12]#

     设置redis服务相关参数,如果不用修改可直接回车,这里我修改为自己实际定义

     1 [root@localhost redis-3.2.12]# cd utils/
     2 [root@localhost utils]# pwd
     3 /root/tools/redis-3.2.12/utils
     4 [root@localhost utils]# ls -lh
     5 total 52K
     6 -rw-rw-r-- 1 root root  593 Jun 13 06:47 build-static-symbols.tcl
     7 -rw-rw-r-- 1 root root 1.3K Jun 13 06:47 cluster_fail_time.tcl
     8 -rw-rw-r-- 1 root root 1.1K Jun 13 06:47 corrupt_rdb.c
     9 drwxrwxr-x 2 root root   57 Jun 13 06:47 create-cluster
    10 -rwxrwxr-x 1 root root 2.1K Jun 13 06:47 generate-command-help.rb
    11 drwxrwxr-x 2 root root   37 Jun 13 06:47 hashtable
    12 drwxrwxr-x 2 root root   67 Jun 13 06:47 hyperloglog
    13 -rwxrwxr-x 1 root root 8.4K Jun 13 06:47 install_server.sh
    14 drwxrwxr-x 2 root root   37 Jun 13 06:47 lru
    15 -rw-rw-r-- 1 root root 1.3K Jun 13 06:47 redis-copy.rb
    16 -rwxrwxr-x 1 root root 1.1K Jun 13 06:47 redis_init_script
    17 -rwxrwxr-x 1 root root 1.1K Jun 13 06:47 redis_init_script.tpl
    18 -rw-rw-r-- 1 root root 1.8K Jun 13 06:47 redis-sha1.rb
    19 drwxrwxr-x 2 root root  110 Jun 13 06:47 releasetools
    20 -rwxrwxr-x 1 root root 3.7K Jun 13 06:47 speed-regression.tcl
    21 -rwxrwxr-x 1 root root  693 Jun 13 06:47 whatisdoing.sh
    22 [root@localhost utils]# ./install_server.sh 
    23 Welcome to the redis service installer
    24 This script will help you easily set up a running redis server
    25 
    26 Please select the redis port for this instance: [6379] 6379
    27 Please select the redis config file name [/etc/redis/6379.conf] /application/redis/conf/redis.conf
    28 Please select the redis log file name [/var/log/redis_6379.log] /application/redis/log/redis.log
    29 Please select the data directory for this instance [/var/lib/redis/6379] /application/redis/data/
    30 Please select the redis executable path [/usr/local/bin/redis-server] /application/redis/bin/redis-server
    31 Selected config:
    32 Port           : 6379
    33 Config file    : /application/redis/conf/redis.conf
    34 Log file       : /application/redis/log/redis.log
    35 Data dir       : /application/redis/data/
    36 Executable     : /usr/local/bin/redis-server
    37 Cli Executable : /usr/local/bin/redis-cli
    38 Is this ok? Then press ENTER to go on or Ctrl-C to abort.
    39 Copied /tmp/6379.conf => /etc/init.d/redis_6379
    40 Installing service...
    41 Successfully added to chkconfig!
    42 Successfully added to runlevels 345!
    43 Starting Redis server...
    44 Installation successful!
    45 [root@localhost utils]# tree /application/redis/
    46 /application/redis/
    47 ├── bin
    48 ├── conf
    49 │   └── redis.conf
    50 ├── data
    51 ├── log
    52 │   └── redis.log
    53 └── run
    54 
    55 5 directories, 2 files
    56 [root@localhost utils]# 

    查看redis启动状态:

    1 [root@localhost utils]# ps xua|grep redis
    2 root     39418  0.5  0.2 136916  4204 ?        Ssl  04:03   0:00 /usr/local/bin/redis-server 127.0.0.1:6379
    3 root     40749  0.0  0.0 112648   952 pts/1    S+   04:06   0:00 grep --color=auto redis
    4 [root@localhost utils]# netstat -lnput|grep 6379
    5 tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      39418/redis-server  
    6 [root@localhost utils]# 

    redis启动OK,这里有个小问题,就是配置文件中的redis.pid和redis数据文件存放路径要修改一下,刚才定义中可能没有生效;我们查看下配置文件:

     1 [root@localhost conf]# grep -E -v "^#|^$" redis.conf 
     2 bind 127.0.0.1
     3 protected-mode yes
     4 port 6379
     5 tcp-backlog 511
     6 timeout 0
     7 tcp-keepalive 300
     8 daemonize yes
     9 supervised no
    10 pidfile /var/run/redis_6379.pid
    11 loglevel notice
    12 logfile /application/redis/log/redis.log
    13 databases 16
    14 save 900 1
    15 save 300 10
    16 save 60 10000
    17 stop-writes-on-bgsave-error yes
    18 rdbcompression yes
    19 rdbchecksum yes
    20 dbfilename dump.rdb
    21 dir /application/redis/data/
    22 slave-serve-stale-data yes
    23 slave-read-only yes
    24 repl-diskless-sync no
    25 repl-diskless-sync-delay 5
    26 repl-disable-tcp-nodelay no
    27 slave-priority 100
    28 appendonly no
    29 appendfilename "appendonly.aof"
    30 appendfsync everysec
    31 no-appendfsync-on-rewrite no
    32 auto-aof-rewrite-percentage 100
    33 auto-aof-rewrite-min-size 64mb
    34 aof-load-truncated yes
    35 lua-time-limit 5000
    36 slowlog-log-slower-than 10000
    37 slowlog-max-len 128
    38 latency-monitor-threshold 0
    39 notify-keyspace-events ""
    40 hash-max-ziplist-entries 512
    41 hash-max-ziplist-value 64
    42 list-max-ziplist-size -2
    43 list-compress-depth 0
    44 set-max-intset-entries 512
    45 zset-max-ziplist-entries 128
    46 zset-max-ziplist-value 64
    47 hll-sparse-max-bytes 3000
    48 activerehashing yes
    49 client-output-buffer-limit normal 0 0 0
    50 client-output-buffer-limit slave 256mb 64mb 60
    51 client-output-buffer-limit pubsub 32mb 8mb 60
    52 hz 10
    53 aof-rewrite-incremental-fsync yes
    54 [root@localhost conf]# 

    pidfile文件存储路径没有修改,这里修改下为./application/redis/run/redis_6379.pid,拷贝/root/tools/redis-3.2.12/src/redis-server /root/tools/redis-3.2.12/src/redis-cli 到目录/application/redis/bin下

    1 [root@localhost bin]# pwd
    2 /application/redis/bin
    3 [root@localhost bin]# ls -l
    4 total 0
    5 [root@localhost bin]# cp /root/tools/redis-3.2.12/src/redis-se
    6 redis-sentinel  redis-server    
    7 [root@localhost bin]# cp /root/tools/redis-3.2.12/src/redis-server ./
    8 [root@localhost bin]# cp /root/tools/redis-3.2.12/src/redis-cli ./
    9 [root@localhost bin]# 

    关闭redis服务,编辑启动文件

    [root@localhost bin]# ps xua|grep redis
    root     39418  0.6  0.2 136916  4204 ?        Ssl  04:03   0:04 /usr/local/bin/redis-server 127.0.0.1:6379
    root     46306  0.0  0.0 112648   952 pts/1    R+   04:14   0:00 grep --color=auto redis
    [root@localhost bin]# /application/redis/bin/redis-cli shutdown
    [root@localhost bin]# ps xua|grep redis
    root     46480  0.0  0.0 112648   952 pts/1    S+   04:15   0:00 grep --color=auto redis
    [root@localhost bin]# 
    
    编辑启动脚本
    [root@localhost bin]# vim /etc/init.d/redis_6379 
    #!/bin/sh
    #Configurations injected by install_server below....
    
    EXEC=/application/redis/bin/redis-server
    CLIEXEC=/application/redis/bin/redis-cli
    PIDFILE=/application/redis/run/redis_6379.pid
    CONF="/application/redis/conf/redis.conf"
    REDISPORT="6379"
    ###############
    # SysV Init Information
    # chkconfig: - 58 74
    # description: redis_6379 is the redis daemon.
    ### BEGIN INIT INFO
    # Provides: redis_6379
    # Required-Start: $network $local_fs $remote_fs
    # Required-Stop: $network $local_fs $remote_fs
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Should-Start: $syslog $named
    # Should-Stop: $syslog $named
    # Short-Description: start and stop redis_6379
    # Description: Redis daemon
    ### END INIT INFO
    
    
    case "$1" in
        start)
            if [ -f $PIDFILE ]
            then
                echo "$PIDFILE exists, process is already running or crashed"
            else
                echo "Starting Redis server..."
                $EXEC $CONF
            fi
            ;;
        stop)
            if [ ! -f $PIDFILE ]
            then
                echo "$PIDFILE does not exist, process is not running"
            else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                $CLIEXEC -p $REDISPORT shutdown
                while [ -x /proc/${PID} ]
                do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
            fi
            ;;
        status)
            PID=$(cat $PIDFILE)
            if [ ! -x /proc/${PID} ]
            then
                echo 'Redis is not running'
            else
                echo "Redis is running ($PID)"
            fi
            ;;
        restart)
            $0 stop
            $0 start
            ;;
        *)
            echo "Please use start, stop, restart or status as first argument"
            ;;
    esac
    [root@localhost bin]# 

    查看启动状态:

    1 [root@localhost bin]# /etc/init.d/redis_6379 start
    2 Starting Redis server...
    3 [root@localhost bin]# ps xua|grep redis
    4 root     48434  0.7  0.1 136916  2176 ?        Ssl  04:18   0:00 /application/redis/bin/redis-server 127.0.0.1:6379
    5 root     48469  0.0  0.0 112648   952 pts/1    S+   04:18   0:00 grep --color=auto redis
    6 [root@localhost bin]#
    7 [root@localhost bin]# netstat -lnupt|grep 6379
    8 tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      48434/redis-server  
    9 [root@localhost bin]# 

    查看对应目录文件:

     1 [root@localhost bin]# tree /application/redis/
     2 /application/redis/
     3 ├── bin
     4 │   ├── redis-cli
     5 │   └── redis-server
     6 ├── conf
     7 │   └── redis.conf
     8 ├── data
     9 │   └── dump.rdb
    10 ├── log
    11 │   └── redis.log
    12 └── run
    13     └── redis_6379.pid
    14 
    15 5 directories, 6 files
    16 [root@localhost bin]# 

    测试连接:

      1 [root@localhost bin]# /application/redis/bin/redis-cli 
      2 127.0.0.1:6379> info 
      3 # Server
      4 redis_version:3.2.12
      5 redis_git_sha1:00000000
      6 redis_git_dirty:0
      7 redis_build_id:7e7350d70058cbc5
      8 redis_mode:standalone
      9 os:Linux 3.10.0-327.el7.x86_64 x86_64
     10 arch_bits:64
     11 multiplexing_api:epoll
     12 gcc_version:4.8.5
     13 process_id:48434
     14 run_id:e2bea78666a0166f3eab59fd3bd47439d7aba000
     15 tcp_port:6379
     16 uptime_in_seconds:367
     17 uptime_in_days:0
     18 hz:10
     19 lru_clock:5780405
     20 executable:/application/redis/bin/redis-server
     21 config_file:/application/redis/conf/redis.conf
     22 
     23 # Clients
     24 connected_clients:1
     25 client_longest_output_list:0
     26 client_biggest_input_buf:0
     27 blocked_clients:0
     28 
     29 # Memory
     30 used_memory:822744
     31 used_memory_human:803.46K
     32 used_memory_rss:2228224
     33 used_memory_rss_human:2.12M
     34 used_memory_peak:822744
     35 used_memory_peak_human:803.46K
     36 total_system_memory:1921671168
     37 total_system_memory_human:1.79G
     38 used_memory_lua:37888
     39 used_memory_lua_human:37.00K
     40 maxmemory:0
     41 maxmemory_human:0B
     42 maxmemory_policy:noeviction
     43 mem_fragmentation_ratio:2.71
     44 mem_allocator:jemalloc-4.0.3
     45 
     46 # Persistence
     47 loading:0
     48 rdb_changes_since_last_save:0
     49 rdb_bgsave_in_progress:0
     50 rdb_last_save_time:1532506694
     51 rdb_last_bgsave_status:ok
     52 rdb_last_bgsave_time_sec:-1
     53 rdb_current_bgsave_time_sec:-1
     54 aof_enabled:0
     55 aof_rewrite_in_progress:0
     56 aof_rewrite_scheduled:0
     57 aof_last_rewrite_time_sec:-1
     58 aof_current_rewrite_time_sec:-1
     59 aof_last_bgrewrite_status:ok
     60 aof_last_write_status:ok
     61 
     62 # Stats
     63 total_connections_received:1
     64 total_commands_processed:1
     65 instantaneous_ops_per_sec:0
     66 total_net_input_bytes:31
     67 total_net_output_bytes:9928
     68 instantaneous_input_kbps:0.00
     69 instantaneous_output_kbps:0.00
     70 rejected_connections:0
     71 sync_full:0
     72 sync_partial_ok:0
     73 sync_partial_err:0
     74 expired_keys:0
     75 evicted_keys:0
     76 keyspace_hits:0
     77 keyspace_misses:0
     78 pubsub_channels:0
     79 pubsub_patterns:0
     80 latest_fork_usec:0
     81 migrate_cached_sockets:0
     82 
     83 # Replication
     84 role:master
     85 connected_slaves:0
     86 master_repl_offset:0
     87 repl_backlog_active:0
     88 repl_backlog_size:1048576
     89 repl_backlog_first_byte_offset:0
     90 repl_backlog_histlen:0
     91 
     92 # CPU
     93 used_cpu_sys:1.84
     94 used_cpu_user:0.06
     95 used_cpu_sys_children:0.00
     96 used_cpu_user_children:0.00
     97 
     98 # Cluster
     99 cluster_enabled:0
    100 
    101 # Keyspace
    102 127.0.0.1:6379> set a b
    103 OK
    104 127.0.0.1:6379> get a
    105 "b"
    106 127.0.0.1:6379> set c sss
    107 OK
    108 127.0.0.1:6379> get c
    109 "sss"
    110 127.0.0.1:6379> save
    111 OK
    112 127.0.0.1:6379> 
    113 127.0.0.1:6379> 

    至此redis安装完成

  • 相关阅读:
    左偏树
    论在Windows下远程连接Ubuntu
    ZOJ 3711 Give Me Your Hand
    SGU 495. Kids and Prizes
    POJ 2151 Check the difficulty of problems
    CodeForces 148D. Bag of mice
    HDU 3631 Shortest Path
    HDU 1869 六度分离
    HDU 2544 最短路
    HDU 3584 Cube
  • 原文地址:https://www.cnblogs.com/kindnull/p/9366624.html
Copyright © 2011-2022 走看看