溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

codis 3.2集群單機(jī)環(huán)境安裝

發(fā)布時(shí)間:2020-09-25 09:27:07 來源:網(wǎng)絡(luò) 閱讀:3997 作者:jxzhfei 欄目:建站服務(wù)器

codis 3.2集群單機(jī)環(huán)境安裝

一、軟件環(huán)境

系統(tǒng):centos 6.5

Jdkjdk-8u111-linux-x64.gz

go : go1.7.3.linux-amd64.tar.gz

zookeeper: zookeeper-3.4.6.tar.gz

本機(jī)IP172.16.40.131

 

軟件下載地址:

codishttps://github.com/CodisLabs/codis

zookeeperhttps://zookeeper.apache.org/

gohttp://golangtc.com/download

 

二、部署zookeeper集群

1.安裝相關(guān)依賴包

yum install -y gcc makegcc-c++ automake lrzsz openssl-devel zlib-* bzip2-* readline* git nmap unzipwget lsof xz net-tools mercurial

2.安裝java

tar zxvfjdk-8u111-linux-x64.gz -C  /usr/local/

cd  /usr/local/

 

ln -sv jdk1.8.0_111  java

 

修改環(huán)境變量

vi /etc/profile

 

JAVA_HOME=/usr/local/java

PATH=$JAVA_HOME/bin:$PATH

CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

export JAVA_HOME

export PATH

export CLASSPATH

 

讓環(huán)境變量生效

source /etc/profile

查看JAVA版本

java -version

 

java 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.安裝zookeeper

mkdir  /{app,appdata}

cd /app

mkdir -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/zookeeper

ln -sv /app/zk2/zookeeper-3.4.6 /app/zk2/zookeeper

ln -sv /app/zk3/zookeeper-3.4.6 /app/zk3/zookeeper

 

cp /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 tick

tickTime=2000

# The number of ticks that the initial

# synchronization phase can take

initLimit=10

# The number of ticks that can pass between

# sending a request and getting anacknowledgement

syncLimit=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 willconnect

clientPort=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=1

server.1=172.16.40.131:2881:3888

server.2=172.16.40.131:2882:3888

server.3=172.16.40.131:2883:3888

 

生成myid

echo "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.cfg

sed -i 's/zk1/zk3/g'  /app/zk3/zookeeper/conf/zoo.cfg

 

sed -i 's/2181/2182/g'  /app/zk2/zookeeper/conf/zoo.cfg

sed -i 's/2181/2183/g'  /app/zk3/zookeeper/conf/zoo.cfg

 

echo "2">/app/zk2/data/myid

echo "3">/app/zk3/data/myid

 

啟動(dòng)zookeeper服務(wù)

/app/zk1/zookeeper/bin/zkServer.sh  start

/app/zk2/zookeeper/bin/zkServer.sh  start

/app/zk3/zookeeper/bin/zkServer.sh  start

 

 

查看zookeeper狀態(tài)

/app/zk1/zookeeper/bin/zkServer.sh  status

JMX enabled by default

Using config:/app/zk1/zookeeper/bin/../conf/zoo.cfg

Mode: leader

 

/app/zk2/zookeeper/bin/zkServer.sh  status

JMX enabled by default

Using config:/app/zk2/zookeeper/bin/../conf/zoo.cfg

 

/app/zk3/zookeeper/bin/zkServer.sh  status

JMX enabled by default

Using config:/app/zk3/zookeeper/bin/../conf/zoo.cfg

Mode: follower

 

二、部署codis

1.go環(huán)境部署

cd /app

tar zxvf  go1.7.3.linux-amd64.tar.gz -C /app

mkdir  gopkg

 

配置GOROOT、GOPATH

vi /etc/profile

export  GOROOT=/app/go

export  GOPATH=/app/gopkg

export  PATH=$PATH:$GOROOT/bin

 

生效環(huán)境變量

source /etc/profile

查看go版本

go version

go version go1.7.3 linux/amd64

 

2.codis編譯

 

創(chuàng)建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

編譯正確如下,沒有錯(cuò)誤出現(xiàn)說明已編譯完成

===============================================================================

go build -i -o bin/codis-dashboard./cmd/dashboard

go build -i -tags "cgo_jemalloc"-o bin/codis-proxy ./cmd/proxy

go build -i -o bin/codis-admin  ./cmd/admin

go build -i -o bin/codis-fe ./cmd/fe

 

查看bin目錄生成文件

cd   /app/gopkg/src/github.com/CodisLabs/codis/bin/

 

[root@codis-02 bin]# ll

total 84488

drwxr-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實(shí)例

部署redis實(shí)例一主兩從

創(chuàng)建codis實(shí)例所需目錄,

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.conf

bind 0.0.0.0

protected-mode no

port 7001

tcp-backlog 511

timeout 60

tcp-keepalive 300

daemonize yes

supervised no

pidfile "/tmp/redis_7001.pid"

loglevel notice

logfile "/app/codis/redis/7001/redis_7001.log"

databases 16

save 900 1

save 300 10

save 60 10000

stop-writes-on-bgsave-error yes

rdbcompression yes

rdbchecksum yes

dbfilename"dump_7001.rdb"

dir "/app/codis/redis/7001"

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 yes

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 64mb60

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

hz 10

aof-rewrite-incremental-fsync yes

 

配置7002,7003,7004,7005,7006

cp /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.conf

sed -i 's/7001/7003/g'  /app/codis/redis/7003/redis.conf

sed -i 's/7001/7004/g'  /app/codis/redis/7004/redis.conf

sed -i 's/7001/7005/g'  /app/codis/redis/7005/redis.conf

sed -i 's/7001/7006/g'  /app/codis/redis/7006/redis.conf

 

啟動(dòng)codis-server服務(wù)

/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.toml

 

vi 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 <PASSWORD> 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 false

backend_primary_only = false

 

# Set backend parallel connections perserver

backend_primary_parallel = 1

backend_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 = ""

 

 

參數(shù)說明:

product_name 集群名稱,參考 dashboard 參數(shù)說明

product_auth 集群密碼,默認(rèn)為空

admin_addr RESTfulAPI

proto_type Redis 口類型,接受 tcp/tcp4/tcp6/unix/unixpacket

proxy_addr Redis 口地址或者路

jodis_addr Jodis 注冊(cè) zookeeper 地址

jodis_timeout Jodis 注冊(cè)sessiontimeout 時(shí)間,單位 second

jodis_compatible Jodis 注冊(cè) zookeeper 的路

backend_ping_period codis-server 探活周期,單位 second,0 表示禁

session_max_timeout client 連接最大讀超時(shí),單位 second,0 表示禁

session_max_bufsize client 連接讀寫緩沖區(qū)小,單位byte

session_max_pipeline client 連接最大的 pipeline

session_keepalive_period client tcpkeepalive 周期,僅 tcp 有效,0 表示禁

 

 

2.啟動(dòng)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= 100

migration_async_maxbulks= 200

migration_async_maxbytes= "32mb"

migration_async_numkeys= 500

migration_timeout= "30s"

 

# Setconfigs for redis sentinel.

sentinel_quorum= 2

sentinel_parallel_syncs= 1

sentinel_down_after= "30s"

sentinel_failover_timeout= "5m"

sentinel_notification_script= ""

sentinel_client_reconfig_script= ""

 

參數(shù)說明:

coordinator_name外部存儲(chǔ)類型,接受 zookeeper/etcd

coordinator_addr外部存儲(chǔ)地址

product_name集群名稱,滿足正則 \w[\w\.\-]*

product_auth集群密碼,默認(rèn)為空

admin_addrRESTful API

啟動(dòng)codis-dashboard

nohup/app/codis/bin/codis-dashboard  --ncpu=4  --config=/app/codis/bin/dashboard.toml  --log=dashboard.log --log-level=WARN &

 

五、部署codis-fe

5.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"

    }

]

 

啟動(dòng)codis-fe服務(wù)

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 &

 

查看相關(guān)服務(wù)端口

[root@codis-02bin]# ss -tunlp | grep codis

tcp    LISTEN    0      128                    *:19000                 *:*      users:(("codis-proxy",10106,7))

tcp    LISTEN    0      128                    *:7001                  *:*      users:(("codis-server",10063,4))

tcp    LISTEN    0      128                    *:7002                  *:*     users:(("codis-server",10068,4))

