为了MUEAS项目的session管理要求,启用redis进行session管理。
首先,就是redis的安装,本博记录的是redis 3.0.6版本。 下载地址http://redis.io/download
安装过程比较简单,解压缩后,直接make进行编译,然后就是安装,如下所示:
1 [root@CloudGame redis-3.0.6]# ll 2 total 152 3 -rw-rw-r-- 1 root root 34339 Dec 18 23:19 00-RELEASENOTES 4 -rw-rw-r-- 1 root root 53 Dec 18 23:19 BUGS 5 -rw-rw-r-- 1 root root 1805 Dec 18 23:19 CONTRIBUTING 6 -rw-rw-r-- 1 root root 1487 Dec 18 23:19 COPYING 7 drwxrwxr-x 6 root root 4096 Dec 29 09:11 deps 8 -rw-rw-r-- 1 root root 11 Dec 18 23:19 INSTALL 9 -rw-rw-r-- 1 root root 151 Dec 18 23:19 Makefile 10 -rw-rw-r-- 1 root root 4223 Dec 18 23:19 MANIFESTO 11 -rw-rw-r-- 1 root root 5201 Dec 18 23:19 README 12 -rw-rw-r-- 1 root root 41560 Dec 18 23:19 redis.conf 13 -rwxrwxr-x 1 root root 271 Dec 18 23:19 runtest 14 -rwxrwxr-x 1 root root 280 Dec 18 23:19 runtest-cluster 15 -rwxrwxr-x 1 root root 281 Dec 18 23:19 runtest-sentinel 16 -rw-rw-r-- 1 root root 7109 Dec 18 23:19 sentinel.conf 17 drwxrwxr-x 2 root root 4096 Dec 29 09:12 src 18 drwxrwxr-x 10 root root 4096 Dec 18 23:19 tests 19 drwxrwxr-x 5 root root 4096 Dec 18 23:19 utils 20 [root@CloudGame redis-3.0.6]# make PREFIX=/usr/local/redis-3.0.6 install
安装就算结束了,接下来,就是最基本的一些配置信息了,让redis-server启动。至于详细的配置信息,比如端口,监听的IP,是否支持主从复制,是否支持集群等,可以参照配置文件的解说进行。
1 [root@CloudGame utils]# ./install_server.sh 2 Welcome to the redis service installer 3 This script will help you easily set up a running redis server 4 5 Please select the redis port for this instance: [6379] 6 Selecting default: 6379 7 Please select the redis config file name [/etc/redis/6379.conf] 8 Selected default - /etc/redis/6379.conf 9 Please select the redis log file name [/var/log/redis_6379.log] 10 Selected default - /var/log/redis_6379.log 11 Please select the data directory for this instance [/var/lib/redis/6379] 12 Selected default - /var/lib/redis/6379 13 Please select the redis executable path [] /usr/local/redis-3.0.6/bin/redis-server 14 Selected config: 15 Port : 6379 16 Config file : /etc/redis/6379.conf 17 Log file : /var/log/redis_6379.log 18 Data dir : /var/lib/redis/6379 19 Executable : /usr/local/redis-3.0.6/bin/redis-server 20 Cli Executable : /usr/local/redis-3.0.6/bin/redis-cli 21 Is this ok? Then press ENTER to go on or Ctrl-C to abort. 22 Copied /tmp/6379.conf => /etc/init.d/redis_6379 23 Installing service... 24 Successfully added to chkconfig! 25 Successfully added to runlevels 345! 26 Starting Redis server... 27 Installation successful!
本安装过程,采用的全是默认配置,其中,需要说明的是,选择可执行文件路径,这个需要根据自己的redis的实际安装情况进行操作,比如我这里安装在/usr/local/redis-3.0.6/bin,则,在安装配置信息(如上红色部分就要指定到可执行文件的路径)。
为了使用命令方便,将安装路径添加到profile文件中(环境变量):
1 SBT_HOME=/usr/local/sbt 2 SCALA_HOME=/usr/local/scala-2.11.7 3 REDIS_HOME=/usr/local/redis-3.0.6 4 PATH=$GIT_HOME/bin:$GIT_HOME/libexec/git-core:$PRV_HOME/bin:$SBT_HOME/bin:$SCALA_HOME/bin:$REDIS_HOME/bin:$PATH 5 export GIT_HOME SBT_HOME SCALA_HOME REDIS_HOME PATH
为了安全的起见,我设置了redis server需要密码认证,这个可以在/etc/redis/6379.conf文件中修改,我就是这么做的:
1 ################################## SECURITY ################################### 2 3 # Require clients to issue AUTH <PASSWORD> before processing any other 4 # commands. This might be useful in environments in which you do not trust 5 # others with access to the host running redis-server. 6 # 7 # This should stay commented out for backward compatibility and because most 8 # people do not need auth (e.g. they run their own servers). 9 # 10 # Warning: since Redis is pretty fast an outside user can try up to 11 # 150k passwords per second against a good box. This means that you should 12 # use a very strong password otherwise it will be very easy to break. 13 # 14 requirepass 你自己的密码
设置了密码后,登录server的时候,是否带密码都可以连接上来,但是执行命令操作,就会出现错误:
1 [root@CloudGame redis-3.0.6]# redis-cli 2 127.0.0.1:6379> config get requirepass 3 (error) NOAUTH Authentication required. 4 127.0.0.1:6379>
当带着密码登录,就可以正常操作:
1 [root@CloudGame redis-3.0.6]# redis-cli -a 你的密码 2 127.0.0.1:6379> config get requirepass 3 1) "requirepass" 4 2) "你的密码" 5 127.0.0.1:6379>
到此,redis的基本安装和配置,就到此结束,有特别性能上的要求,可以对/etc/redis/6379.conf文件进行配置。这个配置涉及到的东西太多,依据具体需求而定。