环境:

OS版本:CentOS 7.2

jdk "1.7.0_79"

Zookeeper version: 3.3.6-1366786

Dubbo版本:2.5.3

Apache Tomcat 7.0.69

 

测试环境为防止干扰,可检查并关闭linux安全设置:

# getenforce

Enforcing

# setenforce 0

编辑selinux,修改如下内容:

SELINUX=enforcing

vi /etc/sysconfig/selinux

SELINUX=disabled

 

#systemctl stop firewalld.service

#systemctl disable firewalld.service

 

1.设置主机名:

[root@localhost ~]# hostnamectl set-hostname test-dubbosvr

 

2.编辑hosts文件,添加记录:

ip hostname

# vi /etc/hosts

 

3.安装JDK:

下载jdk-7u79-linux-x64.tar.gz/usr/local/src目录

建立安装目录:

# mkdir -pv /usr/local/java

mkdir: created directory /usr/local/java

解压jdk-7u79-linux-x64.tar.gz

[root@test-dubbosvr src]# tar zxf jdk-7u79-linux-x64.tar.gz

[root@test-dubbosvr src]# mv jdk1.7.0_79 /usr/local/java

检测当前java版本:

# java -version

-bash: java: command not found

安装jdk:

# alternatives --install /usr/bin/java java /usr/local/java/jdk1.7.0_79/bin/java 2

# alternatives --config java

 

There is 1 program that provides 'java'.

 

  Selection    Command

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

*+ 1           /usr/local/java/jdk1.7.0_79/bin/java

 

Enter to keep the current selection[+], or type selection number:Please Enter

# alternatives --install /usr/bin/jar jar /usr/local/java/jdk1.7.0_79/bin/jar 2

# alternatives --install /usr/bin/javac javac /usr/local/java/jdk1.7.0_79/bin/javac 2

检测java版本:

# java -version

java version "1.7.0_79"

Java(TM) SE Runtime Environment (build 1.7.0_79-b15)

Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

配置环境变量:

# vi /etc/profile

添加内容:

export JAVA_HOME=/usr/local/java/jdk1.7.0_79

export JRE_HOME=/usr/local/java/jdk1.7.0_79/jre

export PATH=$PATH:/usr/local/java/jdk1.7.0_79/bin:/usr/local/java/jdk1.7.0_79/jre/bin

 

使环境变量生效:source /etc/profile

 

4.安装zookeeper(三节点伪分布式集群):

下载zookeeper-3.3.6.tar.gz/usr/local/src目录

解压zookeeper-3.3.6.tar.gz

# tar zxf zookeeper-3.3.6.tar.gz

建立安装目录:

# mkdir -pv /usr/local/zookeeper/{server01,server02,server03}

mkdir: created directory /usr/local/zookeeper

mkdir: created directory /usr/local/zookeeper/server01

mkdir: created directory /usr/local/zookeeper/server02

mkdir: created directory /usr/local/zookeeper/server03

建立logsdata目录:

# mkdir -pv /usr/local/zookeeper/server01/{logs,data}

mkdir: created directory /usr/local/zookeeper/server01/logs

mkdir: created directory /usr/local/zookeeper/server01/data

# mkdir -pv /usr/local/zookeeper/server02/{logs,data}

mkdir: created directory /usr/local/zookeeper/server02/logs

mkdir: created directory /usr/local/zookeeper/server02/data

# mkdir -pv /usr/local/zookeeper/server03/{logs,data}

mkdir: created directory /usr/local/zookeeper/server03/logs

mkdir: created directory /usr/local/zookeeper/server03/data

# cd /usr/local/src/zookeeper-3.3.6/conf

# cp zoo_sample.cfg zoo.cfg

编辑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.

dataDir=/usr/local/zookeeper/server01/data

dataLogDir=/usr/local/zookeeper/server01/logs

# the port at which the clients will connect

clientPort=2181

server.1=192.168.195.136:2888:3888

server.2=192.168.195.136:2889:3889

server.3=192.168.195.136:2890:3890

 

复制/usr/local/src/zookeeper-3.3.6/usr/local/zookeeper/server01目录下:

# cp -ar /usr/local/src/zookeeper-3.3.6 /usr/local/zookeeper/server01

# echo 1 > /usr/local/zookeeper/server01/data/myid

 

编辑/usr/local/src/zookeeper-3.3.6/conf/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.

dataDir=/usr/local/zookeeper/server02/data

dataLogDir=/usr/local/zookeeper/server02/logs

# the port at which the clients will connect

clientPort=2182

server.1=192.168.195.136:2888:3888

server.2=192.168.195.136:2889:3889

server.3=192.168.195.136:2890:3890

复制/usr/local/src/zookeeper-3.3.6/usr/local/zookeeper/server02目录下:

# cp -ar /usr/local/src/zookeeper-3.3.6 /usr/local/zookeeper/server02

# echo 2 > /usr/local/zookeeper/server02/data/myid

 

 

