Construction of Zookeeper cluster

1. Cluster mode

1. Stand-alone mode

    Configuring only one server.id in zoo.cfg is the stand-alone mode.

    In this mode, if the current host goes down, all other servers that depend on the current zookeeper service work cannot work normally. This event is called a single-node node failure. So this mode is generally used in the test environment.

2. Pseudo-distributed

    Configure multiple server.ids in zoo.cfg, where the ip is the current machine, and the ports are different. It is a pseudo-cluster mode at startup.

    This mode has the same problems as the stand-alone mode. This pattern is also used in test environments.

3. Fully distributed

    Multiple machines configure the zoo.cfg file and add each other to the server list. The cluster built above is this kind of fully distributed.

    This mode is the zookeeper cluster mode used in real production environments.

Second, the construction of the zookeeper cluster

    At least three machines are required to build a zookeeper cluster, and jdk needs to be installed as the most basic support.

1. Prepare the virtual machine

    Prepare three virtual machines and plan the ip and port.

2. Install jdk

    Install jdk in the virtual machine and configure the environment variables of jdk.

3. Build a cluster

1. Download the installation package

    Download the zookeeper installation package, download address: http://zookeeper.apache.org/

    Upload it to the Linux cluster environment, plan your own management directory, and decompress the installation package.

tar -zxvf zookeeper-3.4.7.tar.gz

2. Cluster configuration

    Enter the conf directory, copy zoo-sample.cfg to zoo.cfg, and configure zookeeper by modifying zoo.cfg.

1> Data save location

    dataDir specifies the directory in which zookeeper saves the data. If it is not modified, it will be in /tmp by default. The data in this directory may be automatically cleaned up by Linux when the disk space is insufficient or the server is restarted, so be sure to modify this address. Modify it to your own management directory according to personal habits.

2> Modify the server list

    Fully distributed: Multiple machines are configured individually.

server.1=xxx.xxx.xxx.xxx:2888:3888
server.2=xxx.xxx.xxx.xxx:2888:3888
server.3=xxx.xxx.xxx.xxx:2888:3888

    Add these three lines at the end of the configuration file, and ip fill in the ip you plan. The default port numbers of the zookeeper service are 2888 and 3888. You can also add the host and ip mapping to the /etc/hosts file, and write the ip here as hostname.

    It is recommended to fill in the hostname.

3>myid

    Go to the directory where the previously configured zookeeper data file is located to generate a file called myid, in which a number is written to indicate which number the current machine is.

    Note: The file name must be myid, and the file content only needs a number, which is the number of the current server in the server list.

3. start zookeeper

    The various commands to start zookeeper are as follows. You can use the absolute path to operate these commands, or you can use the relative path to operate these commands. The relative path needs to enter the bin directory of the zookeeper service to operate.

#启动ZK服务: 
bin/zkServer.sh start
#停止ZK服务: 
bin/zkServer.sh stop
#重启ZK服务: 
bin/zkServer.sh restart
#查看ZK服务状态: 
bin/zkServer.sh status

    Zookeeper clusters need to be started one by one.

    You can use the jps command to view threads.

    When starting the cluster, if the number of clusters is less than half, the status will show an error message. When the number of clusters exceeds half, it will automatically change to the normal state, and the server that makes the cluster work normally will become the leader role. Other servers have the role of flower.

    The construction of the Zookeeper cluster mode is now complete.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324938460&siteId=291194637