我爱编程

centos 6.5 安装 redis 4.0.2

2017-11-09  本文已影响0人  我不是币神

安装

下载:

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

解压:

# tar zxvf redis-4.0.2.tar.gz

复制到node目录:

# mv redis-4.0.2 node

进入node目录:

# cd  node

编译redis:

# make

正常显示“Hint: To run 'maketest' is a good idea”

执行:

# make install

进入src目录,执行# make test (注意:先安装tcl # yum install tcl)

成功!

启动redis服务:到src目录下执行

# ./redis-server


配置redis.conf

# cd /usr/local/fry/redis

# vim redis.conf

默认是“bind 127.0.0.1 ::1”,改为“bind 0.0.0.0”;

修改启动模式为后台启动 daemonize yes

添加访问密码:去掉“#”符号,将requirepass foobared 中的“foobared”修改为密码,即可。


开机自启动

创建并编辑

# vim /etc/init.d/redis

输入:

# chkconfig: 2345 10 90

# description: Start and Stop redis

PATH=/usr/local/bin:/sbin:/usr/bin:/bin

REDISPORT=6379 #实际环境而定

EXEC=/usr/local/fry/redis/src/redis-server #实际环境而定

REDIS_CLI=/usr/local/fry/redis/src/redis-cli #实际环境而定

PIDFILE=/var/run/redis.pid

CONF="/usr/local/fry/redis/redis.conf" #实际环境而定

case "$1" in

start)

if [ -f $PIDFILE ]

then

echo "$PIDFILE exists, process is already running or crashed."

else

echo "Starting Redis server..."

$EXEC $CONF

fi

if [ "$?"="0" ]

then

echo "Redis is running..."

fi

;;

stop)

if [ ! -f $PIDFILE ]

then

echo "$PIDFILE exists, process is not running."

else

PID=$(cat $PIDFILE)

echo "Stopping..."

$REDIS_CLI -p $REDISPORT SHUTDOWN

while [ -x $PIDFILE ]

do

echo "Waiting for Redis to shutdown..."

sleep 1

done

echo "Redis stopped"

fi

;;

restart|force-reload)

${0} stop

${0} start

;;

*)

echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2

exit 1

esac

执行权限:

# chmod +x /etc/init.d/redis

尝试启动或停止redis:

# service redis start

# service redis stop

开启服务自启动:

# chkconfig redis on

上一篇下一篇

猜你喜欢

热点阅读