欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Linux Centos6.8 安装配置Readis3.2.8

程序员文章站 2024-03-11 10:31:49
...

1:下载

wget  http://download.redis.io/releases/redis-3.2.8.tar.gz


2:解压

tar zxvf redis-3.2.8.tar.gz


3:编译并指定安装目录

make PREFIX=/usr/local/redis-3.2.8 install


4: 添加修改配置文件

cp redis.conf /etc/redis.conf
vim /etc/redis.conf

将  daemonize no  改为 daemonize yes

说明:将Redis设置为后台进程


5:创建redis用户

useradd -r -s /sbin/nologin -M redis


6:创建编辑启动脚本

vim /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"
# this is install catalog
exec="/usr/local/redis-3.2.8/bin/$name"
pidfile="/var/run/redis/redis.pid"
# this is configureFile
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 $?


7:修改文件权限

chmod 755 /etc/init.d/redis


8:设置开机启动

chkconfig --add redis
chkconfig redis on


9:启动redis

service redis start


10:进入redis

/usr/local/redis-3.2.8/bin/redis-cli -h 127.0.0.1 -p 6379


说明:

如果你需要配置密码

vim /etc/redis.conf
去掉requirepass前边的注释  更改自己的密码 requirepass password
再次进入redis 则为

/usr/local/redis-3.2.8/bin/redis-cli -h 127.0.0.1 -p 6379 -a password


一些基础命令

set k v  创建kv值
key *    查看所有键
get k    根据K返回V


上一篇: linux centos6.8 svn的安装配置

下一篇: