redis集群安裝用的是codis ,由豌豆莢開源,相比較twemproxy的好處有很多,參考http://blog.csdn.net/hunci/article/details/51799468
雁江網(wǎng)站制作公司哪家好,找
成都創(chuàng)新互聯(lián)!從網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、
成都響應(yīng)式網(wǎng)站建設(shè)公司等網(wǎng)站項(xiàng)目制作,到程序開發(fā),運(yùn)營維護(hù)。
成都創(chuàng)新互聯(lián)從2013年成立到現(xiàn)在10年的時間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來保證我們的工作的順利進(jìn)行。專注于網(wǎng)站建設(shè)就選
成都創(chuàng)新互聯(lián)。
不廢話,搞起
下面的安裝文檔抄襲了小炒肉的,連接如下
https://www.kissni.com/2017/04/06/codis-redis/
官網(wǎng)的搭建文檔看https://github.com/CodisLabs/codis/blob/release3.2/doc/tutorial_zh.md readme
但是部署中也遇到了一些問題
1,在codis make 的時候出現(xiàn)錯誤
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,內(nèi)存本來就很小只有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
是因?yàn)?應(yīng)用服務(wù)在啟動的時候,觸發(fā)的linux系統(tǒng)內(nèi)存的調(diào)用機(jī)制,為了保證系統(tǒng)正常運(yùn)行oom 殺掉了編譯進(jìn)程
解決:兩個方法,調(diào)節(jié)內(nèi)核,不推薦,會玩掛的(大神請無視)
第二個方法,增加內(nèi)存就好了
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'
兩個錯誤
解決:
其實(shí)兩個錯誤都是沒有制定正確的連接庫的位置
編譯的時候 加上兩個參數(shù)就好了
make MALLOC=libc LDFLAGS+=-ldl
3,在dashboard面板上添加codis-proxy時候,dashboard的server配置文件,codis-proxy中的配置文件
product_name = "codis-demo"
product_auth = ""
這個認(rèn)證,一定要一直,因?yàn)閮烧叨际侨ookeeper里去值,或者說dashboard是通過zk來給codis-proxy
傳達(dá)消息的
架構(gòu)圖
環(huán)境配置
安裝 git
yum install -y git autoconf
安裝 golang,(使用 1.5.x 版本)
wget https://storage.googleapis.com/golang/go1.5.4.linux-amd64.tar.gz
tar zxvf go1.5.4.linux-amd64.tar.gz
mkdir /opt/local
mv go /opt/local/
配置環(huán)境變量
vi /etc/profile
# 添加如下:
# golang ENV
export GOROOT=/opt/local/go
export PATH=$PATH:$GOROOT/bin
export GOPATH=/opt/local/codis# 立即生效
source /etc/profile
# 檢查版本
go version
go version go1.5.4 linux/amd64
echo $GOPATH
/opt/local/codis
安裝 Codis
下載 Codis 源碼
mkdir -p $GOPATH/src/github.com/CodisLabs
cd $GOPATH/src/github.com/CodisLabs
git clone https://github.com/CodisLabs/codis.git -b release3.1
編譯 Codis 源碼
cd $GOPATH/src/github.com/CodisLabs/codismake
make -j -C extern/redis-3.2.4/
# 輸入如下信息:
go build -i -o bin/codis-dashboard ./cmd/dashboard
go build -i -o bin/codis-proxy ./cmd/proxy
go build -i -o bin/codis-admin ./cmd/admin
go build -i -o bin/codis-ha ./cmd/ha
go build -i -o bin/codis-fe ./cmd/fe
# 查看 安裝以后的版本
cat bin/version
version = 2017-03-08 14:07:13 +0800 @b1919d11593dfd1f47a2461837233dfc8fc78002 @3.1.5-26-gb1919d1
compile = 2017-04-05 18:13:46 +0800 by go version go1.5.4 linux/amd64
# 復(fù)制文件,方便管理
mkdir -p /opt/local/codis/{bin,logs,data}/
cp -rf $GOPATH/src/github.com/CodisLabs/codis/bin/* /opt/local/codis/bin
cp -rf $GOPATH/src/github.com/CodisLabs/codis/config /opt/local/codis/
配置 Codis
Codis Dashboard
是后臺服務(wù),展示頁面是由fe來展示的,
集群管理工具,支持 codis-proxy、codis-server 的添加、刪除,以及據(jù)遷移等操作。在集群狀態(tài)發(fā)生改變時,codis-dashboard 維護(hù)集群下所有 codis-proxy 的狀態(tài)的一致性。
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 = 2
sentinel_parallel_syncs = 1
sentinel_down_after = "30s"
sentinel_failover_timeout = "5m"
sentinel_notification_script = ""
sentinel_client_reconfig_script = ""# 啟動 Dashboard
nohup /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 &
Codis Proxy
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 false
backend_primary_only = false
# Set backend parallel connections per server
backend_primary_parallel = 1
backend_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-proxy
nohup /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 添加
Codis-Server
# 啟動 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.1
protected-mode yes
port 6379
tcp-backlog 2048
timeout 0
tcp-keepalive 300
daemonize no
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile "/opt/local/codis/logs/redis.log"
maxmemory 10gb
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename redis_dump.rdb
dir /opt/local/codis/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
Codis-FE
這里要注意下,F(xiàn)E才是真正的展示頁面,所以監(jiān)聽的地址要寫本機(jī)的地址,這樣才可以在瀏覽器中訪問集群的控制面板,而codis-dashboard是算是后臺的服務(wù),一開始沒弄明白(搞死了,弄了一上午)
# 啟動 codis-fe
nohup /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-admin
其實(shí)是集群的命令管理工具
# 添加 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-15fba3007f3c6ee0887749681cb82307
proxy is working ...# 修復(fù)異常退出的 Codis-dashboard
# dashboard 非正常退出,或者 kill -9 時使用
/opt/local/codis/bin/codis-admin --remove-lock --product=codis-demo --zookeeper=127.0.0.1:2181# 修復(fù)異常退出的 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
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
分享題目:安裝codis以及遇到的一些問題-創(chuàng)新互聯(lián)
網(wǎng)頁URL:
http://weahome.cn/article/deciss.html