redis在linux中的安装启动

1. 拖到 /usr/local 下

2. 解压    

    tar zxf redis-4.0.8.tar.gz

3. mkdir /usr/redis

4. 编译

    cd redis-4.0.8/src
    make

    make完后 redis-4.0.8里的SRC目录里有四个可执行文件redis-server、redis-benchmark、redis-cli和redis.conf。

   把这四个文件拷贝到 /usr/redis里面

  mv redis-server /usr/redis
  mv redis-benchmark /usr/redis
  mv redis-cli /usr/redis
  mv redis.conf /usr/redis

5. yum install redis

   然后编写脚本

# chkconfig: 2345 10 90  
# description: Start and Stop redis   
  
PATH=/usr/local/bin:/sbin:/usr/bin:/bin   
REDISPORT=6379  
EXEC=/usr/bin/redis-server   
REDIS_CLI=/usr/bin/redis-cli   
 
PIDFILE=/var/run/redis.pid   
CONF="/etc/redis.conf"  
#AUTH="1234" 设置的redis的密码  

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    
                        sleep 2  
                       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

6. 设置权限

    chmod 755 redis

7. 设置开机自启

     chkconfig redis on

8. 永久关闭防火墙

linux永久关闭防火墙
#关闭iptable
/etc/init.d/iptables stop
#查看iptables 是否关闭
/etc/init.d/iptables status
# 关闭iptables的开机自启动
chkconfig iptables off

9. 重新启动Linux

    reboot

 

上一篇:Redis安装配置


下一篇:redis安装与配置