本文共 9161 字,大约阅读时间需要 30 分钟。
redis集群安装用的是codis ,由豌豆荚开源,相比较twemproxy的好处有很多,参考http://blog.csdn.net/hunci/article/details/51799468
不废话,搞起
下面的安装文档抄袭了小炒肉的,连接如下
官网的搭建文档看 readme
但是部署中也遇到了一些问题
1,在codis make 的时候出现错误
go build -i -o bin/codis-dashboard ./cmd/dashboard
go build github.com/CodisLabs/codis/vendor/github.com/ugorji/go/codec: /opt/local/go/pkg/tool/linux_amd64/compile: signal: killed
make: *** [codis-dashboard] 错误 1
原因:我用的vps,内存本来就很小只有500M,查看日志 /var/log/message
May 16 09:30:06 vultr kernel: Out of memory: Kill process 10020 (compile) score 460 or sacrifice child
May 16 09:30:06 vultr kernel: Killed process 10020, UID 0, (compile) total-vm:383560kB, anon-rss:371776kB, file-rss:120kB
是因为 应用服务在启动的时候,触发的linux系统内存的调用机制,为了保证系统正常运行oom 杀掉了编译进程
解决:两个方法,调节内核,不推荐,会玩挂的(大神请无视)
第二个方法,增加内存就好了
2,编译过程中报错
zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory
zmalloc.h:55:2: error: #error "Newer version of jemalloc required"
make[1]: *** [adlist.o] Error 1
undefined reference to `dladdr'
两个错误
解决:
其实两个错误都是没有制定正确的连接库的位置
编译的时候 加上两个参数就好了
make MALLOC=libc LDFLAGS+=-ldl
3,在dashboard面板上添加codis-proxy时候,dashboard的server配置文件,codis-proxy中的配置文件
product_name = "codis-demo"product_auth = ""
这个认证,一定要一直,因为两者都是去zookeeper里去值,或者说dashboard是通过zk来给codis-proxy
传达消息的
架构图
yum install -y git autoconf
wget https://storage.googleapis.com/golang/go1.5.4.linux-amd64.tar.gztar zxvf go1.5.4.linux-amd64.tar.gzmkdir /opt/localmv go /opt/local/
vi /etc/profile# 添加如下:# golang ENVexport GOROOT=/opt/local/goexport PATH=$PATH:$GOROOT/binexport GOPATH=/opt/local/codis# 立即生效source /etc/profile# 检查版本go versiongo version go1.5.4 linux/amd64echo $GOPATH/opt/local/codis
mkdir -p $GOPATH/src/github.com/CodisLabscd $GOPATH/src/github.com/CodisLabsgit clone https://github.com/CodisLabs/codis.git -b release3.1
cd $GOPATH/src/github.com/CodisLabs/codismakemake -j -C extern/redis-3.2.4/# 输入如下信息:go build -i -o bin/codis-dashboard ./cmd/dashboardgo build -i -o bin/codis-proxy ./cmd/proxygo build -i -o bin/codis-admin ./cmd/admingo build -i -o bin/codis-ha ./cmd/hago build -i -o bin/codis-fe ./cmd/fe# 查看 安装以后的版本cat bin/versionversion = 2017-03-08 14:07:13 +0800 @b1919d11593dfd1f47a2461837233dfc8fc78002 @3.1.5-26-gb1919d1compile = 2017-04-05 18:13:46 +0800 by go version go1.5.4 linux/amd64# 复制文件,方便管理mkdir -p /opt/local/codis/{bin,logs,data}/cp -rf $GOPATH/src/github.com/CodisLabs/codis/bin/* /opt/local/codis/bincp -rf $GOPATH/src/github.com/CodisLabs/codis/config /opt/local/codis/
是后台服务,展示页面是由fe来展示的,
集群管理工具,支持 codis-proxy、codis-server 的添加、删除,以及据迁移等操作。在集群状态发生改变时,codis-dashboard 维护集群下所有 codis-proxy 的状态的一致性。
对于同一个业务集群而言,同一个时刻 codis-dashboard 只能有 0个或者1个;
所有对集群的修改都必须通过 codis-dashboard 完成。
cd /opt/local/codis/config/vim dashboard.toml
# 修改配置文件################################################### ## Codis-Dashboard ## #################################################### Set Coordinator, only accept "zookeeper" & "etcd" & "filesystem".coordinator_name = "zookeeper"coordinator_addr = "127.0.0.1:2181"# Set Codis Product Name/Auth.product_name = "codis-demo"product_auth = ""# Set bind address for admin(rpc), tcp only.admin_addr = "0.0.0.0:18080"# Set configs for redis sentinel.sentinel_quorum = 2sentinel_parallel_syncs = 1sentinel_down_after = "30s"sentinel_failover_timeout = "5m"sentinel_notification_script = ""sentinel_client_reconfig_script = ""
# 启动 Dashboardnohup /opt/local/codis/bin/codis-dashboard --ncpu=4 --config=/opt/local/codis/config/dashboard.toml \ --log=/opt/local/codis/logs/dashboard.log --log-level=WARN &
cd /opt/local/codis/config/vim proxy.toml
# 修改配置文件################################################### ## Codis-Proxy ## #################################################### Set Codis Product Name/Auth.product_name = "codis-demo"product_auth = ""# Set bind address for admin(rpc), tcp only.admin_addr = "0.0.0.0:11080" ###注释说的很明显了,这个是在dashboard上添加proxy的地址,是admin命令控制台,控制proxy的地址# Set bind address for proxy, proto_type can be "tcp", "tcp4", "tcp6", "unix" or "unixpacket".proto_type = "tcp4"proxy_addr = "0.0.0.0:19000"# Set jodis address & session timeout, only accept "zookeeper" & "etcd".jodis_name = "zookeeper"jodis_addr = "127.0.0.1:2181"jodis_timeout = "20s"jodis_compatible = false# Set datacenter of proxy.proxy_datacenter = ""# Set max number of alive sessions.proxy_max_clients = 1000# Set max offheap memory size. (0 to disable)proxy_max_offheap_size = "1024mb"# Set heap placeholder to reduce GC frequency.proxy_heap_placeholder = "256mb"# Proxy will ping backend redis (and clear 'MASTERDOWN' state) in a predefined interval. (0 to disable)backend_ping_period = "5s"# Set backend recv buffer size & timeout.backend_recv_bufsize = "128kb"backend_recv_timeout = "30s"# Set backend send buffer & timeout.backend_send_bufsize = "128kb"backend_send_timeout = "30s"# Set backend pipeline buffer size.backend_max_pipeline = 1024# Set backend never read replica groups, default is falsebackend_primary_only = false# Set backend parallel connections per serverbackend_primary_parallel = 1backend_replica_parallel = 1# Set backend tcp keepalive period. (0 to disable)backend_keepalive_period = "75s"# If there is no request from client for a long time, the connection will be closed. (0 to disable)# Set session recv buffer size & timeout.session_recv_bufsize = "128kb"session_recv_timeout = "30m"# Set session send buffer size & timeout.session_send_bufsize = "64kb"session_send_timeout = "30s"# Make sure this is higher than the max number of requests for each pipeline request, or your client may be blocked.# Set session pipeline buffer size.session_max_pipeline = 1024# Set session tcp keepalive period. (0 to disable)session_keepalive_period = "75s"# Set session to be sensitive to failures. Default is false, instead of closing socket, proxy will send an error response to client.session_break_on_failure = false# Set metrics server (such as http://localhost:28000), proxy will report json formatted metrics to specified server in a predefined period.metrics_report_server = ""metrics_report_period = "1s"# Set influxdb server (such as http://localhost:8086), proxy will report metrics to influxdb.metrics_report_influxdb_server = ""metrics_report_influxdb_period = "1s"metrics_report_influxdb_username = ""metrics_report_influxdb_password = ""metrics_report_influxdb_database = ""
# 启动 codis-proxynohup /opt/local/codis/bin/codis-proxy --ncpu=4 --config=/opt/local/codis/config/proxy.toml \ --log=/opt/local/codis/logs/proxy.log --log-level=WARN &# 日志输出如下:proxy waiting online ...# 必须添加到集群中,才正常。# 可使用 Codis-fe 界面添加 或者使用 Codis-admin 添加
# 启动 server 与 启动 redis 方法相同nohup /opt/local/codis/bin/codis-server /opt/local/codis/config/redis.conf &# 启动 Codis-Server 以后需要使用 Codis-fe 或者 Codis-admin 添加到集群
# 配置文件bind 127.0.0.1protected-mode yesport 6379tcp-backlog 2048timeout 0tcp-keepalive 300daemonize nosupervised nopidfile /var/run/redis_6379.pidloglevel noticelogfile "/opt/local/codis/logs/redis.log"maxmemory 10gbdatabases 16save 900 1save 300 10save 60 10000stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename redis_dump.rdbdir /opt/local/codis/dataslave-serve-stale-data yesslave-read-only yesrepl-diskless-sync norepl-diskless-sync-delay 5repl-disable-tcp-nodelay noslave-priority 100appendonly noappendfilename "appendonly.aof"appendfsync everysecno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbaof-load-truncated yeslua-time-limit 5000slowlog-log-slower-than 10000slowlog-max-len 128latency-monitor-threshold 0notify-keyspace-events ""hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-size -2list-compress-depth 0set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64hll-sparse-max-bytes 3000activerehashing yesclient-output-buffer-limit normal 0 0 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60hz 10aof-rewrite-incremental-fsync yes
这里要注意下,FE才是真正的展示页面,所以监听的地址要写本机的地址,这样才可以在浏览器中访问集群的控制面板,而codis-dashboard是算是后台的服务,一开始没弄明白(搞死了,弄了一上午)
# 启动 codis-fenohup /opt/local/codis/bin/codis-fe --ncpu=4 --log=/opt/local/codis/logs/fe.log --log-level=WARN --zookeeper=127.0.0.1:2181 --listen=127.0.0.1:8080 &
其实是集群的命令管理工具
# 添加 codis-proxy/opt/local/codis/bin/codis-admin --dashboard=127.0.0.1:18080 --create-proxy -x 127.0.0.1:11080# 日志输入如下:jodis create node /jodis/codis-demo/proxy-15fba3007f3c6ee0887749681cb82307proxy is working ...
# 修复异常退出的 Codis-dashboard # dashboard 非正常退出,或者 kill -9 时使用/opt/local/codis/bin/codis-admin --remove-lock --product=codis-demo --zookeeper=127.0.0.1:2181
# 修复异常退出的 Codis-proxy# proxy 非正常退出,或者 kill -9 时使用/opt/local/bin/codis-admin --dashboard=127.0.0.1:18080 --remove-proxy --addr=127.0.0.1:11080 --force