CentOS 7 x64 Codis cluster and standalone Docker

Source: Internet
Author: User
Tags docker run



# to install Zookeeper



wget http://mirrors.cnnic.cn/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz


Tar zxvf zookeeper-3.4.6.tar.gz


MV Zookeeper-3.4.6/opt/local/zookeeper


Mkdir/opt/local/zookeeper/logs


cd/opt/local/zookeeper/conf/


CP Zoo_sample.cfg Zoo.cfg


VI zoo.cfg Modifying configuration files


Modify DataDir

Datadir=/opt/local/zookeeper/data

and increase the log

Datalogdir=/opt/local/zookeeper/logs


Start Zookeeper

/opt/local/zookeeper/bin/zkserver.sh start



The following is a cluster configuration

-------------------------------------------------------

ticktime=2000

Initlimit=5

synclimit=2

Datadir=/opt/local/zookeeper/data

Datalogdir=/opt/local/zookeeper/logs

clientport=2181

server.1=0.0.0.0:2888:3888

server.2=172.16.32.33:2888:3888

server.3=172.16.32.40:2888:3888

#maxClientCnxns =60

#autopurge. snapretaincount=3

#autopurge. purgeinterval=1

-------------------------------------------------------


Echo 1 >/opt/local/zookeeper/data/myid

Echo 2 >/opt/local/zookeeper/data/myid

Echo 3 >/opt/local/zookeeper/data/myid


Start Zookeeper


/opt/local/zookeeper/bin/zkserver.sh start


View startup status

/opt/local/zookeeper/bin/zkserver.sh status






# Install the Go language first


wget https://storage.googleapis.com/golang/go1.4.2.linux-amd64.tar.gz


Tar zxvf go1.4.2.linux-amd64.tar.gz


MV go/usr/local/



# Configure Environment variables


Vi/etc/profile


Export Goroot=/usr/local/go

Export path= $PATH: $GOROOT/bin

Export Gopath=/usr/local/codis




Source/etc/profile


Perform

Go version

View version





Installing Codis


Yum install-y git


Go get-u-D github.com/wandoulabs/codis #这个需要几分钟下载共30M文件

Package Github.com/wandoulabs/codis

Imports Github.com/wandoulabs/codis

Imports Github.com/wandoulabs/codis:no buildable Go Source

Files In/usr/local/codis/src/github.com/wandoulabs/codis


Cd/usr/local/codis/src/github.com/wandoulabs/codis


# installation Configuration


./bootstrap.sh #这个需要十几分钟共下载50M文件

Make Gotest



# after compiling, copy the bin directory and some scripts into the past/usr/local/codis directory:


Mkdir-p/usr/local/codis/{logs,conf,scripts}

Mkdir-p/opt/local/codis_server/{logs,conf,data}


CP-RF bin/usr/local/codis/

CP sample/config.ini/usr/local/codis/conf/

CP sample/redis_conf/6381.conf/opt/local/codis_server/conf/

