"Linux Beginner" zookeeper cluster, win under Jenkins installation (iii)

Source: Internet
Author: User
Tags zookeeper

1, Zookeeper cluster:

In a large Java project, the configuration of environment variables is important, and even project startup is difficult without a good configuration environment variable.

Export zookeeper_home=/home/zookeeper-3.3.3

Export path= $PATH: $ZOOKEEPER _home/bin: $ZOOKEEPER _home/conf

(1) Zookeeper single-Machine mode deployment

Zookeeper's stand-alone mode is often used to quickly test client applications, which in practice cannot be a stand-alone mode. The configuration of the standalone mode is also relatively simple.

L Write configuration file zoo.cfg
The zookeeper-3.3.3/conf folder below is where you write the configuration file. Create a new file zoo.cfg below the folder. The zookeeper run defaults to reading the contents of the Zoo.cfg file. The following is a sample of the simplest configuration file:

ticktime=2000
Datadir=/var/zookeeper
clientport=2181

In this file, we need to specify the value of DataDir, which points to a directory, which needs to be empty at the beginning. The following are the meanings of each parameter:
Ticktime: The base event unit, in milliseconds. This time is the interval between Zookeeper servers or between the client and server, which means that each ticktime time sends a heartbeat.
DataDir: The location of the database snapshot stored in memory, as the name implies is Zookeeper to save the data directory, by default, Zookeeper will write the data log file is also stored in this directory.
ClientPort: This port is the port that the client connects to the Zookeeper server, Zookeeper listens to the port and accepts the client's access request.


When using stand-alone mode, the user needs to be aware that there is no ZooKeeper copy in this configuration, so if the ZooKeeper server fails, the ZooKeeper service will stop.

L Execute Run Script
Run zkserver.sh under the Zookeeper-3.3.3/bin folder and the Zookeeper service will start up after the run is complete.

./zkserver.sh Start
The script defaults to calling the configuration inside the zoo.cfg, so the program starts normally.

(2) Zookeeper cluster mode deployment
Zookeeper cluster mode, multiple zookeeper servers will elect a leader before work, the elected leader die in the next job, and the remaining zookeeper server will know that the leader is dead. In the living zookeeper cluster will continue to elect a leader, the purpose of the election leader is to be in a distributed environment to ensure the consistency of the data.

Confirm the number of cluster servers
Because there is a leader in the zookeeper cluster that manages and coordinates other clustered servers, the number of servers is usually singular, such as 3,5,7 ... So that the number of 2n+1 servers can allow up to n servers to fail.

L Write a configuration file
The configuration file needs to be written on each server, and here is a sample of the configuration file:

# Filename Zoo.cfg
ticktime=2000
datadir=/var/zookeeper/
clientport=2181
Initlimit=5
synclimit=2

server.1=202.115.36.251:2888:3888
server.2=202.115.36.241:2888:3888
server.3=202.115.36.242:2888:3888

Initlimit: This configuration item is used to configure the Zookeeper accept client (the client here is not the client that connects the Zookeeper server, but the Leader that is connected to Follower in the Zookeeper server cluster) Server) The maximum number of heartbeat intervals that can be tolerated when a connection is initialized. The client connection failed when the Zookeeper server has not received the return information of the client after 10 heartbeats (that is, ticktime) length. The total length of time is 5*2000=10 seconds.

Synclimit: This configuration item identifies the length of time that a message, request and response is sent between Leader and Follower, the maximum number of ticktime, and the total length of time is 2*2000=4 seconds

Server. A=b:c:d: Where A is a number, indicating this is the first server, B is the IP address of this server, C is the server and the Leader server in the cluster to exchange information on the port; D means that in case the Leader server in the cluster hangs, a port is needed to re-elect , select a new Leader, which is the port that the server communicates with each other when the election is performed. If it is a pseudo-cluster configuration, because B is the same, so different Zookeeper instance communication port numbers can not be the same, so they should be assigned a different port number.

Create a myID file
In addition to modifying the Zoo.cfg configuration file, the cluster mode to configure a file myID, the file in the DataDir directory, the file is only one of the data is a value, Zookeeper startup will read this file, get the data inside and zoo.cfg The configuration information is compared to determine the server.

Execute Run Script
and stand-alone mode is basically the same way, it is worth noting that you have to do it on different servers, such as running on 251,241,242, respectively:

./zkserver.sh Start
This will enable the entire cluster to start up.


2. Jenkins:

Continuous integration is a simple repetition of labor, people to operate time and effort, the use of automated building tools to complete the best.

In order to fulfill this requirement, I chose Jenkins.

Download the latest installed version of Jenkins from Http://mirrors.jenkins-ci.org/windows/latest under Windows. (If unable to install, download the war package from Http://mirrors.jenkins-ci.org/war/latest/jenkins.war, manual configuration, configuration instructions see https://wiki.jenkins-ci.org/ Display/jenkins/use+jenkins).

1. Installation

Use the installation package directly here to extract Tomcat to a directory, such as/usr/local, into the/bin directory under Tomcat and start Tomcat

Put the Jenkins.war file into the WebApps directory under Tomcat, and when you start Jenkins, the Jenkins directory is automatically created in the WebApps directory

Jenkins, the default port is 8080, if you need to modify, open the installation directory of the Jenkins.xml file, modify the <arguments>-xrs-xmx256m-dhudson.lifecycle= Hudson.lifecycle.windowsservicelifecycle-jar "%base%\jenkins.war"--httpport=8081</arguments> after saving, Start the Jenkins service.

Open http://192.168.0.10:8081/and see an interface similar to the following (I have created a task here):


Indicates that Jenkins has been successfully installed.

2. Create a task

2.1 "New Job", the interface is as follows:


Enter a task name, any name can be, but preferably a meaningful name, where the name and project name are the same as Hummer

2.2 Select the project type, because my project is a MAVEN project, select " Build a MAVEN2/3 project" and click "OK" to go to the next interface.

The 2.3 interface is as follows:


Source control according to their own needs to choose, my source code is the use of SVN management, here Select "Subversion Modules", in the "Repository URL" input your SVN warehouse address, the first time you need to enter the SVN warehouse user name and password.

The interface is larger, scrolling down, the interface of the middle section is as follows:

To build the trigger, I chose "build whenever a SNAPSHOT dependency is built", which means that depending on the build of the snapshot, the project should be built when SVN has been modified.

2.4 Build settings do not have to be modified, use Pom.xml, and the target option is not modified.

2.5 Set the post-build steps, (post Steps, optional settings), I'll ask you to copy the war file to the specified directory after the build succeeds, then deactivate Tomcat, delete the Project Web directory, and start Tomcat.

2.6 Setting up email notifications

Tick "e-mail Notification", in the recipients to enter the email to receive mail.

Click "Save" to complete the setup

3. Click "Build Now" on the left menu of the work area to start building the project,


If the build succeeds, the state of the project is blue and red if it fails.


When the build is complete, the left menu will show "console output" and click to view the console verbose output. Build errors can also be modified according to the appropriate error message.


"Linux Beginner" zookeeper cluster, win under Jenkins installation (iii)

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.