编辑/usr/local/src/zookeeper-3.3.6/conf/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.

dataDir=/usr/local/zookeeper/server03/data

dataLogDir=/usr/local/zookeeper/server03/logs

# the port at which the clients will connect

clientPort=2183

server.1=192.168.195.136:2888:3888

server.2=192.168.195.136:2889:3889

server.3=192.168.195.136:2890:3890

复制/usr/local/src/zookeeper-3.3.6/usr/local/zookeeper/server03目录下:

# cp -ar /usr/local/src/zookeeper-3.3.6 /usr/local/zookeeper/server03

# echo 3 > /usr/local/zookeeper/server03/data/myid

 

启动zookeeperzkServer.sh start:

# /usr/local/zookeeper/server01/zookeeper-3.3.6/bin/zkServer.sh start

JMX enabled by default

Using config: /usr/local/zookeeper/server01/zookeeper-3.3.6/bin/../conf/zoo.cfg

Starting zookeeper ... STARTED

# /usr/local/zookeeper/server02/zookeeper-3.3.6/bin/zkServer.sh start

JMX enabled by default

Using config: /usr/local/zookeeper/server02/zookeeper-3.3.6/bin/../conf/zoo.cfg

Starting zookeeper ... STARTED

# /usr/local/zookeeper/server03/zookeeper-3.3.6/bin/zkServer.sh start

JMX enabled by default

Using config: /usr/local/zookeeper/server03/zookeeper-3.3.6/bin/../conf/zoo.cfg

Starting zookeeper ... STARTED

 

查看zookeeper状态(zkServer.sh status):

# /usr/local/zookeeper/server03/zookeeper-3.3.6/bin/zkServer.sh status

JMX enabled by default

Using config: /usr/local/zookeeper/server03/zookeeper-3.3.6/bin/../conf/zoo.cfg

Mode: follower

# /usr/local/zookeeper/server02/zookeeper-3.3.6/bin/zkServer.sh status

JMX enabled by default

Using config: /usr/local/zookeeper/server02/zookeeper-3.3.6/bin/../conf/zoo.cfg

Mode: leader

# /usr/local/zookeeper/server01/zookeeper-3.3.6/bin/zkServer.sh status

JMX enabled by default

Using config: /usr/local/zookeeper/server01/zookeeper-3.3.6/bin/../conf/zoo.cfg

Mode: follower

 

5.安装dubbo-monitor

 

下载dubbo-monitor-simple-2.5.3-assembly.tar.gz/usr/local/src目录

建立安装目录:

# mkdir -pv /usr/local/dubbo

mkdir: created directory /usr/local/dubbo

解压dubbo-monitor-simple-2.5.3-assembly.tar.gz

# tar zxf dubbo-monitor-simple-2.5.3-assembly.tar.gz

复制/usr/local/src/dubbo-monitor-simple-2.5.3/usr/local/dubbo目录下:

# cp -ar /usr/local/src/dubbo-monitor-simple-2.5.3 /usr/local/dubbo

编辑dubbo.properties

注释如下内容:

dubbo.registry.address=multicast://224.5.6.7:1234

修改如下内容:

dubbo.registry.address=zookeeper://127.0.0.1:2181

dubbo.jetty.port=8080

dubbo.jetty.directory=${user.home}/monitor

dubbo.statistics.directory=${user.home}/monitor/statistics

dubbo.log4j.file=logs/dubbo-monitor-simple.log

 

#cd /usr/local/dubbo/dubbo-monitor-simple-2.5.3/conf

# vi dubbo.properties

dubbo.container=log4j,spring,registry,jetty

dubbo.application.name=simple-monitor

dubbo.application.owner=

#dubbo.registry.address=multicast://224.5.6.7:1234

dubbo.registry.address=zookeeper://192.168.195.136:2181?backup=192.168.195.136:2182,192.168.195.136:2183

#dubbo.registry.address=redis://127.0.0.1:6379

#dubbo.registry.address=dubbo://127.0.0.1:9090

dubbo.protocol.port=7070

dubbo.jetty.port=8088

dubbo.jetty.directory=/usr/local/dubbo/dubbo-monitor-simple-2.5.3/monitor

dubbo.charts.directory=${dubbo.jetty.directory}/charts

dubbo.statistics.directory=${dubbo.jetty.directory}/statistics

dubbo.log4j.file=/usr/local/dubbo/dubbo-monitor-simple-2.5.3/logs/dubbo-monitor-simple.log

dubbo.log4j.level=WARN

 

 创建目录monitor,logs

# mkdir -pv /usr/local/dubbo/dubbo-monitor-simple-2.5.3/{monitor,logs}

mkdir: created directory /usr/local/dubbo/dubbo-monitor-simple-2.5.3/monitor

mkdir: created directory /usr/local/dubbo/dubbo-monitor-simple-2.5.3/logs

创建目录charts,statistics