cp-rf/usr/local/codis/src/github.com/wandoulabs/codis/sample/*.sh/usr/local/codis/scripts/

cp-rf/usr/local/codis/src/github.com/wandoulabs/codis/sample/usage.md/usr/local/codis/scripts/

cp/usr/local/codis/src/github.com/wandoulabs/codis/extern/redis-2.8.21/src/redis-cli/usr/local/codis/bin/ redis-cli-2.8.21

Ln-s/USR/LOCAL/CODIS/BIN/REDIS-CLI-2.8.21/USR/LOCAL/CODIS/BIN/REDIS-CLI




# Modify configuration file


Cd/usr/local/codis/conf


VI Config.ini


# Modify IP, configure Web admin default 18087 port


Dashboard_addr


(ZK configuration zookeeper address, single-machine configuration one, cluster configuration multiple ~ Already, number separated)


Proxy_id=codis_proxy_1 configured as Unique


Product= # Zookeeper Node information



cd/opt/local/codis_server/conf/


# Modify Redis configuration file


6381.conf


CP two parts are 6379.conf 6380.conf, respectively, and from the configuration


# Modify the configuration ports inside and configure the configuration needs to be modified as follows:


Daemonize Yes #后台模式运行

Pidfile var/run/redis_6379.pid #pid File

Port 6379 #运行端口

Timeout #请求超时时间, default 0

LogFile "/opt/local/codis_server/logs/codis_6379.log" #日志文件

Save 1 #打开保存快照的条件 (the first * indicates how long, and the third * indicates how many write operations are performed)

Save 300 10

Save 60 10000

Dbfilename 6379.rdb #数据快照保存的名字

Dir/opt/local/codis_server/data #数据快照的保存目录

Appendfilename "6379_appendonly.aof" #Redis更加高效的数据库备份及灾难恢复方式.

Appendfsync everysec # (always:always indicates that each write operation is synchronized. Everysec: Indicates that the write operation is cumulative, synchronized once per second)




# Start Codis-server Service


/usr/local/codis/bin/codis-server/opt/local/codis_server/conf/6379.conf


/usr/local/codis/bin/codis-server/opt/local/codis_server/conf/6380.conf




# Modify Dashboard Startup script

vi/usr/local/codis/scripts/start_dashboard.sh




# Modify to the following path:

Nohup/usr/local/codis/bin/codis-config-c/usr/local/codis/conf/config.ini-l/opt/local/codis_server/logs/ Dashboard.log Dashboard--addr=:18087--http-log=/opt/local/codis_server/logs/requests.log &>/dev/

Null &




# start

/usr/local/codis/scripts/start_dashboard.sh




# Visit Dashboard

http://localhost:18087/admin/



------------------------------------------------------------------------------------

Dashboard prohibit use of kill-9 end process


If the process is closed using kill-9 or an unexpected shutdown, the Zookeeper node information needs to be removed before it can be started.


or modify the product option in Config.ini to fill in a different node.


------------------------------------------------------------------------------------



# Add Redis Group


/usr/local/codis/scripts/


vi/usr/local/codis/scripts/add_group.sh


--------------------------------------------------------------------------------------------------------------- ----------------------------

#!/bin/sh


Let Group=0


For port in 638{0..3}; Do

Let group= "1+group"

echo "Add group $group with a master (localhost: $port), notice:do not use localhost when Produciton"

/usr/local/codis/bin/codis-config-c/usr/local/codis/conf/config.ini-l/opt/local/codis_server/logs/cconfig.log Server add $group localhost: $port master

Done

--------------------------------------------------------------------------------------------------------------- ----------------------------



Run/usr/local/codis/scripts/add_group.sh Auto-add




# server Groups--> New Server Group--> Add new Redis Instance


#通过管理页面添加组ID, to add a master-slave instance to a group, there can only be one redis-master in a group:


The first master one from the default each group inside the first instance is the primary


Group_1

127.0.0.1:6379 Master

127.0.0.1:6380 slave


Group_2


..............


Group_3


..............


Group_4


..............



Must have 4 groups or more, otherwise the error




# Modify script, initialize slot


vi/usr/local/codis/scripts/initslot.sh


---------------------------------------------------------------------------------------------------------------


#!/bin/sh

echo "Slots initializing ..."

/usr/local/codis/bin/codis-config-c/usr/local/codis/conf/config.ini Slot Init-f

echo "Done"


echo "Set slot ranges to server groups ..."

For ((i=0;i<4;i++)); Do

Let beg= "256*i"

Let end= "256*i + 255"

Let group= "1+i"

/usr/local/codis/bin/codis-config-c/usr/local/codis/conf/config.ini slot Range-set $beg $end $group Online

Done

echo "Done"


--------------------------------------------------------------------------------------------------------------- -




# startup script (initialize Solt after group setup)


/usr/local/codis/scripts/initslot.sh






# Modify start_proxy.sh, start Codis-proxy service


vi/usr/local/codis/scripts/start_proxy.sh


--------------------------------------------------------------------------------------------------------------- -------------------------

#!/bin/sh

echo "Shut down proxy_1 ..."

/usr/local/codis/bin/codis-config-c/usr/local/codis/conf/config.ini Proxy Offline proxy_1

echo "Done"


echo "Start new proxy ..."

Nohup/usr/local/codis/bin/codis-proxy--log-level info-c/usr/local/codis/conf/config.ini-l/opt/local/codis_ Server/logs/proxy.log--cpu=8--addr=0.0.0.0:19000--http-addr=0.0.0.0:11000 &

echo "Done"


echo "Sleep 3s"

Sleep 3

Tail-n 30/opt/local/codis_server/logs/proxy.log


--------------------------------------------------------------------------------------------------------------- ---------------------------






vi/usr/local/codis/scripts/set_proxy_online.sh


--------------------------------------------------------------------------------------------------------------- ---------------------------

#!/bin/sh

echo "Set Proxy_1 online"

/usr/local/codis/bin/codis-config-c/usr/local/codis/conf/config.ini Proxy Online proxy_1

echo "Done"


--------------------------------------------------------------------------------------------------------------- ---------------------------




# Start Proxy

/usr/local/codis/scripts/start_proxy.sh




# Online Proxy

/usr/local/codis/scripts/set_proxy_online.sh










Docker


172.16.1.52


Docker run-h= "Codis"--name codis-d-v/opt/upload/zookeeper:/opt/local/zookeeper/data-v/opt/upload/codis/data:/opt /local/codis_server/data-v/opt/upload/codis/logs:/opt/local/codis_server/logs-p 2181:2181-p 22:22-p 6379:6379-p 6380:6380-p 19000:19000-p 18087:18087-p 11000:11000 Centos/mx-codis



----------------------------------------------------------------------------------------

Cluster version Codis_proxy


Docker needs to configure a fixed IP mode, otherwise IP addr reads the NIC IP for the Docker container


----------------------------------------------------------------------------------------


CentOS 7 x64 Codis cluster and standalone Docker

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.