Redis Codis集群

1、软件环境

用六台机器,系统CentOS7 64位,IP和程序分布表

每台服务器执行依赖安装 :yum install autoconf automake libtool -y

序号    名称    IP    部署程序

2、安装Zookeeper集群

参考Zookeeper集群安装部署文档,此处不在说明。

3、安装go语言

注释:需在每台服务器上执行

#wget https://dl.google.com/go/go1.10.2.linux-amd64.tar.gz

#tar -zxf go1.10.2.linux-amd64.tar.gz -C /usr/local/

#cat << EOF >>/etc/profile

export PATH=$PATH:/usr/local/go/bin

export GOROOT=/usr/local/go

export GOPATH=/usr/local/go/work

path=$PATH:$HOME/bin:$GOROOT/bin:$GOPATH/bin

EOF

#source /etc/profile

4、安装codis

注释:需在每台服务器上执行

#wget https://github.com/CodisLabs/codis/archive/release3.2.zip

#mkdir -p $GOPATH/src/github.com/CodisLabs

#cd /usr/local/go/work/src/github.com/CodisLabs

#unzip /application/tools/release3.2

#mv codis-release3.2/ codis

#cd codis/

#make

5、规划Codis目录

注释:需在每台服务器上执行

#cd /data/codis

#mkdir bin conf log proc redis

#cp -fr /usr/local/go/work/src/github.com/CodisLabs/codis/bin/* ./bin/

#cp -fr /usr/local/go/work/src/github.com/CodisLabs/codis/config/* ./conf/

6、配置

6.1 Codis-1A 上配置condis-fe

配置codis.json

# vim codis.json

[

{

"name": "codis-cluster",

"dashboard": "192.168.0.234:18030"

}

]

启动:

nohup /data/codis/redis/bin/codis-fe --ncpu=2 --log=/data/codis/log/fe.log --log-level=WARN --dashboard-list=/data/codis/conf/codis.json --listen=192.168.0.234:8080 >/dev/null 2>&1 &

通过网页访问:http://192.168.0.234:8080 可以看到codis的管理页面:

6.2 Codis-1A 上配置dashboar

配置dashboard.conf

# vim dashboard.conf

# "zookeeper" 集群地址

coordinator_name = "zookeeper"

coordinator_addr = "192.168.1.5:2181,192.168.1.6:2181,192.168.1.7:2181"

# Set Codis Product {Name/Auth}.

product_name = "codis-cluster"

product_auth = "szyq*@root@@@**"

# 自身服务运维的密码和端口

admin_addr = "192.168.0.234:18030"

启动:

nohup /data/codis/redis/bin/codis-dashboard --ncpu=4 --config=/data/codis/conf/dashboard.conf --log=/data/codis/log/dashboard.log --log-level=WARN >/dev/null 2>&1 &

6.3 Codis-1A 上配置Sentinel

配置sentinel.conf 每台服务都需配置,更改为本机IP即可

# vim sentinel.conf

bind 192.168.0.234

protected-mode no

port 26379

dir "/data/codis/redis/data"

pidfile "/data/codis/run/sentinel_26379.pid"

logfile "/data/codis/log/sentinel_26379.log"

daemonize yes

# Generated by CONFIG REWRITE

sentinel myid cb659bb6f5cfdf13ab31539e3e604d332b6c00e8

sentinel monitor codis-cluster-2 192.168.0.236 16379 2

sentinel failover-timeout codis-cluster-2 300000

sentinel auth-pass codis-cluster-2 szyq*@root@@@**

sentinel config-epoch codis-cluster-2 0

sentinel leader-epoch codis-cluster-2 0

sentinel known-slave codis-cluster-2 192.168.0.237 16380

sentinel monitor codis-cluster-3 192.168.0.239 16379 2

sentinel failover-timeout codis-cluster-3 300000

sentinel auth-pass codis-cluster-3 szyq*@root@@@**

sentinel config-epoch codis-cluster-3 0

sentinel leader-epoch codis-cluster-3 0

sentinel known-slave codis-cluster-3 192.168.0.238 16380

sentinel monitor codis-cluster-1 192.168.0.234 16379 2

sentinel failover-timeout codis-cluster-1 300000

sentinel auth-pass codis-cluster-1 szyq*@root@@@**

sentinel config-epoch codis-cluster-1 0

sentinel leader-epoch codis-cluster-1 0

sentinel known-slave codis-cluster-1 192.168.0.235 16380

sentinel current-epoch 13

启动:

nohup /data/codis/redis/bin/redis-sentinel /data/codis/conf/sentinel.conf >/dev/null 2>&1 &

6.4 Codis-1A 上配置Proxy

配置proxy.conf 每台服务都需配置,更改为本机IP即可

#vim proxy.conf

product_name = "codis-cluster"

product_auth = "szyq*@root@@@**"

session_auth = "szyq*@root@@@**"

admin_addr = "192.168.0.234:11080" ##设置本机IP地址

proto_type = "tcp4"

proxy_addr = "0.0.0.0:19000" ##自身服务端口

jodis_name = "zookeeper" ##zookeeper集群

jodis_addr = "192.168.1.5:2181,192.168.1.6:2181,192.168.1.7:2181/codis"

jodis_auth = ""

jodis_timeout = "20s"

jodis_compatible = true

proxy_max_clients = 1000

proxy_max_offheap_size = "1024mb"

proxy_heap_placeholder = "256mb"

backend_ping_period = "5s"

backend_recv_bufsize = "128kb"

backend_recv_timeout = "30s"

backend_send_bufsize = "128kb"

backend_send_timeout = "30s"

backend_max_pipeline = 20480

backend_primary_only = false

backend_primary_parallel = 1

backend_replica_parallel = 1

backend_keepalive_period = "75s"

backend_number_databases = 16

session_recv_bufsize = "128kb"

session_recv_timeout = "30m"

session_send_bufsize = "64kb"

session_send_timeout = "30s"

session_max_pipeline = 10000

session_keepalive_period = "75s"

an error response to client.

session_break_on_failure = false

specified server in a predefined period.

metrics_report_server = ""

metrics_report_period = "1s"

metrics_report_influxdb_server = ""

metrics_report_influxdb_period = "1s"

metrics_report_influxdb_username = ""

metrics_report_influxdb_password = ""

metrics_report_influxdb_database = ""

metrics_report_statsd_server = ""

metrics_report_statsd_period = "1s"

metrics_report_statsd_prefix = ""

启动:

nohup /data/codis/redis/bin/codis-proxy --ncpu=4 --config=/data/codis/conf/proxy.conf --log=/data/codis/log/proxy.log >/dev/null 2>&1 &

6.5 Codis-1A 上配置Redis Master

配置Redis.conf 每台服务都需配置,更改为本机IP和端口即可

[root@prc-codis-1a redis-16379]# vim redis.conf

基本参数

daemonize yes

pidfile "/data/codis/run/redis-16379.pid"

port 16379

tcp-backlog 65535

bind 192.168.0.234

timeout 0

tcp-keepalive 0

loglevel notice

logfile "/data/codis/log/redis-16379.log"

databases 16

lua-time-limit 5000

maxclients 10000

###慢日志参数###

slowlog-log-slower-than 10000

slowlog-max-len 128

###内存参数###

maxmemory 3000000000

maxmemory-policy noeviction

###RDB持久化参数###

#stop-writes-on-bgsave-error yes

#rdbcompression yes

#rdbchecksum yes

#dbfilename dump.rdb

###AOF持久化参数###

#no-appendfsync-on-rewrite yes

appendonly no

appendfilename "appendonly.aof"

#appendfsync no

#auto-aof-rewrite-min-size 512mb

#auto-aof-rewrite-percentage 100

#aof-load-truncated yes

#aof-rewrite-incremental-fsync yes

###客户端Buffer参数###

client-output-buffer-limit normal 0 0 0

client-output-buffer-limit slave 256mb 64mb 60

client-output-buffer-limit pubsub 32mb 8mb 60

###其他参数###

hash-max-ziplist-entries 512

hash-max-ziplist-value 64

list-max-ziplist-entries 512

list-max-ziplist-value 64

set-max-intset-entries 512

zset-max-ziplist-entries 128

zset-max-ziplist-value 64

hll-sparse-max-bytes 3000

activerehashing yes

latency-monitor-threshold 0

###安全参数###

requirepass "szyq*@root@@@**"

# Generated by CONFIG REWRITE

dir "/data/codis/redis/redis-16379/data"

masterauth "szyq*@root@@@**"

启动:

/data/codis/redis/bin/codis-server /data/codis/redis/redis-16379/redis.conf

7,访问Codis-FE后台

通过网页访问:http://192.168.3.198:8090 可以看到codis的管理页面:

添加Proxy

添加Codis Server 并分组

添加Sentinels

配置Slots

8,启动项开机启动

注释:写入开机文件,示列

# vim /etc/rc.d/rc.local

nohup /data/codis/redis/bin/codis-proxy --ncpu=4 --config=/data/codis/conf/proxy.conf --log=/data/codis/log/proxy.log >/dev/null 2>&1 &

9、测试集群数据同步

链接任何一给proxy服务,写入一行数据

链接任何一台proxy服务,查询数据

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。