Fedora下redis安装及配置

下载:

$ wget http://download.redis.io/releases/redis-2.8.3.tar.gz $ tar xzf redis-2.8.3.tar.gz $ cd redis-2.8.3 $ make 

编译好以后运行服务器:

$ src/redis-server 

运行客户端测试同服务器交互:

$ src/redis-cli redis> set foo bar OK redis> get foo "bar" 




另:如果下载时遇到底下的情况

[root@localhost ~]# wget
-bash: wget: command not found

则安装wget

[root@localhost ~]# yum install wget

=================================================

设置开机启动

1. 设置开机启动,关机自动关闭


[root@localhost ~]# mv redis-server /etc/init.d/redis-server


2、下载配置文件和init启动脚本:

1 wget https://github.com/ijonas/dotfiles/raw/master/etc/init.d/redis-server
2 wget https://github.com/ijonas/dotfiles/raw/master/etc/redis.conf
3 sudo mv redis-server /etc/init.d/redis-server
4 sudo chmod +x /etc/init.d/redis-server
5 sudo mv redis.conf /etc/redis.conf

3、初始化用户和日志路径

第一次启动Redis前,建议为Redis单独建立一个用户,并新建data和日志文件夹

1 sudo useradd redis
2 sudo mkdir -p /var/lib/redis
3 sudo mkdir -p /var/log/redis
4 sudo chown redis.redis /var/lib/redis
5 sudo chown redis.redis /var/log/redis


启动脚本:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
###########################
PATH= /usr/local/bin : /sbin : /usr/bin : /bin
   
REDISPORT=6379
EXEC= /usr/local/bin/redis-server
REDIS_CLI= /usr/local/bin/redis-cli
   
PIDFILE= /var/run/redis .pid
CONF= "/etc/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 does not exist, 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
##############################


把上述代码存为redis,放到/etc/init.d/下面

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


其实做成服务启动,也是调用redis-server,如果想让它在后台作为daemon运行,那么

需要修改redis.conf,将 daemonize no 改为 daemonize yes

4,设定开机启动服务

1
sudo  chkconfig redis on


5,启动,停止redis
启动:

1
service redis start    #或者 /etc/init.d/redis start

停止:

1
service redis stop    #或者 /etc/init.d/redis stop



你可能感兴趣的:(redis,服务器)