The most complete and simplest centos7 install zookeeper and build zookeeper cluster

1. Install zookeeper on centos7

1. Update your system's package manager with the following command:

sudo yum update

2. Use the following command to install JDK:

sudo yum install java-1.8.0-openjdk-devel

3. Use the following command to download ZooKeeper on the Apache website:

wget https://downloads.apache.org/zookeeper/zookeeper-3.7.0/apache-zookeeper-3.7.0-bin.tar.gz

If you need other versions of zookeeper or report that there is no such resource, go to

https://downloads.apache.org/zookeeper/

Query the version you need, just change the link.

4. Unzip ZooKeeper with the following command:

tar -xvf apache-zookeeper-3.7.0-bin.tar.gz

5. Rename the decompressed directory to "zookeeper":

mv apache-zookeeper-3.7.0-bin zookeeper

6. Create the ZooKeeper data directory:

sudo mkdir /var/lib/zookeeper/data

sudo mkdir /var/lib/zookeeper/logs

7. Create a ZooKeeper configuration file:

sudo nano zookeeper/conf/zoo.cfg

The usage of the Nano command can be Baidu, or you can use the vi command

Add the following lines of code to the file:

tickTime=2000

dataDir=/var/lib/zookeeper/data

dataLogDir=/var/lib/zookeeper/logs

clientPort=2181

These settings configure the ZooKeeper tick time (in milliseconds), the data directory where ZooKeeper stores data, and the client ports that ZooKeeper listens on.

8. Start ZooKeeper with the following command:

zookeeper/bin/zkServer.sh start

9. Use the following command to check whether ZooKeeper is running:

./zkServer.sh status

##或者

zookeeper/bin/zkCli.sh

As for whether the original zookeeper needs to be uninstalled, I personally think that it has little impact.

2. Build a zookeeper cluster

1. Follow the steps provided earlier to install and configure ZooKeeper on each node in the cluster. Assign each node in the cluster a unique ID by creating a file named "myid" in each node's ZooKeeper data directory. ID.

        For example, if the ID of the first node is 1, create a file named "/var/lib/zookeeper/data/myid" on that node with the content "1" (without quotes). Be sure to put it under data, otherwise it will report an error that the myid file cannot be found.

        Edit the ZooKeeper configuration file on each node to include a list of all nodes in the cluster. Open the configuration file (default is /opt/zookeeper/conf/zoo.cfg), add a line for each node, the format is as follows:

server.<ID>=<hostname>:2888:3888

        <ID> is replaced with the ID number of the node, <hostname> is replaced with the host name or IP address of the node, 2888 is replaced with the port number of ZooKeeper point-to-point communication, and 3888 is replaced with the port number of the leader election. For example, if the ID of the first node is 1, the host name is "zookeeper1", and the ip is "192.168.211.136", add the following line to the configuration file:

server.1=zookeeper:2888:3888
##或
server.1=192.168.111.136:2888:3888
##若有3台服务器,则需要添加三行:
server.1=192.168.111.136:2888:3888
server.2=192.168.111.135:2888:3888
server.3=192.168.111.134:2888:3888

Note: Do not leave a blank line after adding

2. Start the zookeeper service of each server separately

/opt/zookeeper/zookeeper/bin/zkServer.sh start

3. View status

/opt/zookeeper/zookeeper/bin/zkServer.sh status

Running status follower is the slave server leader is the master server node

3. If you are using a virtual machine, you also need to pay attention to the following configurations:

1. Centos cannot be connected to the Internet under the virtual machine

1. First adjust the network adapter of the virtual machine to NAT mode

2. Set the "Edit" of the virtual machine --> "Virtual Network Editor" in the DHCP settings of VMnet8 and both options are checked.

 The default is ticked

3. Open the VMware DHCP Service and VMware NAT Service services of the physical host in CMD (running as an administrator), command

net start "VMware DHCP Service"
net start "VMware NAT Service"

4. CentOS does not start the network card by default, it needs to be started manually

cd /etc/sysconfig/network-scripts/

ls Check the corresponding number behind ifcfg-eno, take ens33 as an example

Switch to the root user,

vi ifcfg-ens33

edit the file settings

ONBOOT=yes

5. Restart

service NetworkManager stop
service network restart
service NetworkManager start

2. Configure static IP

Because each restart of the virtual machine may cause the IP to change, you need to do some configuration

vi /etc/sysconfig/network-scripts/ifcfg-ens33

Set BOOTPROTO to static

Then add the two values ​​​​ip and subnet mask below

IPADDR=192.168.158.131 (fill in your ip) #IP address

NETMASK=255.255.255.0 (fill in your mask value) #mask value

GATEWAY=192.168.111.1 (default gateway) View in virtual machine-edit-virtual network editor

DNS1=Same as GATEWAY

 

Check the subnet IP and click Edit --> Virtual Network Editor

 

Guess you like

Origin blog.csdn.net/y30345/article/details/130112038