coentos 安装redis

2019-02-15  本文已影响0人  才不是小小喵
  1. 下载redis
wget http://download.redis.io/releases/redis-5.0.3.tar.gz
tar -zxvf redis-5.0.3.tar.gz
cd redis-5.0.3
make
cd src
make install PREFIX=/usr/local/redis
  1. 移动配置文件到安装目录下
cd ../
mv redis.conf /usr/local/redis
  1. 设置redis为后台与开机启动
#将 daemonize no 改成 daemonize yes
vi /usr/local/redis/redis.conf
daemonize no 改成 daemonize yes

#加入里面
vi /etc/rc.local
/usr/local/redis/bin/redis-server   /usr/local/redis/redis.conf
  1. 开启redis
/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf &
#查看默认端口6379
/usr/local/redis/bin/redis-cli
  1. 开启远程访问
vi /usr/local/redis/redis.conf
将 bind 127.0.0.1 注释 #bind 127.0.0.1
protected-mode 改为 no

requirepass testpassword 初始化密码
重启redis 并客户端测试连接
  1. redis 启动脚本
vi /etc/init.d/redis
chmod +x /etc/init.d/redis
service redis start
service redis stop

redis.sh 注意bin目录

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

source /etc/init.d/functions
REDISPORT=6379
BIN="/usr/local/redis/bin"
CONFIG="/usr/local/redis/redis.conf"
PIDFILE="/var/run/redis_${REDISPORT}.pid"


### Read configuration
[ -r "$SYSCONFIG" ] && source "$SYSCONFIG"

RETVAL=0
prog="redis-server"
desc="Redis Server"

start() {

if [ -f $PIDFILE ]
    then
        echo "$PIDFILE exists, process is already running or crashed"
    else
        echo "Starting Redis server..."
        daemon $BIN/$prog $CONFIG
fi

if [ "$?"="0" ]  
    then  
        echo "Redis is running..." 
fi  

RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
return $RETVAL
}

stop() {
        echo -n $"Stop $desc: "
        redispid=$(cat $PIDFILE)
        kill $redispid 
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog $PIDFILE
        return $RETVAL
}

restart() {
    stop
    start
}

case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        restart
        ;;
  condrestart)
        [ -e /var/lock/subsys/$prog ] && restart
        RETVAL=$?
        ;;
  status)
        status $prog
        RETVAL=$?
        ;;
   *)
        echo $"Usage: $0 {start|stop|restart|condrestart|status}"
        RETVAL=1
esac

exit $RETVAL
  1. 配置环境变量
vi /etc/profile.d/redis.sh
export REDIS_HOME=/usr/local/redis
export PATH=$PATH:$REDIS_HOME/bin
source /etc/profile.d/redis.sh
  1. 配置内核参数
vi /etc/sysctl.conf
vm.overcommit_memory = 1 

完成后 
sysctl -p
上一篇下一篇

猜你喜欢

热点阅读