CentOS7.2安装Redis3.0

511遇见多次介绍了redis的安装,它的缓存性能这里就不啰嗦,今天我们测试的版本都比较新,注意版本的核对,和命令顺利。

确认一下centos的版本

[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core) 

一、安装依赖包和开发工具:

yum install vim vim-enhanced wget zip unzip telnet ntsysv compat* apr* nasm* gcc gcc* gcc-c++ ntp make imake cmake automake autoconf python-devel zlib zlib-devel glibc glibc-devel glib2 libxml glib2-devel libxml2 libxml2-devel bzip2 bzip2-devel libXpm libXpm-devel libidn libidn-devel libtool libtool-ltdl-devel* libmcrypt libmcrypt-devel libevent-devel libmcrypt* libicu-devel libxslt-devel postgresql-devel curl curl-devel perl perl-Net-SSLeay pcre pcre-devel ncurses ncurses-devel openssl openssl-devel openldap openldap-devel openldap-clients openldap-servers krb5 krb5-devel e2fsprogs e2fsprogs-devel libjpeg libpng libjpeg-devel libjpeg-6b libjpeg-devel-6b libpng-devel libtiff-devel freetype freetype-devel fontconfig-devel gd gd-devel kernel screen sysstat flex bison nss_ldap pam-devel compat-libstdc++-33

二、解压、编译、安装redis_3.0:


tar zxvf redis-3.0.7.tar.gz -C /usr/src/
cd /usr/src/redis-3.0.7/
make && make install

三、创建redis相关目录:

mkdir -p /home/redis/log
mkdir -p /home/redis/pid
mkdir -p /home/redis/db
mkdir -p /etc/redis/

四、编辑redis.conf配置文件:

cp /usr/src/redis-3.0.7/redis.conf /etc/redis/redis.conf
ln -s /etc/redis/redis.conf /etc/redis.conf
vim /etc/redis.conf
daemonize yes
pidfile "/home/redis/pid/redis.pid"
port 6379
tcp-backlog 511
timeout 30
tcp-keepalive 0
loglevel notice
logfile "/home/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 "/home/redis/db"
requirepass "redis-Passw0rd!"
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
rename-command CONFIG ""
rename-command FLUSHALL ""
rename-command FLUSHDB ""
rename-command KEYS ""
maxmemory 1G
appendonly yes
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-entries 512
list-max-ziplist-value 64
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

五、编写redis启动脚本:

vim /etc/init.d/redis
  1. #!/bin/sh
  2. # chkconfig:        2345 60 40
  3. # Description:        Start and Stop redis
  4. # Provides:        redis
  5. # Default-Start:    2 3 4 5
  6. # Default-Stop:        0 1 6
  7. PATH=/usr/local/bin:/sbin:/usr/bin:/bin
  8. REDISPORT=6379
  9. EXEC=/usr/local/bin/redis-server
  10. REDIS_CLI=/usr/local/bin/redis-cli
  11. PIDFILE=/home/redis/pid/redis.pid
  12. CONF="/etc/redis/redis.conf"
  13. case "$1" in
  14. start)
  15. if [ -f $PIDFILE ]
  16. then
  17. echo "$PIDFILE exists, process is already running or crashed"
  18. else
  19. echo "Starting Redis server..."
  20. $EXEC $CONF
  21. fi
  22. if [ "$?"="0" ] 
  23. then
  24. echo "Redis is running..."
  25. fi
  26. ;;
  27. stop)
  28. if [ ! -f $PIDFILE ]
  29. then
  30. echo "$PIDFILE does not exist, process is not running"
  31. else
  32. PID=$(cat $PIDFILE)
  33. echo "Stopping Redis server..."
  34. $REDIS_CLI -p $REDISPORT SHUTDOWN
  35. while [ -x ${PIDFILE} ]
  36. do
  37. echo "Waiting for Redis to shutdown ..."
  38. sleep 1
  39. done
  40. echo "Redis is stopped"
  41. fi
  42. ;;
  43. restart|reload)
  44. ${0} stop
  45. ${0} start
  46. ;;
  47. *)
  48. echo "Usage: /etc/init.d/redis {start|stop|restart|reload}" >&2
  49. exit 1
  50. esac

六、添加redis系统服务:

chmod a+x /etc/init.d/redis
chkconfig --add redis
chkconfig --level 2345 redis on
chkconfig --list | grep redis

七、启动redis服务:


service redis start
ps -aux | grep redis
netstat -anptu | grep 6379

八、测试:

redis-cli -h 127.0.0.1 -p 6379 -a redis-Passw0rd!

九、防火墙启用6379端口:

iptables -A INPUT -p tcp --dport 6379 -j ACCEPT

发布日期:

所属分类: 手游单机 标签:  


没有相关文章!