Redis 安装 及 主从配置


:Mr.zhou  阅读: 2,977 次

  Redis是一个开源、支持网络、基于内存、键值对存储数据库。与其他非关系型数据库主要不同在于,Redis中值的类型不仅限于字符串(Strings),还支持如下抽象数据类型:(列表)Lists、(集合)Sets、(有序集合)Sorted sets 、(哈希)Hashes。Redis 通过 RDB、AOF 两种方式来实现数据的持久化。

安装Redis

  Redis 源码包保存路径 /usr/local/src

  Redis 软件安装路径 /usr/local/redis

[root@node-a ~]# yum install -y tcl
[root@node-a ~]# cd /usr/local/src/
[root@node-a src]# wget http://download.redis.io/releases/redis-3.2.0.tar.gz
[root@node-a src]# tar xf redis-3.2.0.tar.gz
[root@node-a src]# cd redis-3.2.0
[root@node-a redis-3.2.0]# make
[root@node-a redis-3.2.0]# make test
...
\o/ All tests passed without errors!

Cleanup: may take some time... OK
make[1]: Leaving directory `/usr/local/src/redis-3.2.0/src'
[root@node-a redis-3.2.0]#
[root@node-a redis-3.2.0]# make PREFIX=/usr/local/redis-3.2.0 install
[root@node-a redis-3.2.0]# mkdir /usr/local/redis-3.2.0/{conf,logs,data}
[root@node-a redis-3.2.0]# ln -s /usr/local/redis-3.2.0 /usr/local/redis
[root@node-a redis-3.2.0]# tree /usr/local/redis
/usr/local/redis
├── bin
│   ├── redis-benchmark
│   ├── redis-check-aof
│   ├── redis-check-rdb
│   ├── redis-cli
│   ├── redis-sentinel -> redis-server
│   └── redis-server
├── conf
├── data
└── logs

4 directories, 6 files
[root@node-a redis-3.2.0]#

  可以通过 utils/install_server.sh 交互脚本生成 redis 的配置文件。也可以自己手动修改。

  复制配置文件手动修改。注意配置文件中的 bind 项。

[root@node-a redis-3.2.0]# cp redis.conf /usr/local/redis/conf/6379.conf

[root@node-a redis-3.2.0]# grep -Ev '^$|#' /usr/local/redis/conf/6379.conf
bind 127.0.0.1
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 0
daemonize yes
supervised no
pidfile /var/run/redis_3679.pid
loglevel notice
logfile "/usr/local/redis/logs/6379.log"
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /usr/local/redis/data
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
[root@node-a redis-3.2.0]#

  复制启动脚本,不同的实例,创建不同的启动脚本。根据Redis的安装路径和配置文件修改启动脚本中的路径。

[root@node-a redis-3.2.0]# cp utils/redis_init_script /etc/init.d/redis

[root@node-a redis-3.2.0]# sed -n '6,11p' /etc/init.d/redis
REDISPORT=6379
EXEC=/usr/local/redis/bin/redis-server
CLIEXEC=/usr/local/redis/bin/redis-cli

PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/usr/local/redis/conf/${REDISPORT}.conf"
[root@node-a redis-3.2.0]#

  启动服务

[root@node-a redis-3.2.0]# /etc/init.d/redis start
Starting Redis server...
[root@node-a redis-3.2.0]#

  调整内核参数

[root@node-a redis-3.2.0]# echo 'net.core.somaxconn = 32768' >> /etc/sysctl.conf
[root@node-a redis-3.2.0]# sysctl -p

  测试

[root@node-a redis-3.2.0]# /usr/local/redis/bin/redis-cli
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379> set website 'www.z-dig.com'
OK
127.0.0.1:6379> keys *
1) "website"
127.0.0.1:6379> get website
"www.z-dig.com"
127.0.0.1:6379>


转载请注明原文链接:http://www.z-dig.com/redis-install-and-master-slave-configuration.html



正文部分到此结束