安装redis:
直接安装:
0 1 2 3 4 5 6 7 8 9 10 |
wget http://download.redis.io/releases/redis-3.2.0.tar.gz tar -zxf redis-3.2.0.tar.gz cd redis-3.2.0/ make MALLOC=jemalloc make PREFIX=/byrd/service/redis-3.2.0 install ln -s /byrd/service/redis-3.2.0 /usr/local/redis mkdir /usr/local/redis/etc cp redis.conf /usr/local/redis/etc/ sysctl -w vm.overcommit_memory=1 echo "512" > /proc/sys/net/core/somaxconn /usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf & |
实操过程:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[root@www tools]# wget http://download.redis.io/releases/redis-3.2.0.tar.gz #下载最新稳定版 [root@www tools]# tar -zxf redis-3.2.0.tar.gz #解压 [root@www tools]# cd redis-3.2.0/ [root@www redis-3.2.0]# make MALLOC=jemalloc #jemalloc适合多线程下内存分配管理 [root@www redis-3.2.0]# make test #yum install tcl才可以test [root@www redis-3.2.0]# make PREFIX=/byrd/service/redis-3.2.0 install 安装 [root@www redis-3.2.0]# ln -s /byrd/service/redis-3.2.0 /usr/local/redis [root@www redis-3.2.0]# mkdir /usr/local/redis/etc [root@www redis-3.2.0]# cp redis.conf /usr/local/redis/etc/ [root@www redis-3.2.0]# echo "512" > /proc/sys/net/core/somaxconn [root@www redis-3.2.0]# sysctl -w vm.overcommit_memory=1 [root@www redis-3.2.0]# /usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf & [root@www redis-3.2.0]# cat /sys/kernel/mm/transparent_hugepage/enabled [always] madvise never [root@www redis-3.2.0]# echo never > /sys/kernel/mm/transparent_hugepage/enabled |
安装脚本:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
#!/bin/bash # Author:Byrd # Version:1.0 # Site:note.t4x.org # Contact:root#t4x.org Tools_Dir=/byrd/tools Insta_Dir=/byrd/service Redis_Down=http://download.redis.io/releases/redis-3.2.0.tar.gz Redis_Conf=/usr/local/redis Retu_Code=0 [ -d $Tools_Dir ] || mkdir $Tools_Dir -p [ -d $Insta_Dir ] || mkdir $Insta_Dir yum install gcc gcc-c++ vim wget tcl tcl-devel -y cd ${Tools_Dir} if [ -d /usr/local/redis/etc ];then echo "Redis Installed" exit 0 fi if [ -f `basename $Redis_Down` ]; then tar zxf `basename $Redis_Down` cd redis-3.2.0 make MALLOC=jemalloc if [ $Retu_Code -eq 0 ];then make PREFIX=${Insta_Dir}/redis-3.2.0 install ln -s ${Insta_Dir}/redis-3.2.0 /usr/local/redis mkdir /usr/local/redis/{etc,cache} cp redis.conf /usr/local/redis/etc sysctl vm.overcommit_memory=1 echo "vm.overcommit_memory = 1" >> /etc/sysctl.conf echo 1024 >/proc/sys/net/core/somaxconn cd $Redis_Conf/etc cp redis.conf redis.conf.$(date +%F) sed -i "s#daemonize no#daemonize yes#g" redis.conf sed -i 's#logfile ""#logfile "/var/log/redis.log"#g' redis.conf sed -i 's#dir ./#dir /usr/local/redis/cache#g' redis.conf sed -i "s#appendonly no#appendonly yes#g" redis.conf sed -i 's/# maxmemory-policy noeviction/maxmemory-policy volatile-ttl/g' redis.conf sed -i 's/# maxmemory <bytes>/maxmemory 536870912/g' redis.conf #512M else echo "Redis Install Error,Please Chenk" exit 1 fi else wget http://download.redis.io/releases/redis-3.2.0.tar.gz tar zxf `basename $Redis_Down` cd redis-3.2.0 make MALLOC=jemalloc if [ $Retu_Code -eq 0 ];then make PREFIX=${Insta_Dir}/redis-3.2.0 install ln -s ${Insta_Dir}/redis-3.2.0 /usr/local/redis mkdir /usr/local/redis/{etc,cache} cp redis.conf /usr/local/redis/etc sysctl vm.overcommit_memory=1 echo "vm.overcommit_memory = 1" >> /etc/sysctl.conf echo 1024 >/proc/sys/net/core/somaxconn cd $Redis_Conf/etc cp redis.conf redis.conf.$(date +%F) sed -i "s#daemonize no#daemonize yes#g" redis.conf sed -i 's#logfile ""#logfile "/var/log/redis.log"#g' redis.conf sed -i 's#dir ./#dir /usr/local/redis/cache#g' redis.conf sed -i "s#appendonly no#appendonly yes#g" redis.conf sed -i 's/# maxmemory-policy noeviction/maxmemory-policy volatile-ttl/g' redis.conf sed -i 's/# maxmemory <bytes>/maxmemory 536870912/g' redis.conf #512M else echo "Redis Install Error,Please Chenk" exit 1 fi fi if [ `netstat -tunlp | grep 6379 | wc -l` -eq 0 ]; then $Redis_Conf/bin/redis-server $Redis_Conf/etc/redis.conf sleep 3 echo "/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf" >>/etc/rc.local if [ `netstat -tunlp | grep 6379 | wc -l` -eq 1 ]; then echo "Redis Running" else echo "plases chk /var/log/redis.log,redis config err maybe" exit 1 fi fi |
过期时间参数说明:SourceByrd's Weblog-https://note.t4x.org/basic/centos-install-redis/
SourceByrd's Weblog-https://note.t4x.org/basic/centos-install-redis/SourceByrd's Weblog-https://note.t4x.org/basic/centos-install-redis/[volatile-lru|allkeys-lru|volatile-random|allkeys-random|volatile-ttl|volatile-lfu|allkeys-lfu|noeviction]
VolatileLRU
按照LRU算法逐出原有数据,但仅逐出设置了过期时间的数据
VolatileTTL
仅逐出设置了过期时间的数据,并且是按照TTL有小到大的顺序进行逐出
AllKeysLRU
按照LRU算法逐出原有数据
VolatileRandom
随机逐出原有数据,但仅逐出设置了过期时间的数据
AllKeysRandom
随机逐出原有数据
NoEviction
不逐出任何数据,新数据的写入会得到一个错误信息
VolatileLFU
只从设置失效(expire set)的key中选择最不常用的key进行删除
AllkeysLFU
优先删除掉最不常用的key SourceByrd's Weblog-https://note.t4x.org/basic/centos-install-redis/
申明:除非注明Byrd's Blog内容均为原创,未经许可禁止转载!详情请阅读版权申明!