# mkdir -pv /usr/local/dubbo/dubbo-monitor-simple-2.5.3/monitor/{charts,statistics}

mkdir: created directory /usr/local/dubbo/dubbo-monitor-simple-2.5.3/monitor/charts’

mkdir: created directory /usr/local/dubbo/dubbo-monitor-simple-2.5.3/monitor/statistics’

启动dubbo:

# /usr/local/dubbo/dubbo-monitor-simple-2.5.3/bin/start.sh

Starting the simple-monitor .......OK!

PID: 16835

STDOUT: /usr/local/dubbo/dubbo-monitor-simple-2.5.3/logs/stdout.log

检查端口状态:

# netstat -ano | grep 7070

tcp        0      0 0.0.0.0:7070            0.0.0.0:*               LISTEN      off (0.00/0/0)

# netstat -ano | grep 8088

tcp        0      0 0.0.0.0:8088            0.0.0.0:*               LISTEN      off (0.00/0/0)

 

6.安装tomcat,并安装配置dubbo-admin

下载apache-tomcat-7.0.69.tar.gz/usr/local/src目录

解压apache-tomcat-7.0.69.tar.gz

# tar zxf apache-tomcat-7.0.69.tar.gz

建立安装目录/usr/local/dubbo/dubbo-admin-tomcat

# mkdir -pv /usr/local/dubbo/dubbo-admin-tomcat

mkdir: created directory /usr/local/dubbo/dubbo-admin-tomcat

复制/usr/local/src/apache-tomcat-7.0.69目录下所有文件至/usr/local/dubbo/dubbo-admin-tomcat目录下:

注:不包含/usr/local/src/apache-tomcat-7.0.69目录本身

# cp -ar /usr/local/src/apache-tomcat-7.0.69/. /usr/local/dubbo/dubbo-admin-tomcat

删除tomcat自带的webapps/ROOT目录:

# rm -rf /usr/local/dubbo/dubbo-admin-tomcat/webapps/ROOT

下载dubbo-admin-2.5.3.war/usr/local/src目录

解压dubbo-admin-2.5.3.war/usr/local/dubbo/dubbo-admin-tomcat/webapps/ROOT目录:

# unzip /usr/local/src/dubbo-admin-2.5.3.war -d /usr/local/dubbo/dubbo-admin-tomcat/webapps/ROOT

编辑/usr/local/dubbo/dubbo-admin-tomcat/webapps/ROOT/WEB-INF/dubbo.properties文件:

修改如下内容:

dubbo.registry.address=zookeeper://127.0.0.1:2181?backup=127.0.0.1:2182,127.0.0.1:2183

vi /usr/local/dubbo/dubbo-admin-tomcat/webapps/ROOT/WEB-INF/dubbo.properties

dubbo.registry.address=zookeeper://192.168.195.136:2181?backup=192.168.195.136:2182,192.168.195.136:2183

dubbo.admin.root.password=root

dubbo.admin.guest.password=guest

 


启动tomcat

# /usr/local/dubbo/dubbo-admin-tomcat/bin/startup.sh

Using CATALINA_BASE:   /usr/local/dubbo/dubbo-admin-tomcat

Using CATALINA_HOME:   /usr/local/dubbo/dubbo-admin-tomcat

Using CATALINA_TMPDIR: /usr/local/dubbo/dubbo-admin-tomcat/temp

Using JRE_HOME:        /usr/local/java/jdk1.7.0_79/jre

Using CLASSPATH:       /usr/local/dubbo/dubbo-admin-tomcat/bin/bootstrap.jar:/usr/local/dubbo/dubbo-admin-tomcat/bin/tomcat-juli.jar

Tomcat started.

检测端口及进程状态:

# netstat -nlp | grep 8080

tcp6       0      0 :::8080                 :::*                    LISTEN      16979/java          

# ps -ef | grep 16979

root      16979      1  5 21:23 pts/0    00:00:03 /usr/local/java/jdk1.7.0_79/jre/bin/java -Djava.util.logging.config.file=/usr/local/dubbo/

dubbo-admin-tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.endorsed.dirs=/usr/local/dubbo/dubbo-admin-tomcat/endorsed -classpath /usr/local/dubbo/dubbo-admin-tomcat/bin/bootstrap.jar:/usr/local/dubbo/dubbo-admin-tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/dubbo/dubbo-admin-tomcat -Dcatalina.home=/usr/local/dubbo/dubbo-admin-tomcat -Djava.io.tmpdir=/usr/local/dubbo/dubbo-admin-tomcat/temp org.apache.catalina.startup.Bootstrap startroot      16995   2539  0 21:24 pts/0    00:00:00 grep --color=auto 16979

 

7.访问dubbo

http://192.168.195.136:8080

用户名:root

密码:root

 

8.重启机器后,需要先启动zookeeper,然后启动dubbo-monitor,最后启动dubbo-admin(即tomcat)。