Redis 3.2.x安装和配置

1. 关闭防火墙和Selinux

        Linux的防火墙是咱们新手的噩梦,很多情况会出现能ping通,但是访问不了Web页面。所以开始就干掉它!

    1.1 关闭防火墙

    [root@localhost ~]# /etc/init.d/iptables stop
    iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
    iptables: Flushing firewall rules:                         [  OK  ]
    iptables: Unloading modules:                               [  OK  ]

    1.2 开机自动关闭防火墙

    [root@localhost ~]# chkconfig iptables off

    1.3 查看Selinux状态

    [root@localhost ~]# sestatus
    SELinux status: enabled 
    SELinuxfs mount: /sys/fs/selinux 
    SELinux root directory: /etc/selinux 
    Loaded policy name: targeted 
    Current mode: enforcing 
    Mode from config file: enforcing 
    Policy MLS status: enabled 
    Policy deny_unknown status: allowed 
    Max kernel policy version: 28

    1.4 关闭selinux

    [root@localhost ~]# vi /etc/selinux/config 

修改 SELINUX=disabled 
注:永久开启->改成:SELINUX=enforcing

2. 下载并安装Redis 3.2.x版本

注:为了方便管理,/root下创建一个文件夹专门放所需软件

    [root@localhost ~]# mkdir tools
    [root@localhost ~]# cd tools

   2.1 安装redis编译组件

    [root@localhost tools]# yum -y install gcc-c++ tcl

   2.2 下载Redis 3.2.x安装包

    [root@localhost tools]# wget http://download.redis.io/releases/redis-3.2.12.tar.gz

    2.3 解压Redis 3.2.x

    [root@localhost tools]# tar -zxvf redis-3.2.12.tar.gz

2.4 make && make install

[root@localhost redis-3.2.12]# pwd
/root/tools/redis-3.2.12
[root@localhost redis-3.2.12]# make && make install
--------省略部分--------------------
    CC redis-check-rdb.o
    CC geo.o
    LINK redis-server
    INSTALL redis-sentinel
    CC redis-cli.o
    LINK redis-cli
    CC redis-benchmark.o
    LINK redis-benchmark
    INSTALL redis-check-rdb
    CC redis-check-aof.o
    LINK redis-check-aof

Hint: It's a good idea to run 'make test' ;)

make[1]: Leaving directory `/root/tools/redis-3.2.12/src'
cd src && make install
make[1]: Entering directory `/root/tools/redis-3.2.12/src'

Hint: It's a good idea to run 'make test' ;)

    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
[root@localhost redis-3.2.12]#

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

[root@localhost redis-3.2.12]# cd utils/
[root@localhost utils]# pwd
/root/tools/redis-3.2.12/utils
[root@localhost utils]# ls -lh
total 52K
-rw-rw-r-- 1 root root  593 Jun 13 06:47 build-static-symbols.tcl
-rw-rw-r-- 1 root root 1.3K Jun 13 06:47 cluster_fail_time.tcl
-rw-rw-r-- 1 root root 1.1K Jun 13 06:47 corrupt_rdb.c
drwxrwxr-x 2 root root   57 Jun 13 06:47 create-cluster
-rwxrwxr-x 1 root root 2.1K Jun 13 06:47 generate-command-help.rb
drwxrwxr-x 2 root root   37 Jun 13 06:47 hashtable
drwxrwxr-x 2 root root   67 Jun 13 06:47 hyperloglog
-rwxrwxr-x 1 root root 8.4K Jun 13 06:47 install_server.sh
drwxrwxr-x 2 root root   37 Jun 13 06:47 lru
-rw-rw-r-- 1 root root 1.3K Jun 13 06:47 redis-copy.rb
-rwxrwxr-x 1 root root 1.1K Jun 13 06:47 redis_init_script
-rwxrwxr-x 1 root root 1.1K Jun 13 06:47 redis_init_script.tpl
-rw-rw-r-- 1 root root 1.8K Jun 13 06:47 redis-sha1.rb
drwxrwxr-x 2 root root  110 Jun 13 06:47 releasetools
-rwxrwxr-x 1 root root 3.7K Jun 13 06:47 speed-regression.tcl
-rwxrwxr-x 1 root root  693 Jun 13 06:47 whatisdoing.sh
[root@localhost utils]# ./install_server.sh 
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] 6379
Please select the redis config file name [/etc/redis/6379.conf] /application/redis/conf/redis.conf
Please select the redis log file name [/var/log/redis_6379.log] /application/redis/log/redis.log
Please select the data directory for this instance [/var/lib/redis/6379] /application/redis/data/
Please select the redis executable path [/usr/local/bin/redis-server] /application/redis/bin/redis-server
Selected config:
Port           : 6379
Config file    : /application/redis/conf/redis.conf
Log file       : /application/redis/log/redis.log
Data dir       : /application/redis/data/
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 utils]# tree /application/redis/
/application/redis/
├── bin
├── conf
│   └── redis.conf
├── data
├── log
│   └── redis.log
└── run

