Linux(CentOS)安装配置zeromq、jzmq(解决各种问题)

时间:2021-10-18 22:28:42
Linux(CentOS)安装配置zeromq、jzmq(解决各种问题)

  今天为Hadoop配置zeromq、jzmq遇到各种问题,先是编译出错,到编译成功后测试出错等等,下面将我遇到的问题与大家分享一下。

  第一个注意点是:必须先编译安装zeromq,然后在编译jzmq,否则会报zmq.h文件找不到。

  官方安装配置链接:http://zeromq.org/bindings:java

Step 1:安装必须的依赖包:

[mdrill01@mdrill01 ~]$ sudo yum install autoconf automake libtool gcc gcc-g++ make libuuid-dev git java-1.6.-openjdk-devel

  备注:其中一些包依据操作系统不同所以并不是上面的名称,请使用yum list avaiable *package name*查询可获取的包,然后安装。例如:查找openjdk,蓝色背景的就是我们要找的。

ot@mdrill01 jzmq]# sudo yum list avaiable *openjdk*
Loaded plugins: fastestmirror, langpacks
          .......
Available Packages
java-1.6.-openjdk.x86_64 :1.6.0.33-1.13.5.0.el7_0 updates
java-1.6.-openjdk-demo.x86_64 :1.6.0.33-1.13.5.0.el7_0 updates
java-1.6.-openjdk-devel.x86_64 :1.6.0.33-1.13.5.0.el7_0 updates
java-1.6.-openjdk-javadoc.x86_64 :1.6.0.33-1.13.5.0.el7_0 updates
java-1.6.-openjdk-src.x86_64 :1.6.0.33-1.13.5.0.el7_0 updates
java-1.7.-openjdk.x86_64 :1.7.0.71-2.5.3.1.el7_0 updates
java-1.7.-openjdk-accessibility.x86_64 :1.7.0.71-2.5.3.1.el7_0 updates
java-1.7.-openjdk-demo.x86_64 :1.7.0.71-2.5.3.1.el7_0 updates
java-1.7.-openjdk-devel.x86_64 :1.7.0.71-2.5.3.1.el7_0 updates
java-1.7.-openjdk-headless.x86_64 :1.7.0.71-2.5.3.1.el7_0 updates
java-1.7.-openjdk-javadoc.noarch :1.7.0.71-2.5.3.1.el7_0 updates
java-1.7.-openjdk-src.x86_64 :1.7.0.71-2.5.3.1.el7_0 updates
[root@mdrill01 jzmq]# sudo yum install java-1.6.-openjdk-devel.x86_64 #安装
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
............
Dependency Updated:
python-javapackages.noarch :3.4.-.el7_0
Complete!
[root@mdrill01 jzmq]#

Step 2:编译安装zeromq-2.1.7

2.1 解压缩包

[mdrill01@mdrill01 ~]$ tar -zxvf zeromq-2.1..tar.gz

2.2 Build&&Install

$ cd
$ ./autogen.sh
$ ./configure
$ make
$ sudo make install

Step 3:编译安装jzmq

3.1从github上clone jzmq

$ git clone https://github.com/zeromq/jzmq.git

3.2 Bulid&&Install(官方提供步骤,可惜不行)

$ cd jzmq
$ ./autogen.sh
$ ./configure
$ make          #在执行make的时候报make[1]: *** No rule to make target `classdist_noinst.stamp', needed by `org/zeromq/ZMQ.class'. Stop.
$ sudo make install

3.3错误排除

  1)确保Step 1的依赖包安装完全

  2)检查JDK是不是用的openjdk6,如果不是请将JAVA_HOME临时指向/usr/lib/jvm/java-1.6.0-openjdk.x86_64/

[mdrill01@mdrill01 ~]$ echo $JAVA_HOME
/usr/java/jdk1..0_45
[mdrill01@mdrill01 ~]$ JAVA_HOME=/usr/lib/jvm/java-1.6.-openjdk.x86_64/

3.4解决错误

  1)将目录切换至jzmq/src下

  2)touch classdist_noinst.stamp

  3)执行:

CLASSPATH=.:./.:$CLASSPATH javac -d . org/zeromq/ZMQ.java org/zeromq/ZMQException.java org/zeromq/ZMQQueue.java org/zeromq/ZMQForwarder.java org/zeromq/ZMQStreamer.java

  4)

cd ..
./autogen.sh./configure
make
sudo make install

  5)测试是否安装成功,切换至jzmq/perf/目录下,执行sh local_lat.sh tcp://127.0.0.1:5000 1 100进行测试:

[mdrill01@mdrill01 jzmq]$ cd perf/
[mdrill01@mdrill01 perf]$ sh local_lat.sh tcp://127.0.0.1:5000 1 100
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jzmq in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:)
at java.lang.Runtime.loadLibrary0(Runtime.java:)
at java.lang.System.loadLibrary(System.java:)
at org.zeromq.ZMQ.<clinit>(ZMQ.java:)
at local_lat.main(local_lat.java:)

  no jzmq in java.library.path???

  解决办法:

export JAVA_LIBRARY_PATH=/usr/local/lib
或者export LD_LIBRARY_PATH=/usr/local/lib
最好将其加入~/.bashrc中
[mdrill01@mdrill01 perf]$ vi ~/.bashrc
export LD_LIBRARY_PATH=/usr/local/lib

  然后在进行测试一切OK,首先在一个终端下执行:sh local_lat.sh tcp://127.0.0.1:5000 1 100

[mdrill01@mdrill01 perf]$ source ~/.bashrc
[mdrill01@mdrill01 perf]$ sh local_lat.sh tcp://127.0.0.1:5000 1 100

  此时,打开另外一个终端执行:sh remote_lat.sh tcp://127.0.0.1:5000 1 100

[mdrill01@mdrill01 jzmq]$ cd perf/
[mdrill01@mdrill01 perf]$ pwd
/home/mdrill01/component/jzmq/perf
[mdrill01@mdrill01 perf]$ sh remote_lat.sh tcp://127.0.0.1:5000 1 100
message size: [B]            #####说明测试成功
roundtrip count:
mean latency: 140.0 [us]
[mdrill01@mdrill01 perf]$

参考:Compiling JZMQ on Ubuntu

  Hadoop and JZMQ - no jzmq in java.library.path