歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux基礎知識

Linux 安裝 Redis 服務

下載地址 http://download.redis.io/releases/redis-3.2.0.tar.gz

官網下載地址 http://redis.io/download

 

1。下載安裝包

  cd /tmp

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

2。解壓

  tar -zxvf redis-3.2.0.tar.gz

3。安裝

  mkdir /usr/local/redis

  cd redis-3.2.0

  make PREFIX=/usr/local/redis install     //我將redis安裝到/usr/local/redis下

4。修改配置文件

  cd /usr/local/redis

  mkdir conf

  cp /tmp/redis-3.2.0/redis.conf /usr/local/redis/conf/6379.conf

  將6379.conf文件中的daemonize no修改為daemonize yes使redis在後台啟動

5。啟動redis

  /usr/local/redis/bin/redis-server /usr/local/redis/conf/6379.conf

6。ps -ef|grep redis查看是否啟動

 

------------------------------------------------------------------------------------------------------------------------------------------------------

擴充

如果想將redis加入服務中

1.新建redis啟動腳本

  vim /etc/ini.d/redis

  添加如下代碼

  

 #!/bin/sh
 #chkconfig: 345 86 14
 #description: Startup and shutdown script for Redis
  
 PROGDIR=/usr/local/redis/bin #安裝路徑
 PROGNAME=redis-server
 DAEMON=$PROGDIR/$PROGNAME
 CONFIG=/usr/local/redis/conf/6379.conf
 PIDFILE=/var/run/redis-6379.pid
 DESC="redis daemon"
 SCRIPTNAME=/etc/init.d/redis
  
 start()
 {
          if test -x $DAEMON
          then
         echo -e "Starting $DESC: $PROGNAME"
                    if $DAEMON $CONFIG
                    then
                             echo -e "OK"
                    else
                             echo -e "failed"
                    fi
          else
                    echo -e "Couldn't find Redis Server ($DAEMON)"
          fi
 }
  
 stop()
 {
          if test -e $PIDFILE
          then
                    echo -e "Stopping $DESC: $PROGNAME"
                    if kill `cat $PIDFILE`
                    then
                             echo -e "OK"
                    else
                             echo -e "failed"
                    fi
          else
                    echo -e "No Redis Server ($DAEMON) running"
          fi
 }
  
 restart()
 {
     echo -e "Restarting $DESC: $PROGNAME"
     stop
          start
 }
  
 list()
 {
          ps aux | grep $PROGNAME
 }
  
 case $1 in
          start)
                    start
         ;;
          stop)
         stop
         ;;
          restart)
         restart
         ;;
          list)
         list
         ;;
  
          *)
         echo "Usage: $SCRIPTNAME {start|stop|restart|list}" >&2
         exit 1
         ;;
 esac
 exit 0
View Code

 

2.其他操作

cd /etc/ini.d/

chmod +x redis 

chkconfig --add redis

chkconfig --level 345 redis on

chkconfig --list redis

service redis start

Copyright © Linux教程網 All Rights Reserved