一、安裝redis
1) 本實(shí)驗(yàn)采用一主一從,后面文章會持續(xù)講解redis主從,哨兵,cluster
2) 主庫 192.168.12.131:7001
3) 從庫 192.168.12.131:7002
4) wget http://download.redis.io/releases/redis-3.2.6.tar.gz
5) tar zxf redis-3.2.6.tar.gz;mv redis-3.2.6 redis
6) 進(jìn)入redis目錄執(zhí)行make;make install 完成編譯安裝
二、配置Redis
1) 打開redis.conf修改以下參數(shù)
2) bind 127.0.0.1 修改為 bind 192.168.12.131
3) protected-mode yes 修改為no
4) port 6379 修改為7001
5) daemonize no 修改為 yes
6) pidfile /var/run/redis_6379.pid 6379修改為7001
7) logfile "" 修改為 logfile "/usr/local/software/redis/logs/redis_7001.log"
8) dir ./ 修改為 dir /usr/local/software/redis/data/7001
9) 需要創(chuàng)建data 、logs目錄,其他配置目前保持默認(rèn)
10) mv redis.conf redis_7001.conf; cp redis_7001.conf redis_7002.conf
11) 編輯redis_7002.conf把7001全部修改為7002
12) slaveof <masterip> <masterport> 修改為slaveof 192.168.12.131 7001 高版本此參數(shù) 為replicaof
13) ln -s /usr/local/software/redis/src/redis-* /usr/bin/
三、啟動Redis并查看主從狀態(tài)
1) 啟動redis 命令如下
/usr/bin/redis-server /usr/local/software/redis/redis_7001.conf
/usr/bin/redis-server /usr/local/software/redis/redis_7002.conf
2) 查看端口及進(jìn)程狀態(tài)
3) 登錄7001及7002查看主從狀態(tài)
4) 在主庫上寫入數(shù)據(jù)查看從庫是否同步
7001主庫
7002從庫
5)把Redis服務(wù)添加到開機(jī)啟動項(xiàng)
1) 進(jìn)入/usr/local/software/redis/utils 目錄執(zhí)行cp redis_init_script /etc/init.d/redis
2) 修改/etc/init.d/redis配置文件如下,并添加服務(wù)chkconfig --add redis
6)Redis啟動項(xiàng)描述信息
#!/bin/sh
# chkconfig: 2345 10 90
# description: Start and Stop redis
# Simple Redis init.d script conceived to work on linux systems
# as it does use of the /proc filesystem.
### BEGIN INIT INFO
# Provides: redis_6379
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Redis data structure server
# Description: Redis data structure server. See https://redis.io
### END INIT INFO