centos编译安装redis

redis下载地址,下载自己需要的版本: https://redis.io/download

我使用的版本是3.0

mv redis-3.0.7 /usr/local/redis
cd /usr/local/redis/
yum -y install gcc-c++
make MALLOC=libc  && make install
redis-server /usr/local/redis/redis.conf

便可以正常启动

make 过程中需要使用make MALLOC=libc命令,否则会出现以下错误

make[1]: Entering directory /usr/local/redis/src'
CC adlist.o
在包含自 adlist.c:34 的文件中:
zmalloc.h:50:31: 错误:jemalloc/jemalloc.h:没有那个文件或目录
zmalloc.h:55:2: 错误:#error "Newer version of jemalloc required"
make[1]: *** [adlist.o] 错误 1
make[1]: Leaving directory
/usr/local/redis/src’
make: * [all] 错误 2

但是我们实际使用的话这样挺不方便的,一来无法使用service命令进快速启动, 二来也无法开机自启动
vim /etc/init.d/redis

#!/bin/sh 
# 
# redis - this script starts and stops the redis-server daemon 
# 
# chkconfig:   - 85 15
# description:  Redis is a persistent key-value database 
# processname: redis-server 
# config:      /etc/redis.conf 
# config:      /etc/sysconfig/redis 
# pidfile:     /var/run/redis.pid 

# Source function library. 
. /etc/rc.d/init.d/functions 

# Source networking configuration. 
. /etc/sysconfig/network 

# Check that networking is up. 
[ "$NETWORKING" = "no" ] && exit 0

redis="/usr/local/bin/redis-server"
prog=$(basename $redis) 

REDIS_CONF_FILE="/etc/redis.conf"

[ -f /etc/sysconfig/redis ] && . /etc/sysconfig/redis 

lockfile=/var/lock/subsys/redis 

start() { 
    [ -x $redis ] || exit 5
    [ -f $REDIS_CONF_FILE ] || exit 6
    echo -n $"Starting $prog: "
    daemon $redis $REDIS_CONF_FILE 
    retval=$? 
    echo 
    [ $retval -eq 0 ] && touch $lockfile 
    return $retval 
} 

stop() { 
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT 
    retval=$? 
    echo 
    [ $retval -eq 0 ] && rm -f $lockfile 
    return $retval 
} 

restart() { 
    stop 
    start 
} 

reload() { 
    echo -n $"Reloading $prog: "
    killproc $redis -HUP 
    RETVAL=$? 
    echo 
} 

force_reload() { 
    restart 
} 

rh_status() { 
    status $prog 
} 

rh_status_q() { 
    rh_status >/dev/null 2>&1
} 

case "$1" in 
    start) 
        rh_status_q && exit 0
        $1
        ;; 
    stop) 
        rh_status_q || exit 0
        $1
        ;; 
    restart|configtest) 
        $1
        ;; 
    reload) 
        rh_status_q || exit 7
        $1
        ;; 
    force-reload) 
        force_reload 
        ;; 
    status) 
        rh_status 
        ;; 
    condrestart|try-restart) 
        rh_status_q || exit 0
        ;; 
    *) 
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
        exit 2
esac 

chmod +x /etc/init.d/redis

mkdir /etc/redis
cp redis.conf /etc/redis.conf
vim /etc/redis.conf
daemonize yes #只有saemonize设置为yes,才会以后台的方式启动
chkconfig –add redis
service redis start

[root@localhost redis]# chkconfig –list redis
redis 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
[root@localhost redis]# ps aux|grep redis
root 2602 0.0 0.3 31000 1904 ? Ssl 00:17 0:00 /usr/local/bin/redis-server *:6379
root 2608 0.0 0.1 103248 872 pts/0 S+ 00:17 0:00 grep redis

看到以上信息便确定完全成功

生产环境中需要设置Redis最大占用内存,以1GB为例

# In short... if you have slaves attached it is suggested that you set a lower
# limit for maxmemory so that there is some free RAM on the system for slave
# output buffers (but this is not needed if the policy is 'noeviction').
#
# maxmemory <bytes>
maxmemory 1073741824
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值