5 directories, 2 files
[root@localhost utils]#

2.6 查看redis启动状态:

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

redis启动OK,这里有个小问题,就是刚才设置redis服务相关参数可能没有生效;我们查看下配置文件:

[root@localhost conf]# grep -E -v "^#|^$" redis.conf 
bind 127.0.0.1
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile /application/redis/log/redis.log
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /application/redis/data/
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
[root@localhost conf]#

没有问题的话检查自启动文件中各个路径修改是否已生效

[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=/var/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]# 

以上路径配置若有问题,可手动修改并重启


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

测试连接:

[root@localhost bin]# /application/redis/bin/redis-cli 
127.0.0.1:6379> info 
# Server
redis_version:3.2.12
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:7e7350d70058cbc5
redis_mode:standalone
os:Linux 3.10.0-327.el7.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:4.8.5
process_id:48434
run_id:e2bea78666a0166f3eab59fd3bd47439d7aba000
tcp_port:6379
uptime_in_seconds:367
uptime_in_days:0
hz:10
lru_clock:5780405
executable:/application/redis/bin/redis-server
config_file:/application/redis/conf/redis.conf

# Clients
connected_clients:1
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0

# Memory
used_memory:822744
used_memory_human:803.46K
used_memory_rss:2228224
used_memory_rss_human:2.12M
used_memory_peak:822744
used_memory_peak_human:803.46K
total_system_memory:1921671168
total_system_memory_human:1.79G
used_memory_lua:37888
used_memory_lua_human:37.00K
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
mem_fragmentation_ratio:2.71
mem_allocator:jemalloc-4.0.3

# Persistence
loading:0
rdb_changes_since_last_save:0
rdb_bgsave_in_progress:0
rdb_last_save_time:1532506694
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:-1
rdb_current_bgsave_time_sec:-1
aof_enabled:0
aof_rewrite_in_progress:0
aof_rewrite_scheduled:0
aof_last_rewrite_time_sec:-1
aof_current_rewrite_time_sec:-1
aof_last_bgrewrite_status:ok
aof_last_write_status:ok

# Stats
total_connections_received:1
total_commands_processed:1
instantaneous_ops_per_sec:0
total_net_input_bytes:31
total_net_output_bytes:9928
instantaneous_input_kbps:0.00
instantaneous_output_kbps:0.00
rejected_connections:0
sync_full:0
sync_partial_ok:0
sync_partial_err:0
expired_keys:0
evicted_keys:0
keyspace_hits:0
keyspace_misses:0
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:0
migrate_cached_sockets:0

# Replication
role:master
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0

# CPU
used_cpu_sys:1.84
used_cpu_user:0.06
used_cpu_sys_children:0.00
used_cpu_user_children:0.00

# Cluster
cluster_enabled:0

# Keyspace
127.0.0.1:6379> set a b
OK
127.0.0.1:6379> get a
"b"
127.0.0.1:6379> set c sss
OK
127.0.0.1:6379> get c
"sss"
127.0.0.1:6379> save
OK
127.0.0.1:6379> 
127.0.0.1:6379>

至此redis安装完成

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值