codis 3.2集群单机环境安装
codis 3.2集群单机环境安装 一、软件环境 系统:centos 6.5Jdk:jdk-8u111-linux-x64.gzgo : go1.7.3.linux-amd64.tar.gzzookeeper: zookeeper-3.4.6.tar.gz本机IP:172.16.40.131软件下载地址:codis:https://github.com/CodisLabs/codiszookeeper:https://zookeeper.apache.org/go:http://golangtc.com/download 二
codis 3.2集群单机环境安装
一、软件环境
系统:centos 6.5Jdk:jdk-8u111-linux-x64.gzgo : go1.7.3.linux-amd64.tar.gzzookeeper: zookeeper-3.4.6.tar.gz本机IP:172.16.40.131软件下载地址:codis:https://github.com/CodisLabs/codiszookeeper:https://zookeeper.apache.org/go:http://golangtc.com/download
二、部署zookeeper
集群
1.安装相关依赖包yum install -y gcc makegcc-c++ automake lrzsz openssl-devel zlib-* bzip2-* readline* git nmap unzipwget lsof xz net-tools mercurial2.安装javatar zxvfjdk-8u111-linux-x64.gz -C /usr/local/cd /usr/local/ln -sv jdk1.8.0_111 java修改环境变量vi /etc/profileJAVA_HOME=/usr/local/javaPATH=$JAVA_HOME/bin:$PATHCLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jarexport JAVA_HOMEexport PATHexport CLASSPATH让环境变量生效source /etc/profile查看JAVA版本java -versionjava version “1.8.0_111″Java(TM) SE Runtime Environment (build1.8.0_111-b14)Java HotSpot(TM) 64-Bit Server VM (build25.111-b14, mixed mode)3.安装zookeepermkdir /{app,appdata}cd /appmkdir -pv ./{zk1,zk2,zk3}/{data,log}tar zxvf zookeeper-3.4.6.tar.gz -C /app/zk1/tar zxvf zookeeper-3.4.6.tar.gz -C /app/zk2/tar zxvf zookeeper-3.4.6.tar.gz -C /app/zk3/ln -sv /app/zk1/zookeeper-3.4.6 /app/zk1/zookeeperln -sv /app/zk2/zookeeper-3.4.6 /app/zk2/zookeeperln -sv /app/zk3/zookeeper-3.4.6 /app/zk3/zookeepercp /app/zk1/zookeeper/conf/zoo_sample.cfg/app/zk1/zookeeper/conf/zoo.cfg修改zoo.cfg配置文件vi /app/zk1/zookeeper/conf/zoo.cfg# The number of milliseconds of each ticktickTime=2000# The number of ticks that the initial# synchronization phase can takeinitLimit=10# The number of ticks that can pass between# sending a request and getting anacknowledgementsyncLimit=5# the directory where the snapshot isstored.# do not use /tmp for storage, /tmp here isjust# example sakes.dataDir=/app/zk1/data# the port at which the clients willconnectclientPort=2181# the maximum number of client connections.# increase this if you need to handle moreclients#maxClientCnxns=60## Be sure to read the maintenance sectionof the# administrator guide before turning onautopurge.##http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance## The number of snapshots to retain indataDir#autopurge.snapRetainCount=3# Purge task interval in hours# Set to “0” to disable autopurge feature#autopurge.purgeInterval=1server.1=172.16.40.131:2881:3888server.2=172.16.40.131:2882:3888server.3=172.16.40.131:2883:3888生成myidecho “1”>/app/zk1/data/myid配置zk2、zk3:cp /app/zk1/zookeeper/conf/zoo.cfg /app/zk2/zookeeper/conf/cp /app/zk1/zookeeper/conf/zoo.cfg /app/zk3/zookeeper/conf/sed -i ‘s/zk1/zk2/g’ /app/zk2/zookeeper/conf/zoo.cfgsed -i ‘s/zk1/zk3/g’ /app/zk3/zookeeper/conf/zoo.cfgsed -i ‘s/2181/2182/g’ /app/zk2/zookeeper/conf/zoo.cfgsed -i ‘s/2181/2183/g’ /app/zk3/zookeeper/conf/zoo.cfgecho “2”>/app/zk2/data/myidecho “3”>/app/zk3/data/myid启动zookeeper服务/app/zk1/zookeeper/bin/zkServer.sh start/app/zk2/zookeeper/bin/zkServer.sh start/app/zk3/zookeeper/bin/zkServer.sh start查看zookeeper状态/app/zk1/zookeeper/bin/zkServer.sh statusJMX enabled by defaultUsing config:/app/zk1/zookeeper/bin/../conf/zoo.cfgMode: leader/app/zk2/zookeeper/bin/zkServer.sh statusJMX enabled by defaultUsing config:/app/zk2/zookeeper/bin/../conf/zoo.cfg/app/zk3/zookeeper/bin/zkServer.sh statusJMX enabled by defaultUsing config:/app/zk3/zookeeper/bin/../conf/zoo.cfgMode: follower二、部署codis
1.go
环境部署
cd /apptar zxvf go1.7.3.linux-amd64.tar.gz -C /appmkdir gopkg配置GOROOT、GOPATHvi /etc/profileexport GOROOT=/app/goexport GOPATH=/app/gopkgexport PATH=$PATH:$GOROOT/bin生效环境变量source /etc/profile查看go版本go versiongo version go1.7.3 linux/amd64
2.codis
编译
创建codis编译目录mkdir -pv /app/gopkg/src/github.com/CodisLabs/下载codis软件包cd /app/gopkg/src/github.com/CodisLabs/git clone https://github.com/CodisLabs/codis.git -b release3.2编译cd codis/make编译正确如下,没有错误出现说明已编译完成===============================================================================go build -i -o bin/codis-dashboard./cmd/dashboardgo build -i -tags “cgo_jemalloc”-o bin/codis-proxy ./cmd/proxygo build -i -o bin/codis-admin ./cmd/admingo build -i -o bin/codis-fe ./cmd/fe查看bin目录生成文件cd /app/gopkg/src/github.com/CodisLabs/codis/bin/[root@codis-02 bin]# lltotal 84488drwxr-xr-x. 4 root root 4096 Jun 13 18:12 assets-rwxr-xr-x. 1 root root 15465215 Jun 1318:12 codis-admin-rwxr-xr-x. 1 root root 17085915 Jun 1318:12 codis-dashboard-rwxr-xr-x. 1 root root 15358965 Jun 1318:12 codis-fe-rwxr-xr-x. 1 root root 19311099 Jun 1318:12 codis-proxy-rwxr-xr-x. 1 root root 7982986 Jun 13 18:11 codis-server-rwxr-xr-x. 1 root root 5580519 Jun 13 18:11 redis-benchmark-rwxr-xr-x. 1 root root 5712403 Jun 13 18:11 redis-cli-rw-r–r–. 1 root root 168 Jun 13 18:11 version
3.codis
实例
部署redis实例一主两从创建codis实例所需目录,mkdir -pv /app/codis/redis/{7001,7002,7003,7004,7005,7006}cp -r /app/gopkg/src/github.com/CodisLabs/codis/bin/app/codis/redis配置如下vi /app/codis/redis/7001/redis.confbind 0开发云主机域名.0.0.0protected-mode noport 7001tcp-backlog 511timeout 60tcp-keepalive 300daemonize yessupervised nopidfile “/tmp/redis_7001.pid”loglevel noticelogfile “/app/codis/redis/7001/redis_7001.log”databases 16save 900 1save 300 10save 60 10000stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename”dump_7001.rdb”dir “/app/codis/redis/7001”slave-serve-stale-data yesslave-read-only yesrepl-diskless-sync norepl-diskless-sync-delay 5repl-disable-tcp-nodelay noslave-priority 100appendonly yesappendfilename “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 64mb60client-output-buffer-limit pubsub 32mb 8mb60hz 10aof-rewrite-incremental-fsync yes配置7002,7003,7004,7005,7006cp /app/codis/redis/7001/redis.conf /app/codis/redis/7002/cp /app/codis/redis/7001/redis.conf /app/codis/redis/7003/cp /app/codis/redis/7001/redis.conf /app/codis/redis/7004/cp /app/codis/redis/7001/redis.conf /app/codis/redis/7005/cp /app/codis/redis/7001/redis.conf /app/codis/redis/7006/sed -i ‘s/7001/7002/g’ /app/codis/redis/7002/redis.confsed -i ‘s/7001/7003/g’ /app/codis/redis/7003/redis.confsed -i ‘s/7001/7004/g’ /app/codis/redis/7004/redis.confsed -i ‘s/7001/7005/g’ /app/codis/redis/7005/redis.confsed -i ‘s/7001/7006/g’ /app/codis/redis/7006/redis.conf启动codis-server服务/app/codis/bin/codis-server /app/codis/redis/7001/redis.conf/app/codis/bin/codis-server /app/codis/redis/7002/redis.conf/app/codis/bin/codis-server /app/codis/redis/7003/redis.conf/app/codis/bin/codis-server /app/codis/redis/7004/redis.conf/app/codis/bin/codis-server /app/codis/redis/7005/redis.conf/app/codis/bin/codis-server /app/codis/redis/7006/redis.conf
三、部署codis-proxy
1.
生成codis-proxy
配置文件
cd /app/codis/bin//app/codis/bin/codis-proxy –default-config|tee proxy.toml >> proxy.tomlvi proxy.tom##################################################### Codis-Proxy ###################################################### Set Codis Product Name/Auth.product_name =”codis-demo”product_auth =””# Set auth for client session#1. product_auth is used for auth validation among codis-dashboard,#codis-proxy and codis-server.#2. session_auth is different from product_auth, it requires clients#to issue AUTH
before processing any other commands.
session_auth = “”# Set bind address for admin(rpc), tcponly.admin_addr =”0.0.0.0:11080″# Set bind address for proxy, proto_typecan be “tcp”, “tcp4”, “tcp6”, “unix” or”unixpacket”.proto_type = “tcp4”proxy_addr =”0.0.0.0:19000″# Set jodis address & session timeout#1. jodis_name is short for jodis_coordinator_name, only accept”zookeeper” & “etcd”.#2. jodis_addr is short for jodis_coordinator_addr#3. proxy will be registered as node:#if jodis_compatible = true (not suggested):# /zk/codis/db_{PRODUCT_NAME}/proxy-{HASHID}(compatible with Codis2.0)#or else#/jodis/{PRODUCT_NAME}/proxy-{HASHID}jodis_name =”zookeeper”jodis_addr =”172.16.40.131:2881,172.16.40.131:2882,172.16.40.131:2883″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 todisable)proxy_max_offheap_size = “1024mb”# Set heap placeholder to reduce GCfrequency.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 = 20480# Set backend never read replica groups,default is falsebackend_primary_only = false# Set backend parallel connections perserverbackend_primary_parallel = 1backend_replica_parallel = 1# Set backend tcp keepalive period. (0 todisable)backend_keepalive_period = “75s”# Set number of databases of backend.backend_number_databases = 16# If there is no request from client for along 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 maxnumber of requests for each pipeline request, or your client may be blocked.# Set session pipeline buffer size.session_max_pipeline = 10000# Set session tcp keepalive period. (0 todisable)session_keepalive_period = “75s”# Set session to be sensitive to failures.Default is false, instead of closing socket, proxy will send an error responseto client.session_break_on_failure = false# Set metrics server (such ashttp://localhost:28000), proxy will report json formatted metrics to specifiedserver in a predefined period.metrics_report_server = “”metrics_report_period = “1s”# Set influxdb server (such ashttp://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 =””# Set statsd server (such aslocalhost:8125), proxy will report metrics to statsd.metrics_report_statsd_server = “”metrics_report_statsd_period =”1s”metrics_report_statsd_prefix = “”参数说明:product_name 集群名称,参考 dashboard 参数说明product_auth 集群密码,默认为空admin_addr RESTfulAPI 端口proto_type Redis 端口类型,接受 tcp/tcp4/tcp6/unix/unixpacketproxy_addr Redis 端口地址或者路径jodis_addr Jodis 注册 zookeeper 地址jodis_timeout Jodis 注册ses开发云主机域名siontimeout 时间,单位 secondjodis_compatible Jodis 注册 zookeeper 的路径backend_ping_period 与codis-server 探活周期,单位 second,0 表示禁止session_max_timeout 与 client 连接最大读超时,单位 second,0 表示禁止session_max_bufsize 与 client 连接读写缓冲区大小,单位bytesession_max_pipeline 与 client 连接最大的 pipeline大小session_keepalive_period 与 client 的 tcpkeepalive 周期,仅 tcp 有效,0 表示禁止
2.
启开发云主机域名动codis-proxy
nohup /app/codis/bin/codis-proxy –ncpu=4–config=/app/codis/bin/proxy.toml –log=proxy.log –log-level=WARN &
四、部署codis-dashboard
1.
生成codis-proxy
配置文件
/app/codis/bin/codis-dashboard–default-config |tee dashboard.toml >>dashboard.toml修改codis-proxy配置vidashboard.toml##################################################### Codis-Dashboard ## #################################################### SetCoordinator, only accept “zookeeper” & “etcd” &”filesystem”.# QuickStart#coordinator_name= “filesystem”#coordinator_addr= “/tmp/codis”coordinator_name = “zookeeper”coordinator_addr =”172.16.40.131:2181,172.16.40.131:2182,172.16.40.131:2183″# SetCodis Product Name/Auth.product_name = “codis-demo”product_auth = “”# Setbind address for admin(rpc), tcp only.admin_addr = “0.0.0.0:18080”# Setarguments for data migration (only accept ‘sync’ & ‘semi-async’).migration_method= “semi-async”migration_parallel_slots= 100migration_async_maxbulks= 200migration_async_maxbytes= “32mb”migration_async_numkeys= 500migration_timeout= “30s”# Setconfigs for redis sentinel.sentinel_quorum= 2sentinel_parallel_syncs= 1sentinel_down_after= “30s”sentinel_failover_timeout= “5m”sentinel_notification_script= “”sentinel_client_reconfig_script= “”参数说明:coordinator_name外部存储类型,接受 zookeeper/etcdcoordinator_addr外部存储地址product_name集群名称,满足正则 w[w.-]*product_auth集群密码,默认为空admin_addrRESTful API 端口
启动codis-dashboard
nohup/app/codis/bin/codis-dashboard –ncpu=4 –config=/app/codis/bin/dashboard.toml –log=dashboard.log –log-level=WARN &五、部署codis-fe5.1生成codis-fe配置文件/app/codis/bin/codis-admin –dashboard-list –zookeeper=172.16.40.131:2182 |tee ./codis.json>>codis.json[root@codis-02bin]# cat codis.json[ { “name”:”codis-demo”, “dashboard”:”172.16.40.131:18080″ }]启动codis-fe服务nohup/app/codis/bin/codis-fe –ncpu=4 –log=fe.log –log-level=WARN –dashboard-list=/app/codis/bin/codis.json –listen=0.0.0.0:18090 &查看相关服务端口[root@codis-02bin]# ss -tunlp | grep codistcp LISTEN0 128 *:19000 *:* users:((“codis-proxy”,10106,7))tcp LISTEN0 128 *:7001 *:* users:((“codis-server”,10063,4))tcp LISTEN0 128 *:7002 *:*users:((“codis-server”,10068,4))tcp LISTEN0 128 *:7003 *:*users:((“codis-server”,10073,4))tcp LISTEN0 128 *:7004 *:*users:((“codis-server”,10078,4))tcp LISTEN0 128 *:7005 *:*users:((“codis-server”,10083,4))tcp LISTEN0 128 *:7006 *:*users:((“codis-server”,10088,4))tcp LISTEN0 128 :::18080 :::*users:((“codis-dashboard”,10150,5))tcp LISTEN0 128 :::11080 :::*users:((“codis-proxy”,10106,8))tcp LISTEN0 128 :::18090 :::* users:((“codis-fe”,10221,5))六、redis sentinel部署创建redis-sentinel目录mkdir -pv /app/codis/sentinel/{27001,27002}配置sentinel文件vi /app/codis/sentinel/27001/sentinel-27001.confbind 0.0.0.0protected-mode noport 27001dir /app/codis/sentinel/27001/vi /app/codis/sentinel/27002/sentinel-27002.confbind 0.0.0.0protected-mode noport 27002dir /app/codis/sentinel/27002/启动sentinel服务cp/app/gopkg/src/github.com/CodisLabs/codis/extern/redis-3.2.8/src/redis-sentinel/app/codis/bin//app/codis/bin/redis-sentinel /app/codis/sentinel/27001/sentinel-27001.conf &/app/codis/bin/redis-sentinel /app/codis/sentinel/27002/sentinel-27002.conf &七、使用codis-fe管理codis集群环境1.codis-fe管理界面http://172.16.40.131:18090
添加codis-proxy
:
采用命令增加[root@codis-02 bin]# ./codis-admin –dashboard=127.0.0.1:18080 –create-proxy -x 127.0.0.1:11080也可以采用界面增加
添加codis-server
先NEW GROUP
增加一主两从
增加两组
以上也可以用命令增加
添加
redis-sentinel
命令增加
[root@codis-02bin]# ./codis-admin –dashboard=172.16.40.131:18080 –sentinel-add –addr=172.16.40.131:27002
分配
slot
slot:数据槽,在 codis-server 间数据分片的单元;建议将数据槽均分于多个 group;在 codis-fe 管理界面添加 redis-sentinel,并同步,同步后 redis-sentinel 配置文件会更新root@codis-02bin]# cat /app/codis/sentinel/27001/sentinel-27001.confbind 0.0.0.0protected-mode noport 27001dir “/app/codis/sentinel/27001″#Generated by CONFIG REWRITEsentinelmyid b445aae57d1283b4d89d9ed23fd96982dbc344c3sentinelmonitor codis-demo-2 172.16.40.131 7004 2sentinelfailover-timeout codis-demo-2 300000sentinelconfig-epoch codis-demo-2 0sentinelleader-epoch codis-demo-2 0sentinelknown-slave codis-demo-2 172.16.40.131 7005sentinelknown-slave codis-demo-2 172.16.40.131 7006sentinelknown-sentinel codis-demo-2 172.16.40.131 27002b236624dce5df7317e5c3e5f30401899c4961094sentinelmonitor codis-demo-1 172.16.40.131 7001 2sentinelfailover-timeout codis-demo-1 300000sentinelconfig-epoch codis-demo-1 0sentinelleader-epoch codis-demo-1 0sentinelknown-slave codis-demo-1 172.16.40.131 7002sentinelknown-slave codis-demo-1 172.16.40.131 7003sentinelknown-sentinel codis-demo-1 172.16.40.131 27002 b236624dce5df7317e5c3e5f30401899c4961094sentinelcurrent-epoch 0
本文从转载,原作者保留一切权利,若侵权请联系删除。
《codis 3.2集群单机环境安装》来自互联网同行内容,若有侵权,请联系我们删除!