如何在CentOS 6.7上配置和安装ZeroMQ(libsodium)?

当开始使用ZeroMQ(版本4.2.0或更高版本)时可能会非常具有挑战性,尤其是在具备所有先决条件的情况下。 我花了整整两天的时间来解决这个问题。 因此,我分享了这些信息,以便其他人可以避免同样的陷阱,并可以很好地从头开始建立自己的环境。

陷阱#1

为您的平台开发。 我习惯于在Ubuntu 14.04.3 LTE中进行开发,但是在这种情况下,我的部署环境恰好是CentOS 6.7(最小服务器)。 因为诸如GLIBC版本的依赖关系是不同的,所以最好坚持使用目标平台的设置。

本练习假定您已经安装了CentOS 6.7(最小服务器选项)。

陷阱2

在研究中,您可能会遇到以下错误。 我包括他们,希望搜索引擎机器人将您带到此博客,以便您省去一些麻烦。

checking whether the C compiler works… configure: error: in `/root/downloads/libzmq-master’:
configure: error: cannot run C compiled programs.
If you meant to cross compile, use `–host’.
libsodium is not installed
src/.libs/libzmq.so: undefined reference to `crypto_secretbox_open'
src/.libs/libzmq.so: undefined reference to `crypto_box_beforenm'
src/.libs/libzmq.so: undefined reference to `crypto_secretbox'
src/.libs/libzmq.so: undefined reference to `crypto_box'
src/.libs/libzmq.so: undefined reference to `crypto_box_keypair'
src/.libs/libzmq.so: undefined reference to `sodium_init'
src/.libs/libzmq.so: undefined reference to `crypto_box_open'
src/.libs/libzmq.so: undefined reference to `randombytes_close'
src/.libs/libzmq.so: undefined reference to `crypto_box_open_afternm'
src/.libs/libzmq.so: undefined reference to `randombytes'
src/.libs/libzmq.so: undefined reference to `crypto_box_afternm'
collect2: ld returned 1 exit status
make[1]: *** [tools/curve_keygen] Error 1
make[1]: Leaving directory `/root/downloads/libzmq-<wbr />master'
make: *** [all-recursive] Error 1
GLIB 2.14 not found

以下步骤为您提供了逐步指导,以指导您编译标准ZeroMQ HelloWorld Server和HelloWorld Client。

# Steps to a working ZeroMQ 4+ code on CentOS67

# Login as root or make sure you have sudo access
# The following instructions assume you are logged in as "root"
# Assumes the following path /root/downloads
mkdir download
cd download

# ZeroMQ 4+ requires libsodium 
# You also need a C compiler

# Pre-requisites
yum update
# Gets your system upto date with the latest updates

yum install libtool gcc-c++ glib*
# This installs autoconf, automake, cloog-ppl, cpp, gcc, mpfr, ppl
yum groupinstall "development tools"



# Let us install and build libsodium
wget https://download.libsodium.org/libsodium/releases/libsodium-1.0.3.tar.gz
tar -xvf libsodium-1.0.3.tar.gz
cd libsodium-1.0.3
./configure
make clean
make
make install
# libsodium libraries are now installed under /usr/local/lib directory
# Next we need to tell libzmq and other development code where to find these libraries

# Add the following exports defining the following environmental libraries
# Edit the root users .bashrc file
vim /root/.bashrc
# Add the following
#-----
export sodium_CFLAGS="-I/usr/local/include"
export sodium_LIBS="-L/usr/local/lib"
export CPATH=/usr/local/include
export LIBRARY_PATH=/usr/local/lib
export LD_LIBRARY_PATH=/usr/local/lib
export LD_RUN_PATH=/usr/local/lib
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
export CFLAGS=$(pkg-config --cflags libsodium)
export LDFLAGS=$(pkg-config --libs libsodium)
#-----

# Reinitialize settings under .bashrc
source ~/.bashrc

# Add libsodium to ldconfig 
echo '/usr/local/lib' > tee -a /etc/ld.so.conf.d/libsodium.conf

# Download the latest lizmq from the GIT repository
cd /root/downloads
wget https://github.com/zeromq/libzmq/archive/master.zip
unzip master.zip
cd libzmq-master

# Lets begin building it
# Generate the configure script from template
./autogen.sh
./configure
make clean
make
make install

# ZeroMQ libraries are installed in /usr/local/lib path
# Need to add the libraries to ldconfig so that they can be
# statically linked in C code
# Since ZMQ is installed in the same path as libsodium,
# we do not need to add another path into /etc/ld.so.conf.d/*.conf
# we just need to reload the "ldconfig"
ldconfig

# Let try compiling and testing a sample code
mkdir /root/downloads/zmqtest
cd /root/downloads/zmqtest

# vim helloserver.c
# Copy hwserver code from the following url:
wget https://github.com/imatix/zguide/raw/master/examples/C/hwserver.c

# Copy hwclient code from the following url:
wget https://github.com/imatix/zguide/raw/master/examples/C/hwclient.c

# Compile hwserver 
gcc hwserver.c -o hwserver -lzmq
gcc hwclient.c -o hwclient -lzmq

# Open two SSH terminals to /root/downloads/zmqtest
# Run hello-world server in terminal #1
# Run hello-world client in terminal #2

# If it runs, you're all set to go
# Please link me from your blog/social places so that others can easily find this article
# Also provide me with feedback so that I can ammend this guide for others

谢谢您的欢呼!

翻译自: https://www.javacodegeeks.com/2015/09/how-to-configure-and-install-zeromq-libsodium-on-centos-6-7.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值