tcp    LISTEN    0      128                    *:7003                  *:*     users:(("codis-server",10073,4))

tcp    LISTEN    0      128                    *:7004                  *:*     users:(("codis-server",10078,4))

tcp    LISTEN    0      128                    *:7005                  *:*     users:(("codis-server",10083,4))

tcp    LISTEN    0      128                    *:7006                  *:*     users:(("codis-server",10088,4))

tcp    LISTEN    0      128                   :::18080                :::*     users:(("codis-dashboard",10150,5))

tcp    LISTEN    0      128                   :::11080                :::*     users:(("codis-proxy",10106,8))

tcp    LISTEN    0      128                   :::18090                :::*      users:(("codis-fe",10221,5))

 

六、redis sentinel部署

創(chuàng)建redis-sentinel目錄

mkdir  -pv  /app/codis/sentinel/{27001,27002}

 

配置sentinel文件

vi  /app/codis/sentinel/27001/sentinel-27001.conf

 

bind 0.0.0.0

protected-mode no

port 27001

dir /app/codis/sentinel/27001/

 

 

vi /app/codis/sentinel/27002/sentinel-27002.conf

 

bind 0.0.0.0

protected-mode no

port 27002

dir /app/codis/sentinel/27002/

 

 

啟動(dòng)sentinel服務(wù)

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集群環(huán)境

1.codis-fe管理界面

http://172.16.40.131:18090

codis 3.2集群單機(jī)環(huán)境安裝

 

 

添加codis-proxy

采用命令增加

[root@codis-02 bin]# ./codis-admin --dashboard=127.0.0.1:18080  --create-proxy -x 127.0.0.1:11080

 

也可以采用界面增加

 

codis 3.2集群單機(jī)環(huán)境安裝

添加codis-server

NEW GROUP

codis 3.2集群單機(jī)環(huán)境安裝

 

 

增加一主兩從

codis 3.2集群單機(jī)環(huán)境安裝

 

增加兩組

codis 3.2集群單機(jī)環(huán)境安裝

 

以上也可以用命令增加

 

 

添加redis-sentinel

codis 3.2集群單機(jī)環(huán)境安裝

 

命令增加

[root@codis-02bin]# ./codis-admin --dashboard=172.16.40.131:18080  --sentinel-add   --addr=172.16.40.131:27002

 

codis 3.2集群單機(jī)環(huán)境安裝

 

codis 3.2集群單機(jī)環(huán)境安裝


分配 slot

slot:數(shù)據(jù)槽,在 codis-server 間數(shù)據(jù)分片的單元;建議將數(shù)據(jù)槽均分于多個(gè) group

codis 3.2集群單機(jī)環(huán)境安裝

codis-fe 管理界面添加 redis-sentinel,并同步,同步后 redis-sentinel 配置文件會(huì)更新

root@codis-02bin]# cat /app/codis/sentinel/27001/sentinel-27001.conf

bind 0.0.0.0

protected-mode no

port 27001

dir "/app/codis/sentinel/27001"

 

#Generated by CONFIG REWRITE

sentinelmyid b445aae57d1283b4d89d9ed23fd96982dbc344c3

sentinelmonitor codis-demo-2 172.16.40.131 7004 2

 

sentinelfailover-timeout codis-demo-2 300000

sentinelconfig-epoch codis-demo-2 0

sentinelleader-epoch codis-demo-2 0

sentinelknown-slave codis-demo-2 172.16.40.131 7005

sentinelknown-slave codis-demo-2 172.16.40.131 7006

sentinelknown-sentinel codis-demo-2 172.16.40.131 27002b236624dce5df7317e5c3e5f30401899c4961094

sentinelmonitor codis-demo-1 172.16.40.131 7001 2

sentinelfailover-timeout codis-demo-1 300000

sentinelconfig-epoch codis-demo-1 0

sentinelleader-epoch codis-demo-1 0

sentinelknown-slave codis-demo-1 172.16.40.131 7002

sentinelknown-slave codis-demo-1 172.16.40.131 7003

sentinelknown-sentinel codis-demo-1 172.16.40.131 27002 b236624dce5df7317e5c3e5f30401899c4961094

sentinelcurrent-epoch 0


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI