系统AliyunLinux
一、安装Redis(我把redis安装在了/alidata/server/redis下)
1
2
3
4
5
|
去http: //redis .io /download 下载redis用FTP工具传到服务器或者按照redis官网写的步骤进行操作 wget http: //download .redis.io /releases/redis-2 .8.18. tar .gz // 下载 tar xzf redis-2.8.18. tar .gz // 解压 cd redis-2.8.18 make // 编译 |
二、 配置Redis
1
2
3
4
5
6
7
8
|
cp redis.conf /etc/redis .conf #复制一份redis配置文件到etc目录下 打开redis配置文件 vi /etc/redis .conf 修改 daemonize yes #是否作为守护进程运行 dir /var/lib/redis/ 缓存存放位置 useradd redis #增加redis用户 mkdir -p /var/lib/redis #创建db文件夹 chown redis.redis /var/lib/redis #db文件放在这里 |
三、编辑启动脚本(网上找的)
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
|
<span style= "font-family:Microsoft YaHei;font-size:14px;" > # description: Start and Stop redis PATH= /usr/local/bin : /sbin : /usr/bin : /bin REDISPORT=6379 EXEC= /alidata/server/redis-2 .8.18 /src/redis-server REDIS_CLI= /alidata/server/redis-2 .8.18 /src/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 exists, process is not running." else PID=$( cat $PIDFILE) echo "Stopping..." $REDIS_CLI -p $REDISPORT -a $AUTH 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< /span > |
四、加入开机启动项
1
|
vi /etc/rc .d /rc . local |
增加
1
|
/etc/init .d /redis start |
五、测试
在你的站点目录下创建一个php文件
1
2
3
4
|
$redis = new Redis(); $redis->connect( '127.0.0.1' , 6379); $redis-> set ( 'test' , '11111' ); echo $redis->get( 'test' ); |
好了到此为止就配置好了redis,由于本人新手也是在摸索中配置了如有不对的地方欢迎大家指正,不胜感激!