1. 程式人生 > >dubbo搭建

dubbo搭建

dubbo 搭建

環境:

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.設置主機名:

[[email protected] ~]# 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

[[email protected] src]# tar zxf jdk-7u79-linux-x64.tar.gz

[[email protected] 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)。


本文出自 “IT運維” 博客,請務必保留此出處http://itops.blog.51cto.com/2420369/1947799

dubbo搭建