CentOS 7 安装Libevent

2023-09-18 14:28:46

CentOS 7 安装Libevent

1.下载安装包

新版本是libevent-2.1.12-stable.tar.gz。(如果你的系统已经安装了libevent,可以不用安装)
官网:http://www.monkey.org/~provos/libevent/

2.创建目录

# mkdir libevent-stable

3.解压
# tar zxvf libevent-2.1.12-stable.tar.gz

4.进入目录
# cd libevent-2.1.12-stable

5.设置安装路径
# ./configure –prefix=/usr/local/libevent

[root@localhost libevent-2.1.12-stable]# ./configure -prefix=/usr/local/libevent
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether make supports nested variables... (cached) yes
checking whether make supports the include directive... yes (GNU style)
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
提示报错:
configure: error: openssl is a must but can not be found. You should add the directory containing ‘openssl.pc’ to the ‘PKG_CONFIG_PATH’ environment variable, or set ‘CFLAGS’ and ‘LDFLAGS’ directly for openssl, or use `–disable-openssl’ to disable support for openssl encryption

大致报错信息:编译libevent源码,openssl 依赖包在CentOS系统中没有发现openssl, 系统全局变量中缺少PKG_CONFIG_PATH 变量定义,注意PKG_CONFIG_PATH变量必须包含openssl.pc 连接文件。

解决办法:重新安装OpenSSL 替换CentOS 7 默认自带的OpenSSL。

一、查看主机openssl版本信息


1、查看路径
# which openssl
复制
2、查看版本
# openssl version
复制
3、查看CentOS版本
# cat /etc/redhat-release

温馨提示:CentOS 7.6 默认版本:openssl-1.0.2k
 

二、安装Openssl


方法一、下载源码编译安装
访问OpenSSL官网资源,查看是否有最新的版本发布。

官网资源地址:https://www.openssl.org/source

1、解压并切换目录
tar -zxvf openssl-1.0.2j.tar.gz
cd openssl-1.0.2j
复制
2、设定Openssl 安装,( –prefix )参数为欲安装之目录,也就是安装后的档案会出现在该目录下
./config --prefix=/usr/local/openssl
复制
3、执行命令
./config -t
复制
4、执行make、make install,编译Openssl
make & make install

建议再安装一次,使用shared 生成动态连接库。否则无法找到库文件
./config shared --prefix=/usr/local/openssl

make clean

make&& make install
 

5、centos 切换openssl版本
mv /usr/bin/openssl /usr/bin/openssl.bak
mv /usr/include/openssl /usr/include/openssl.bak

ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/openssl/include/openssl /usr/include/openssl

echo "/usr/local/openssl/lib" >> /etc/ld.so.conf

ldconfig -v

ln -s /usr/local/openssl/lib/libssl.so.1.0.0 /usr/lib64/libssl.so.1.0.0
ln -s /usr/local/openssl/lib/libcrypto.so.1.0.0 /usr/lib64/libcrypto.so.1.0.0
 

注意:不能直接删除软链接
CentOS 7 OpenSSL 默认libssl.so.* 和libcrypto.so.* 软连接。
[root@localhost lib]# find / -name libssl.so.1.0.2k
/var/lib/docker/overlay2/30e17a77fc02fa56f32ede3a9d504681b9035fecbd69d5b283d9d2d635bd8b55/diff/usr/lib64/libssl.so.1.0.2k
/var/lib/docker/overlay2/99f62cd325cf4c1fd668b98f95919648b19b0638ff2626250be1c14908f91ee9/diff/usr/lib64/libssl.so.1.0.2k
/usr/lib64/libssl.so.1.0.2k
[root@localhost lib]# find / -name libcrypto.so.1.0.2k
/var/lib/docker/overlay2/30e17a77fc02fa56f32ede3a9d504681b9035fecbd69d5b283d9d2d635bd8b55/diff/usr/lib64/libcrypto.so.1.0.2k
/var/lib/docker/overlay2/99f62cd325cf4c1fd668b98f95919648b19b0638ff2626250be1c14908f91ee9/diff/usr/lib64/libcrypto.so.1.0.2k
/usr/lib64/libcrypto.so.1.0.2k

如需使用新版本开发,则需替换原来的软链接指向,即替换原动态库,进行版本升级。

替换/lib(lib64)和/usr/lib(lib64)和/usr/local/lib(lib64)存在的相应动态库:
[root@localhost lib]# ln -s /usr/local/openssl/lib/libssl.so.1.0.0 /usr/lib64/libssl.so.1.0.0
[root@localhost lib]# ln -s /usr/local/openssl/lib/libcrypto.so.1.0.0 /usr/lib64/libcrypto.so.1.0.0

设置PKG_CONFIG_PATH 全局环境变量

vi /etc/procfile

-- 最后一行添加如下指令:
export PKG_CONFIG_PATH=/usr/local/openssl/lib/pkgconfig

-- 修改后的配置文件生效
source /etc/profilee

再次编译Libevent 源码

5.设置安装路径
# ./configure –prefix=/usr/local/libevent

[root@localhost libevent-2.1.12-stable]# ./configure -prefix=/usr/local/libevent
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether make supports nested variables... (cached) yes
checking whether make supports the include directive... yes (GNU style)
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
*****

 6. 编译并且安装至指定路径地址(/usr/local/libevent)

# make &  make install

root@localhost libevent-2.1.12-stable]# make &  make install
[1] 8554
make  install-am
make  all-am
make[1]: 进入目录“/usr/local/libevent-stable/libevent-2.1.12-stable”
make[1]: 进入目录“/usr/local/libevent-stable/libevent-2.1.12-stable”
  CC       sample/le_proxy-le-proxy.o
  CC       sample/le_proxy-le-proxy.o
  CC       libevent_openssl_la-bufferevent_openssl.lo
mv: 无法获取"sample/.deps/le_proxy-le-proxy.Tpo" 的文件状态(stat): 没有那个文件或目录
make[1]: *** [sample/le_proxy-le-proxy.o] 错误 1
make[1]: 离开目录“/usr/local/libevent-stable/libevent-2.1.12-stable”
make: *** [all] 错误 2
In file included from /usr/local/openssl/include/openssl/ssl.h:152:0,
                 from bufferevent_openssl.c:66:
bufferevent_openssl.c: 在函数‘bufferevent_openssl_socket_new’中:
/usr/local/openssl/include/openssl/bio.h:589:34: 警告:计算出的值未被使用 [-Wunused-value]
 # define BIO_set_close(b,c)      (int)BIO_ctrl(b,BIO_CTRL_SET_CLOSE,(c),NULL)
                                  ^
bufferevent_openssl.c:1466:3: 附注:in expansion of macro ‘BIO_set_close’
   BIO_set_close(bio, 0);
   ^
  CCLD     libevent_openssl.la
  CCLD     sample/le-proxy
  CC       sample/https_client-https-client.o
  CC       sample/https_client-hostcheck.o
******

至此CentOS 7 安装Libevent 网络库结束。

CentOS 7 验证Libevent 框架

前提:使用libevent 源码中的sample 文件夹中的hello-word

NetCat 工具:各种TCP和UDP监听和连接测试用途。 

判断CentOS 7 中是否安装netcat/nc, 执行如下指令:

# nc --help
如果没有netcat 版本信息输出和使用手册输出,你则需要安装netcat/nc 工具,请执行如下指令:

# yum install -y nc

[root@localhost ~]# yum install -y nc
已加载插件:fastestmirror
Determining fastest mirrors
 * base: mirrors.bupt.edu.cn
 * extras: mirrors.ustc.edu.cn
 * updates: mirrors.bupt.edu.cn
base                                                                                                                     | 3.6 kB  00:00:00
docker-ce-stable                                                                                                         | 3.5 kB  00:00:00
extras                                                                                                                   | 2.9 kB  00:00:00
updates                                                                                                                  | 2.9 kB  00:00:00
docker-ce-stable/7/x86_64/primary_db                                                                                     | 117 kB  00:00:26
正在解决依赖关系
--> 正在检查事务
---> 软件包 nmap-ncat.x86_64.2.6.40-19.el7 将被 安装
*****

启动Libevent服务端

[root@localhost sample]# ./hello-world
*** 等待客户端连接 ***

使用NetCat/NC 模拟TCP请求

[root@localhost ~]# nc 192.168.43.10 9995
Hello, World!

LibEvent 服务端输出

[root@localhost sample]# ./hello-world
*** 等待客户端连接 ***
flushed answer

更多推荐

展会动态 | 迪捷软件邀您参加2023世界智能网联汽车大会

*9月18日之前注册的观众免收门票费*由北京市人民政府、工业和信息化部、公安部、交通运输部和中国科学技术协会联合主办的2023世界智能网联汽车大会将于9月21日-24日在北京·中国国际展览中心(顺义馆)举行。论坛背景本届展会以“聚智成势协同向新——迈向商业化应用新征程”为主题,总面积预计5万平方米,参展商200余家。展

java 工程管理系统源码+项目说明+功能描述+前后端分离 + 二次开发

Java版工程项目管理系统SpringCloud+SpringBoot+Mybatis+Vue+ElementUI+前后端分离功能清单如下:首页工作台:待办工作、消息通知、预警信息,点击可进入相应的列表项目进度图表:选择(总体或单个)项目显示1、项目进度图表2、项目信息施工地图:1、展示当前角色权限下能看到的施工地图(

《机器学习实战》笔记

《机器学习实战》笔记一:K近邻KNNK近邻算法概述:工作原理,一般流程;KNN示例:加载数据,分析数据,数据归一化,定义KNN算法,划分数据集,训练测试,使用算法构建完整可用系统;《机器学习实战》笔记二:决策树决策树构造:伪代码,一般流程,信息增益,划分数据集,递归构造决策树;测试和存储决策树:使用决策树执行分类,决策

JDK8特性——Stream API

文章目录集合处理数据的弊端Steam流式思想概述Stream流的获取方式根据Collection获取通过Stream的of方法Stream常用方法介绍forEachcountfilterlimitskipmapsorteddistinctmatchfindmax和minreducemap和reduce的组合mapToI

VScode常用快捷键

添加多个光标alt+鼠标左键Ctrl+Shift+P,F1:显示命令面板Ctrl+P:快速打开Ctrl+Shift+N:新窗口/实例Ctrl+Shift+W:关闭窗口/实例Ctrl+X:剪切行Ctrl+C:复制行ALT+↑/↓:上下移动Shift+Alt+↓/↑:向上/向下复制行Ctrl+Shift+K:删除行Ctrl

【树形 DP】如何从“方向“角度理解树形 DP

题目描述这是LeetCode上的「834.树中距离之和」,难度为「困难」。Tag:「树形DP」、「DFS」、「动态规划」、「树」给定一个无向、连通的树。树中有n个标记为0...n-1的节点以及n-1条边。给定整数n和数组edges,表示树中的节点和之间有一条边。返回长度为n的数组answer,其中answer[i]是树

UML六大关系总结

UML六大关系有:继承、关系、聚合、组合、实现、依赖。分为通过图和代码总结这些关系。1、继承classBird:Animal{}说明:一段都是子类继承父类,在子类的后面用一个冒号表示,冒号后面跟着父类的名字。继承只能继承父类共有和保护的属性或方法,私有的变量或方法不能被子类继承。2、关联ClassPenguin{pri

基于Pandas+余弦相似度+大数据智能护肤品推荐系统——机器学习算法应用(含Python工程源码)+数据集

目录前言总体设计系统整体结构图系统流程图运行环境Python环境Pycharm环境模块实现1.文件读入2.推荐算法1)数据预处理2)计算相似度3)排序并提取产品4)组合推荐算法3.应用模块1)得到最终产品2)筛选过敏物质3)筛选相互禁忌的产品4)输出单品推荐与组合推荐4.测试调用函数系统测试工程源代码下载其它资料下载前

Leetcode.2591 将钱分给最多的儿童

题目链接Leetcode.2591将钱分给最多的儿童rating:1531题目描述给你一个整数moneymoneymoney,表示你总共有的钱数(单位为美元)和另一个整数childrenchildrenchildren,表示你要将钱分配给多少个儿童。你需要按照如下规则分配:所有的钱都必须被分配。每个儿童至少获得111美

第九天:QT入门保姆教程(常用的控件,信号与槽,定时器 QTimer,样式表 Qt Style Sheets,sqlite3数据库,开发板串口)

QT的简介我另外分享了一个qt案例源码包,里面包括文章中的任务源码和一系列常用案例需要的点击此处下载官网www.qt.ioQT是一个基于C++的跨平台的应用程序开发框架跨平台:一次编写,到处编译主流的平台都支持,如:Windows,Linux,Android,MacOS...应用程序:主要用于GUI程序开发,也可以用于

RT-Thread(学习)

RT-Thread是一款完全由国内团队开发维护的嵌入式实时操作系统(RTOS),具有完全的自主知识产权。经过16个年头的沉淀,伴随着物联网的兴起,它正演变成一个功能强大、组件丰富的物联网操作系统。RT-Thread概述RT-Thread,全称是RealTime-Thread,顾名思义,它是一个嵌入式实时多线程操作系统,

热文推荐