CentOS+Jdk+Jboss+Dubbo配置教程

目录

目录

1.软件准备

2.安装步骤

2.1.安装虚拟机

2.2.在CentOS上安装JDK

2.3.安装Jboss

2.4.Zookeeper单机版的安装与测试

2.5.Zookeeper 集群安装

2.6.dubbo管理控制台及集成zookeeper集群部署


CentOS+Jdk+Jboss+Dubbo配置教程

1.软件准备

虚拟机:VMware-workstation-full-10.0.0-1295980.exe

CentOS:

CentOS-5.10-i386-bin-DVD-1of2.iso、CentOS-5.10-i386-bin-DVD-2of2.iso

Jdk7jdk-7u45-linux-i586.rpm

Jboss7.1.1jboss-as-7.1.1.Final.zip

Zookeeperzookeeper-3.4.5.tar.gz

SSH工具:SSHSecureShellClient-3.2.9.exe

2.安装步骤

2.1.安装虚拟机

  • 在电脑上安装VMware-workstation-full-10.0.0-1295980.exe
  • 在Vmware上安装CentOS操作系统

2.2.在CentOS上安装JDK

  • 查看Linux自带的JDK是否已安装(卸载centOS已安装的1.4

安装好的CentOS会自带OpenJdk,用命令 java -version ,会有下面的信息:

# java –version注:下面开始#开始是shell命令,并且用颜色区分

java version "1.6.0"

       OpenJDK Runtime Environment (build 1.6.0-b09)

       OpenJDK 64-Bit Server VM (build 1.6.0-b09, mixed mode)

最好还是先卸载掉openjdk,在安装sun公司的jdk,先查看 rpm -qa | grep java

#rpm -qa | grep java

java-1.4.2-gcj-compat-1.4.2.0-40jpp.115

java-1.6.0-openjdk-1.6.0.0-1.7.b09.el5

卸载:

#rpm -e --nodeps java-1.4.2-gcj-compat-1.4.2.0-40jpp.115

#rpm -e --nodeps java-1.6.0-openjdk-1.6.0.0-1.7.b09.el5

  • 安装JDK

在usr下新建java文件夹,用ssh工具将安装包jdk-7u45-linux-i586.rpm放在/usr/java目录下,然后安装JDK,注:也可以直接在centos直接点击安装jdk;

# cd /usr/java

# sudo rpm -ivh jdk-7u45-linux-i586.rpm

  • 配置环境变量

# vi /etc/profile

按i 进入vi插入模式,光标移动到最后,在最后加入以下几行:

export JAVA_HOME=/usr/java/jdk1.6.0_10

export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

export PATH=$PATH:$JAVA_HOME/bin

按ESC

wq(退出vi 并保存)

# reboot (重启机器配置生效)

2.3.安装Jboss

  • 把jboss解压文件放到usr文件夹下面,目录文件结构/usr/jboss-as-7.1.1.Final/bin
  • 执行添加管理员用户

#cd /usr/local/jboss/bin

#sh add-user.sh

What type of user do you wish to add?

  a) Management User (mgmt-users.properties)

  b) Application User (application-users.properties)

: a

Enter the details of the new user to add.

Realm (ManagementRealm) :  (回车)

Username : (输入用户名)

Password : (输入密码)

Re-enter Password :(重新输入密码)

About to add user 'adminjboss' for realm 'ManagementRealm'

Is this correct yes/no? yes

Added user 'adminjboss' to file '/usr/local/jboss/standalone/configuration/mgmt-users.properties'

Added user 'adminjboss' to file '/usr/local/jboss/domain/configuration/mgmt-users.properties'

  • 配置环境变量

# vi /etc/profile

export JBOSS_HOME=/usr/jboss-as-7.1.1.Final

  export PATH=$PATH:$JBOSS_HOME/bin

:wq

  • 修改standalone.xml文件

编辑standalone.xml文件,将jboss.bind.address.management、jboss.bind.address127.0.0.1替换为本机IP或者0.0.0.0

vi /jboss/standalone/configuration/standalone.xml

保存并退出,按ESC后输入:wq

  • 编辑防火墙

vi /etc/sysconfig/iptables

注意要在最后一句的前面添加如下语句:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 8009 -j ACCEPT

  • 启动jboss

启动jboss有两种方式:

(1)如果关闭当前窗口则jboss服务也被关闭。

#sh /usr/jboss-as-7.1.1.Final/bin/standalone.sh

(2)如果关闭当前窗口则jboss服务在后台运行。

#nohup /usr/jboss-as-7.1.1.Final/bin/standalone.sh

jboss启动后访问http://(centosip地址):9990/

即可出现管理员页面,表示启动成功。(IP为用户在standalone.xml配置文件中配置过的IP)

  • 部署Jboss Web程序,这里只将简单的打包 war
  • 利用jdk里的工具,例如我们要打包的文件在D:\cbweb;

运行 cmd; md D:\cbweb进入D:\cbweb

然后输入jar -cvf  cbweb.war *

回车,文件配打包成cbweb.war *,位于D:\cbweb中。

  • 利用eclipse

在WebRoot上单击右键,选择Export选项,

