linux zmq环境配置,zmq安装与使用
Zmq的安装与使用
花了一下午时间来安装使用zmq,终于将程序调通。记录下安装使用过程及遇到的问题
zmq的安装
安装前准备
在安装zeromq之前需要安装libtool, autoconf, automake, uuid-dev, util-linux
具体指令如下
yum install libtool
yum install autoconf
yum install automake
yum install uuid uuid-devel
安装util-linux时我直接下载的源码包,
地址:http://mirrors.oss.org.cn/linux_kernel/util-linux/v2.21/util-linux-2.21.1.tar.gz
下载后解压安装
tar zxvfutil-linux-2.21.1.tar.gz
cd util-linux-2.21.1
./configure
make
sudo make install
sudo ldconfig
1.2 安装zmq
获得zeromq的源码包
wget http://download.zeromq.org/zeromq-2.0.10.tar.gz
如果想获得最新的源码包http://download.zeromq.org/
安装zeromq
tar zxvf zeromq-2.0.10.tar.gz
cd zeromq-2.0.10
./configure
make
sudo make install
sudo ldconfig
1.3 使用python编程,要安装pyzmq
获得pyzmq的源代码
https://pypi.python.org/packages/source/p/pyzmq/
安装
tar zxvf pyzmq-14.4.0.tar.gz
cd pyzmq-14.4.0
python setup.py build
sudo python setup.py install
注意:pyzmq版本要与zeromq版本一致,不然就算安装了pyzmq运行.py脚本时也会报错,我开始时就是遇到了这个问题,报错如下
Traceback (most recent call last):
File "server.py", line 1, in
import zmq
File "/usr/lib64/python2.6/site-packages/zmq/__init__.py", line 26, in
from zmq.utils import initthreads # initialize threads
ImportError: libzmq.so.0: cannot open shared object file: No such file or directory
从字面意思看,是找不到libzmp.so.0文件,查看官方文档,说是因为
I am guessing you are on on Linux. This looks like the error you will see if you don't use rpath or set LD_LIBRARY_PATH.
If you install libzmq to a location other than the default (/usr/local) on Linux, you may need to do one of the following:
·SetLD_LIBRARY_PATHto point to thelibdirectory of ØMQ.
·Build the extension using the--rpathflag:
$ python setup.py build_ext --rpath=/opt/zeromq-dev/lib
于是按照以下方式设置LD_LIBRARY_PATH
[moqian.ydd@r10g04458.sqa.zmf /home/moqian.ydd/tools]
$cd /
vi ~/.bash_profile
添加:
LD_LIBRARY_PATH=/usr/local/lib
export LD_LIBRARY_PATH
即:
PATH=$PATH:$HOME/bin
LD_LIBRARY_PATH=/usr/local/lib
export PATH
export LD_LIBRARY_PATH
然后运行
$ source ~/.bash_profile
设置后,再运行.py脚本,还是报上面的错误。于是重新安装pyzmq的最新版本,问题得到解决
举例
采用zmq的request/reply模式,使用TCP协议
Client端代码
import zmq
context=zmq.Context()
print "connect to server"
socket=context.socket(zmq.REQ)
socket.connect("tcp://localhost:555")
for request in range(1,10):
print "send message ",request,"...."
socket.send("hello")
message=socket.recv()
print "receive reply ",request,"[",message,"]"
Server端代码
import zmq
import time
context=zmq.Context()
socket=context.socket(zmq.REP)
socket.bind("tcp://*:555")
while True:
message=socket.recv()
print "receive request:",message
time.sleep(1)
print "do some work"
socket.send("i am work!")
开两个客户端,先启动server端脚本,然后启动client端脚本,方式如下
sudo pyton server.py
sudo python client.py
Client端运行结果
connect to server
send message 1 ....
receive reply 1 [ i am work! ]
send message 2 ....
receive reply 2 [ i am work! ]
send message 3 ....
receive reply 3 [ i am work! ]
send message 4 ....
receive reply 4 [ i am work! ]
send message 5 ....
receive reply 5 [ i am work! ]
send message 6 ....
receive reply 6 [ i am work! ]
send message 7 ....
receive reply 7 [ i am work! ]
send message 8 ....
receive reply 8 [ i am work! ]
send message 9 ....
receive reply 9 [ i am work! ]
Server端运行结果如下
receive request: hello
do some work
receive request: hello
do some work
receive request: hello
do some work
receive request: hello
do some work
receive request: hello
do some work
receive request: hello
do some work
receive request: hello
do some work
receive request: hello
do some work
receive request: hello
do some work
linux zmq环境配置,zmq安装与使用相关推荐
- Linux网络环境配置 虚拟机网络环境配置
Linux网络环境配置 问题 安装一个Centos 7虚拟机,发现网络无法联通,并且没有IP地址. 发现无法访问外网,并且无法与宿主机相同 使用ifconfig命令查看IP信息,发现没有IP地址 使用 ...
- linux下织梦cms安装环境配置文件,Mac本地环境配置以及安装织梦CMS,增加新的坑解决办法...
Mac上其实已经自带了Apache和PHP,只是默认关闭的.开启一下就行了. Apache配置 apache已经自带了,只需在"终端"输入命令开启下就行了. 开启apache ...
- android 环境配置和安装, Android系统包说明,基本控件,常用代码,ADB 命令行,APK文件确解,小技艺,...
一. 环境配置和安装(Android2.2) 参考文章:这里 1.1 JDK 1.2 SDK 下载地址:http://dl.google.com/android ...
- Pytorch环境配置与安装(Anaconda、Pycharm、Jupyter)
目录 一. Pytorch环境配置与安装 1.1 安装Anaconda 1.2 创建Anaconda虚拟环境 1.3 安装Pytorch 二. Pycharm和Jupyter notebook的安装及 ...
- wamp环境变量配置php,WAMP环境配置-PHP安装
我这次环境配置安装的是php-5.6.25版本! (最近我在反复安装PHP的时候出现了一个问题,httpd.conf加载php5apache2_4.dll出现错误,怎么修改都不行,此时我安装的是VC1 ...
- Linux+javaEE学习笔记之Linux网络环境配置
Linux+javaEE学习笔记之Linux网络环境配置 网络知识简单介绍: Ip地址是:IP地址是IP协议提供的一种统一的地址格式,它为互联网上的每一个网络和每一台主机分配一个逻辑地址,以此来屏蔽物 ...
- 沁恒CH32F103C8T6(二): Linux PlatformIO环境配置, 示例运行和烧录
目录 沁恒CH32F103C8T6(一): Keil5环境配置,示例运行和烧录 沁恒CH32F103C8T6(二): Linux PlatformIO环境配置, 示例运行和烧录 沁恒CH32F103C ...
- 【一生一芯】Chap.1 “一生一芯”实验环境配置| VMware安装Ubuntu20.04 | PA工程配置 | 解决llvm版本问题
[一生一芯]Chap.1 "一生一芯"实验环境配置| VMware安装Ubuntu20.04 | PA工程配置 | 解决llvm版本问题 0. 什么是PA? 1. 安装VMware ...
- linux集成环境包一键安装web环境
linux集成环境包一键安装web环境 linux服务器一般非小型官网或个人网站等,其他中小型或者大型项目都应该是采用的linux服务器,其中的特性大概就是安全吧,不过我一直用linux,很多大神级别 ...
最新文章
- IEA:截止2015年全球太阳能光伏装机累计超228GW
- 获取文件的MIME类型
- 草稿--Windows消息机制
- Python中星号、下画线、斜线含义汇总
- selenium+python自动化测试系列(二):AutoIt工具实现本地文件上传
- VUE之命令行报错:Component template should contain exactly one root element. If you are using v-if on multi
- HDOJ 2013_大二写
- 队列总结(六)DelayQueue
- JPEG编码压缩率调整
- 各大主流社交软件显示ip地址-如何实现ip飘移
- 2021-03-26 大数据技术对企业管理的影响和应用前景分析
- C语言LMS双麦克风消噪算法,基于两个时域LMS算法双麦克风系统分析.doc
- PseudoSeg: Designing Pseudo Labels for Semantic Segmentation阅读笔记
- mysql 备份 发送邮件_mysql 自动备份发邮件 到指定邮箱
- 通过反编译分析骑砍2俘虏招募机制
- 羊吃草-区间端点问题
- Windows环境下OpenSSL下载安装及制作证书
- 翻译连载 |《你不知道的JS》姊妹篇 |《JavaScript 轻量级函数式编程》- 第 4 章:组合函数...
- 三只松鼠,“跑”不动了?
- 58热衷改名背后,就能拯救自身命运吗?