Dubbo recommends using Zookeeper as a registry for services.
Registration center server (192.168.1.106) configuration, install Zookeeper
1. Modify the /etc/hosts file of the operating system to add:
# zookeeper servers
192.168.1.106 edu-provider-01
2. Go to http://apache.fayea.com/zookeeper/ to download zookeeper-3.4.10:
$ wget http://apache.fayea.com/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz
3. Unzip the zookeeper installation package:
$ tar -zxvf zookeeper-3.4.10.tar.gz
4. Create the following directories in the /home/lh/dev/zookeeper-3.4.10 directory:
$ cd /home/lh/dev/zookeeper-3.4.10
$ mkdir data
$ mkdir logs
5. Copy the zoo_sample.cfg file in the zookeeper-3.4.10/conf directory and name it zoo.cfg
$ cp zoo_sample.cfg zoo.cfg
6. Modify the zoo.cfg configuration file:
$ vim 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 an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/home/lh/dev/zookeeper-3.4.10/data
dataLogDir=/home/lh/dev/zookeeper-3.4.10/logs
# the port at which the clients will connect
clientPort=2181
#2888,3888 are election port
server.1=edu-provider-01:2888:3888
in:
The 2888 port number is the port for communication between zookeeper services.
3888 is the port through which zookeeper communicates with other applications.
edu-provider-01 is the hostname whose IP has been mapped in hosts.
initLimit: This configuration item is used to configure Zookeeper to accept clients (the client mentioned here is not the client that the user connects to the Zookeeper server, but the Follower server connected to the Leader in the Zookeeper server cluster) How long can the initial connection be tolerated The number of heartbeat intervals. When the Zookeeper server has not received the return information from the client after more than 10 heartbeats (that is, tickTime), it indicates that the client connection failed. The total time length is 5*2000=10 seconds.
syncLimit: This configuration item identifies the length of the message, request and response time sent between the Leader and the Follower. The longest time length cannot exceed the length of several tickTimes. The total time length is 2*2000=4 seconds.
server.A=B:C:D: where A is a number, indicating the number of the server; B is the IP address of the server or the hostname of the IP mapped in the /etc/hosts file; C indicates this The port through which the server exchanges information with the leader server in the cluster; D indicates that in case the leader server in the cluster hangs, a port is needed to re-elect and elect a new leader, and this port is used to execute the election. The port on which the servers communicate with each other. If it is a pseudo-cluster configuration, since B is the same, the communication port numbers of different Zookeeper instances cannot be the same, so they must be assigned different port numbers.
7. Create myid file under dataDir=/home/lh/dev/zookeeper-3.4.10/data
Edit the myid file and enter the corresponding number on the machine with the corresponding IP. For example, on zookeeper, the content of the myid file is 1. If the installation configuration is only done on a single point, there is only one server.1.
$ vim myid
1
8. Modify vim /home/lh/.bash_profile under the lh user and add the zookeeper configuration:
# zookeeper env
export ZOOKEEPER_HOME=/home/lh/dev/zookeeper-3.4.10
export PATH=$ZOOKEEPER_HOME/bin:$PATH
Make the configuration file take effect
$ source /home/lh/.bash_profile
Note: The environment variables in this configuration are only valid for user lh
9. Open the ports 2181, 2888, 3888 to be used in the firewall
Switch to root user privileges and execute the following commands:
# chkconfig iptables on
# service iptables start
Edit /etc/sysconfig/iptables
# vim /etc/sysconfig/iptables
Add the following 3 lines:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 2181 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 2888 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3888 -j ACCEPT
Restart the firewall:
# service iptables restart
Check firewall port status:
# service iptables status
Table: filter
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
2 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
3 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
4 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
5 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:2181
6 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:2888
7 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:3888
8 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
num target prot opt source destination
1 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
num target prot opt source destination
Note: The 3-line configuration must be configured before the REJECT line! ! ! Otherwise invalid! ! !
10. Start and test zookeeper (start with lh user, not root) :
(1) Use the lh user to execute in the /home/lh/dev/zookeeper-3.4.10/bin directory:
$ zkServer.sh start(也可以在任意位置执行,因为配置了环境变量)
(2) Enter the jps command to view the process:
$ jps
1456 QuorumPeerMain
1475 Jps
Among them, QuorumPeerMain is the zookeeper process , which starts normally
(3) Check the status:
$ zkServer.sh status
(4) View the output information of the zookeeper service:
Since the service information output file is in /home/lh/dev/zookeeper-3.4.10/bin/zookeeper.out
$ tail -500f zookeeper.out
11. Stop the zookeeper process:
$ zkServer.sh stop
12. Configure zookeeper to start using the lh user:
Edit the /etc/rc.local file and add:
vim /etc/rc.local
su - lh -c '/home/lh/dev/zookeeper-3.4.10/bin/zkServer.sh start'