宗小宗-PHP程序猿

欢迎各位朋友前来,如果我的文章中有不对的地方,还望指正;如需转载,请注明原处

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

  添加如下代码

  

 1 #!/bin/sh
 2 #chkconfig: 345 86 14
 3 #description: Startup and shutdown script for Redis
 4  
 5 PROGDIR=/usr/local/redis/bin #安装路径
 6 PROGNAME=redis-server
 7 DAEMON=$PROGDIR/$PROGNAME
 8 CONFIG=/usr/local/redis/conf/6379.conf
 9 PIDFILE=/var/run/redis-6379.pid
10 DESC="redis daemon"
11 SCRIPTNAME=/etc/init.d/redis
12  
13 start()
14 {
15          if test -x $DAEMON
16          then
17         echo -e "Starting $DESC: $PROGNAME"
18                    if $DAEMON $CONFIG
19                    then
20                             echo -e "OK"
21                    else
22                             echo -e "failed"
23                    fi
24          else
25                    echo -e "Couldn't find Redis Server ($DAEMON)"
26          fi
27 }
28  
29 stop()
30 {
31          if test -e $PIDFILE
32          then
33                    echo -e "Stopping $DESC: $PROGNAME"
34                    if kill `cat $PIDFILE`
35                    then
36                             echo -e "OK"
37                    else
38                             echo -e "failed"
39                    fi
40          else
41                    echo -e "No Redis Server ($DAEMON) running"
42          fi
43 }
44  
45 restart()
46 {
47     echo -e "Restarting $DESC: $PROGNAME"
48     stop
49          start
50 }
51  
52 list()
53 {
54          ps aux | grep $PROGNAME
55 }
56  
57 case $1 in
58          start)
59                    start
60         ;;
61          stop)
62         stop
63         ;;
64          restart)
65         restart
66         ;;
67          list)
68         list
69         ;;
70  
71          *)
72         echo "Usage: $SCRIPTNAME {start|stop|restart|list}" >&2
73         exit 1
74         ;;
75 esac
76 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

 

posted @ 2016-06-17 11:30  宗小宗  阅读(291)  评论(0编辑  收藏  举报