然后选择J2EE   WAR   file选项,然后选择工程名称和路径,单击完成就可以了。

  • 将打包的war文件放到standalone/deployments目录下,然后访问访问http://(centosip地址):9990/cbweb

2.4.Zookeeper单机版的安装与测试

  • 下载最新的稳定版并zookeeper-3.4.5.tar.gz,放到/home/文件夹下面,解压

#tar -zxvf zookeeper-3.4.5.tar.gz

  • 生成配置

conf/目录下有个zoo_sample.cfg,是样板配置文件,复制一份成zoo.cfg,里面有两个比较重要的配置:

dataDir=/var/lib/zookeeper # 数据存放位置,可根据需要修改

clientPort=2181 # 服务监听端口,可根据需要修改

# cd zookeeper-3.4.5

# cp conf/zoo_sample.cfg conf/zoo.cfg

# vi conf/zoo.cfg

# vi 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.

# do not use /tmp for storage, /tmp here is just

# example sakes.

dataDir=/home/zookeeper-3.4.5/data数据存放位置,可根据需要修改

# the port at which the clients will connect

clientPort=2181服务监听端口,可根据需要修改

#

# Be sure to read the maintenance section of the

# administrator guide before turning on autopurge.

#

# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance

#

# The number of snapshots to retain in dataDir

#autopurge.snapRetainCount=3

# Purge task interval in hours

"conf/zoo.cfg" 25L, 820C written

# mkdir data(新建文件夹)

  • 启动、关闭服务,查看服务状态

# ./bin/zkServer.sh start(启动服务)

JMX enabled by default

Using config: /home/zookeeper-3.4.5/bin/../conf/zoo.cfg

Starting zookeeper ... STARTED

# ./bin/zkServer.sh status(查看服务状态)

JMX enabled by default

Using config: /home/zookeeper-3.4.5/bin/../conf/zoo.cfg

Mode: standalone

# ./bin/zkServer.sh stop(停止服务)

JMX enabled by default

Using config: /home/zookeeper-3.4.5/bin/../conf/zoo.cfg

Stopping zookeeper ... STOPPED

  • 运行淘宝提供者dubbo-demo-provider-2.3.0-assembly.tar.gz、消费者dubbo-demo-consumer-2.3.0-assembly.tar.gz实例

安装提供者:

#tar zxvf dubbo-demo-provider-2.3.0-assembly.tar.gz

#cd dubbo-demo-provider-2.3.0

dubbo.registry.address的值改为zookeeper://127.0.0.1:2181

#vi conf/dubbo.properties

启动提供者:

#./bin/start.sh

安装消费者:

#tar zxvf dubbo-demo-consumer-2.3.0-assembly.tar.gz

#cd dubbo-demo-consumer-2.3.0

dubbo.registry.address的值改为zookeeper://127.0.0.1:2181

#vi conf/dubbo.properties

启动消费者:

#./bin/start.sh

可以在logs/stdout.log查看运行信息。

2.5.Zookeeper 集群安装

参考zookeeper 集群安装(单点与分布式成功安装)摘录 - 我的Java路上那些事儿 - BlogJava

  • 准备3台linux机器,IP如下

192.168.67

192.168.68

192.168.69

  • 分别拷贝zookeeper-3.4.5.tar.gz到每台机器上,进行如下设置:

修改zoo.cfg文件,参考单机版

[root@localhost zookeeper-3.4.5]# vi conf/zoo.cfg

tickTime=2000

initLimit=10

syncLimit=5

dataDir=/home/zookeeper-3.4.5/data

clientPort=2181

dataLogDir=/home/zookeeper-3.4.5/logs

server.1=192.168.67:4000:5000  

server.2=192.168.68: 4000:5000

server.3=192.168.69: 4000:5000

  • 设置myid

设置192.168.67上data文件夹下myid内容为1;

设置192.168.68上data文件夹下myid内容为2;

设置192.168.69上data文件夹下myid内容为3;

  • 启动集群

分别在三台机器上启动zookeeper:

[root@localhost zookeeper-3.4.5]# bin/zkServer.sh start

JMX enabled by default

Using config: /home/zookeeper-3.4.5/bin/../conf/zoo.cfg

Starting zookeeper ... STARTED

完成以后查看状态:

192.168.67

[root@localhost zookeeper-3.4.5]# bin/zkServer.sh status

JMX enabled by default

Using config: /home/zookeeper-3.4.5/bin/../conf/zoo.cfg

Mode: follower

192.168.69

[root@localhost home]#  zookeeper-3.4.5/bin/zkServer.sh status

JMX enabled by default

Using config: /home/zookeeper-3.4.5/bin/../conf/zoo.cfg

Mode: follower

192.168.68

[root@localhost home]#  zookeeper-3.4.5/bin/zkServer.sh status

JMX enabled by default

Using config: /home/zookeeper-3.4.5/bin/../conf/zoo.cfg

Mode: leader

2.6.dubbo管理控制台及集成zookeeper集群部署

阿里巴巴文档没有开放了,控制台代码没有下到,不过可以看看网上的文章:http://blog.csdn.net/rangqiwei/article/details/19398301

你可能感兴趣的:(linux,dubbo,java)