redis的优点:支持主从备份,操作指令丰富,支持异步的数据持久化
将 redis 安装到 /usr/local/webserver/redis
1.下载安装包
wget http://redis.googlecode.com/files/redis-2.2.15.tar.gz
tar zxvf redis-2.2.15.tar.gz
cd redis-2.2.15
make
mkdir -p /usr/local/webserver/redis/conf
mkdir -p /usr/local/webserver/redis/run
mkdir -p /usr/local/webserver/redis/db
cp redis.conf /usr/local/webserver/redis/conf/
cd src
2.将 src 目录下所有可执行文件复制到安装目录
cp redis-benchmark redis-check-aof redis-check-dump redis-cli redis-server mkreleasehdr.sh
/usr/local/webserver/redis/
3.修改配置文件
------- vi /usr/local/webserver/redis/conf/redis.conf --------
daemonize yes --yes启用守护进程
pidfile /usr/local/webserver/redis/run/redis.pid --Redis以守护进程方式运行时把pid写入文件
dir /usr/local/webserver/redis/db --数据存放的目录
--------------------------------------------------------------
4.创建启动和停止服务脚本
------- vi /usr/local/webserver/redis/start.sh ---------
#!/bin/bash
/usr/local/webserver/redis/redis-server /usr/local/webserver/redis/conf/redis.conf
------- vi /usr/local/webserver/redis/stop.sh ---------
#!/bin/bash
kill `cat /usr/local/webserver/redis/run/redis.pid`
chmod a+x /usr/local/webserver/redis/start.sh /usr/local/webserver/redis/stop.sh
5.启动 redis 服务
/usr/local/webserver/redis/start.sh
验证证服务是否成功:
netstat -nlpt | grep 6379
6.启动客户端验证
/usr/local/webserver/redis/redis-cli
>set key1 val1
>get key1
二. M/S主从集群配置
1台Master和一台Slave
Master IP:127.0.0.1 PORT:6379
Slave1 IP:127.0.0.1 PORT:63791
2.复制slave目录,方便管理
cp -r /usr/local/webserver/redis /usr/local/webserver/redis-slave1
3.修改slave的配置文件和服务脚本
-- vi /usr/local/webserver/redis-slave1/conf/redis.conf --
port 63791
pidfile /usr/local/webserver/redis-slave1/run/redis.pid
dir /usr/local/webserver/redis-slave1/db
slaveof 127.0.0.1 6379
----------------------------------------------------------
-- vi /usr/local/webserver/redis-slave1/start.sh --
#!/bin/bash
/usr/local/webserver/redis-slave1/redis-server /usr/local/webserver/redis-slave1/conf/redis.conf
---------------------------------------------------
------- vi /usr/local/webserver/redis-slave1/stop.sh ---------
#!/bin/bash
kill `cat /usr/local/webserver/redis-slave1/run/redis.pid`
--------------------------------------------------------
4.启动M/S服务
/usr/local/webserver/redis/start.sh
/usr/local/webserver/redis-slave1/start.sh
验证服务是否正常
netstat -nlpt | grep redis-server
5.验证redis是否有效
/usr/local/webserver/redis/redis-cli [默认连接端口:6379 的 Master服务]
>set key1 val1
>quit
/usr/local/webserver/redis/redis-cli -p 63791 [连接 Slave1 服务]
>get key1
“val1″ (数据成功同步了)
多个slave同理配置。