redis 控制shell脚本

安装方法:

1.centos默认没有安装tcl:
sudo yum install -y tcl
wget http://download.redis.io/releases/redis-2.8.13.tar.gz
tar zxvf redis-2.8.13.tar.gz
cd redis-2.8.13/src
2.安装到指定目录:
sudo make PREFIX=/opt/redis install
3.复制配置文件到安装目录:
cp ../redis.conf /opt/redis
4.修改redis.conf,打开后台运行选项:
daemonize yes
5.启动服务:
sudo /opt/redis/bin/redis-server ../reids.conf

管理脚本:

#!/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/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="/opt/redis/src/redis-server"
prog=$(basename $redis)
REDIS_CONF_FILE="/opt/redis/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
 

设为开机启动

按上面内容编写脚本,vim /etc/init.d/redis

执行权限:chmod +x /etc/init.d/redis

开机自启动

# 尝试启动或停止redis
service redis start
service redis stop

# 开启服务自启动
chkconfig redis on

 

发布日期:
分类:Nosql