Linux Centos6.8 安装redis

1.下载: wget  http://download.redis.io/releases/redis-3.2.9.tar.gz

2.解压: tar zxvf redis-3.2.9.tar.gz

3.进入目录: cd redis-3.2.9

编译并指定安装目录: make PREFIX=/usr/local/redis-3.2.9 install

4.创建软链接: ln -s /usr/local/redis-3.2.9 /usr/local/redis

cp redis.conf /etc/redis.conf

5.编辑/etc/redis.conf

daemonize no  ==> daemonize yes    (设置redis为后台daemon进程)

6.创建redis用户

[root@redis-server ~]# useradd -r -s /sbin/nologin -M redis

7.创建启动脚本/etc/init.d/redis

#!/bin/sh

#

# redis        init file for starting up the redis daemon

#

# chkconfig:  - 20 80

# description: Starts and stops the redis daemon.

# Source function library.

#!/bin/sh

#

# redis        init file for starting up the redis daemon

#

# chkconfig:  - 20 80

# description: Starts and stops the redis daemon.

# Source function library.

. /etc/rc.d/init.d/functions

name="redis-server"

exec="/usr/local/redis/bin/$name"

pidfile="/var/run/redis/redis.pid"

REDIS_CONFIG="/etc/redis.conf"

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

lockfile=/var/lock/subsys/redis

start() {

[ -f $REDIS_CONFIG ] || exit 6

[ -x $exec ] || exit 5

echo -n $"Starting $name: "

daemon --user ${REDIS_USER-redis} "$exec $REDIS_CONFIG"

retval=$?

echo

[ $retval -eq 0 ] && touch $lockfile

return $retval

}

stop() {

echo -n $"Stopping $name: "

killproc -p $pidfile $name

retval=$?

echo

[ $retval -eq 0 ] && rm -f $lockfile

return $retval

}

restart() {

stop

start

}

reload() {

false

}

rh_status() {

status -p $pidfile $name

}

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)

$1

;;

reload)

rh_status_q || exit 7

$1

;;

force-reload)

force_reload

;;

status)

rh_status

;;

condrestart|try-restart)

rh_status_q || exit 0

restart

;;

*)

echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart}"

exit 2

esac

exit $?

8. 修改脚本文件权限

[root@redis-server ~]# chmod 755 /etc/init.d/redis

9. 添加进service服务管理并设置开机启动

[root@redis-server ~]# chkconfig --add redis

[root@redis-server ~]# chkconfig redis on

10. redis服务测试

service redis start

11. 连接测试(通过自带redis-cli命令连接测试)

[root@redis-server ~]# /usr/local/redis/bin/redis-cli -h 127.0.0.1 -p 6379

你可能感兴趣的:(Linux Centos6.8 安装redis)