libevent linux( libevent的简单更新)
各位老铁们,大家好,今天由我来为大家分享libevent linux,以及 libevent的简单更新的相关问题知识,希望对大家有所帮助。如果可以帮助到大家,还望关注收藏下本站,您的支持是我们最大的动力,谢谢大家了哈,下面我们开始吧!
libevent-2.0.22-stable.gz怎么安装
在Linux系统中进行FastDFS软件的安装配置,方法的过程中是很复杂的,所以如果不是专业的电脑高手可能是没有办法整理出来,所以为了方便网友们更好的了解这个软件的安装,一下就是详细的过程,大家一起来看看吧!第一步:安装FastDFS
1.解压 FastDFS_v4.07.tar.gz==>FastDFS
2. cd FastDFS==>vim make.sh修改以下内容
TARGET_PREFIX=/usr/local/fdfs
TARGET_CONF_PATH=/usr/local/fdfs/conf
mkdir-p/usr/local/fdfs
mkdir-p/usr/local/fdfs/conf修改
if ["$uname"="Linux" ]; then if ["$WITH_LINUX_SERVICE"="1" ]; then if [!-d$TARGET_CONF_PATH ]; then mkdir-p$TARGET_CONF_PATH cp-f conf/tracker.conf$TARGET_CONF_PATH cp-f conf/storage.conf$TARGET_CONF_PATH cp-f conf/client.conf$TARGET_CONF_PATH cp-f conf/http.conf$TARGET_CONF_PATH cp-f conf/mime.types$TARGET_CONF_PATH fi cp-f init.d/fdfs_trackerd/etc/rc.d/init.d/ cp-f init.d/fdfs_storaged/etc/rc.d/init.d//sbin/chkconfig--add fdfs_trackerd/sbin/chkconfig--add fdfs_storaged fi fi第二步:安装libevent-2.0.19-stable.tar.gz
1.解压 libevent-2.0.19-stable.tar.gz==>libevent-2.0.19-stable
2.进入libevent-2.0.19-stable安装./configure--prefix=/usr/local/libevent
make
make install
3.添加软连接
ln-s/usr/local/libevent/lib/libevent-2.0.so.5/usr/lib/libevent-2.0.so.5
ln-s/usr/local/libevent/lib/libevent-2.0.so.5/usr/lib64/libevent-2.0.so.5
ln-s/usr/local/libevent/lib/libevent-2.0.so.5/lib64/libevent-2.0.so.5
ln-s/usr/local/libevent/lib/libevent-2.0.so.5/lib/libevent-2.0.so.5
ln-s/usr/local/libevent/lib/libevent-2.0.so.5/usr/local/lib64/libevent-2.0.so.5
ln-s/usr/local/libevent/lib/libevent-2.0.so.5/usr/local/lib/libevent-2.0.so.5第三步:安装FastDFS./make.sh C_INCLUDE_PATH=/usr/local/libevent/include LIBRARY_PATH=/usr/local/libevent/lib./make.sh install第四步:如果/usr/local/fastdfs/conf没有fdfs_trackerd和fdfs_storaged这两个文件,就从/FastDFS/tracker和FastDFS/storage/目录下复制过去第五步:修改配置
mkdir-p/home/softinstall/data/tracker
1.修改 tracker.conf
base_path=/home/softinstall/data/tracker
bind_addr=192.168.9.169
1.1修改storage_ids.conf
100001 group1 192.168.9.169
2.启动tracker./fdfs_trackerd../conf/tracker.conf查看22122端口是否启动起来第六步:配置storage
mkdir-p/home/softinstall/data/store
mkdir-p/home/softinstall/data/store/store0
mkdir-p/home/softinstall/data/store/store1
mkdir-p/home/softinstall/data/store/store2
1.修改storage.conf
base_path=/home/softinstall/data/store
store_path_count=3
store_path0=/home/softinstall/data/store/store0
store_path1=/home/softinstall/data/store/store1
store_path2=/home/softinstall/data/store/store2
tracker_server=192.168.9.169:22122#限6*6=36个目录默认256*256
subdir_count_per_path=6
2.启动storage./fdfs_storaged../conf/storage.conf查看23000端口是否启动第七步:安装nginx+fastdfs模块
1.安装pcre-8.32进入pcre-8.32./configure
make
make install安装如果有问题缺省某些包,可以执行:
yum groupinstall"Development Tools"第八步:解压fastdfs-nginx-module_v1.15.tar.gz和 nginx-1.4.2.tar.gz
1.进入 fastdfs-nginx-module_v1.15/src
vim fastdfs-nginx-module_v1.15/src/config修改成以下内容
ngx_addon_name=ngx_http_fastdfs_module
HTTP_MODULES="$HTTP_MODULES ngx_http_fastdfs_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS$ngx_addon_dir/ngx_http_fastdfs_module.c"
CORE_INCS="$CORE_INCS/usr/local/fdfs/include/fastdfs/usr/local/fdfs/include/fastcommon/"
CORE_LIBS="$CORE_LIBS-L/usr/local/fdfs/lib-lfastcommon-lfdfsclient"
CFLAGS="$CFLAGS-D_FILE_OFFSET_BITS=64-DFDFS_OUTPUT_CHUNK_SIZE='256*1024'-DFDFS_MOD_CONF_FILENAME='\"/usr/local/fdfs/conf/mod_fastdfs.conf\"'"
2.安装进入nginx-1.4.2目录./configure--prefix=/home/softinstall/nginx/nginx-fastdfs-install--with-pcre=/home/softinstall/nginx/pcre-8.32--add-module=/home/softinstall/nginx/fastdfs-nginx-module/src安装中如果有问题可以执行安装以下包:yum-y install gcc gcc-c++ zlib-devel openssl-devel
3.配置nginx.conf进入nginx-fastdfs-install/conf
vim nginx.conf配置以下内容
location/M00{
root/home/softinstall/data/store/store0/data;
ngx_fastdfs_module;}
location/M01{
root/home/softinstall/data/store/store1/data;
ngx_fastdfs_module;}
location/M02{
root/home/softinstall/data/store/store2/data;
ngx_fastdfs_module;}
4.配置mod_fastdfs.conf
mkdir-p/home/softinstall/data/nginx_mod进入/usr/local/fdfs/conf目录
vim mod_fastdfs.conf
base_path=/home/softinstall/data/nginx_mod
tracker_server=192.168.9.169:22122
store_path_count=3
store_path0=/home/softinstall/data/store/store0
store_path1=/home/softinstall/data/store/store1
store_path2=/home/softinstall/data/store/store2
5.启动nginx进入/home/softinstall/nginx/nginx-fastdfs-install/sbin./nginx如果启动找不到
error while loading shared libraries: libfdfsclient.so: cannot open shared object file: No such file or directory
error while loading shared libraries: libfastcommon.so: cannot open shared object file: No such file or directory请使用以下软连接
ln-s/usr/local/fdfs/lib/libfastcommon.so/usr/lib/libfastcommon.so
ln-s/usr/local/fdfs/lib/libfastcommon.so/usr/lib64/libfastcommon.so
ln-s/usr/local/fdfs/lib/libfdfsclient.so/usr/lib64/libfdfsclient.so
ln-s/usr/local/fdfs/lib/libfdfsclient.so/usr/lib/libfdfsclient.so==========================fastDHT================================【第一步:】安装 Berkley DB【1.】 tar-zxvf db-4.7.25.tar.gz进入 db-4.7.25/build_unix../dist/configure--prefix=/usr【第二步:】安装FastDHT
mkdir-p/usr/local/fdht
mkdir-p/usr/local/fdht/conf
1. tar-zxvf FastDHT_v1.23.tar.gz进入 FastDHT_v1.23
vim make.sh修改
TARGET_PREFIX=/usr/local/fdht
TARGET_CONF_PATH=/usr/local/fdht/conf
if ["$1"="install" ]; then cd.. cp-f restart.sh$TARGET_PREFIX/bin cp-f stop.sh$TARGET_PREFIX/bin if ["$uname"="Linux" ]; then if ["$WITH_LINUX_SERVICE"="1" ]; then if [!-d$TARGET_CONF_PATH ]; then mkdir-p$TARGET_CONF_PATH cp-f conf/fdhtd.conf$TARGET_CONF_PATH cp-f conf/fdht_servers.conf$TARGET_CONF_PATH cp-f conf/fdht_client.conf$TARGET_CONF_PATH fi cp-f init.d/fdhtd/etc/rc.d/init.d//sbin/chkconfig--add fdhtd fi fi
fi【2.】安装./make.sh------------------------------------------------------------------------------如果出现 global.h:18:19: error: event.h: No such file or directory进入/home/softinstall/fastdfs/libevent-2.0.19-stable然后执行./configure--prefix=/usr
make
make install---------------------------------------------------------------------------------./make.sh install【3.】配置fdht【3.1】 vim/usr/local/fdht/conf/fdhtd.conf
port=11411
bash_path=/home/softinstall/data/fastdht
cache_size= 32MB
store_sub_keys=true
use_storage_id=true#include/usr/local/fdht/conf/fdht_servers.conf(本行前有#表示打开,如果想关闭此选项,则应该为##开头)【3.2】 vim/usr/local/fdht/conf/fdht_server.conf
group_count= 1
group0= 192.168.9.165:11411【3.3】 vim/usr/local/fdht/conf/fdht_client.conf
keep_alive=1(本选项关联 storaged.conf文件)
base_path=/home/softinstall/data/fastdht#include/usr/local/fdht/conf/fdht_servers.conf【3.4】配置FastDFS的 storaged.conf文件
vi storaged.conf(默认位置:/usr/local/fdfs/conf/storaged.conf)
check_file_duplicate=1本配置项解释:是否检测上传文件已经存在。如果已经存在,则不存在文件内容,建立一个索引链接以节省磁盘空间
key_namespace=FastDFS本配置项解释:当上个参数设定为1时,在FastDHT中的命名空间
keep_alive=1本配置项解释:长连接配置选项,如果为0则为短连接 1为长连接#include/usr/local/fdht/conf/fdht_servers.conf本配置项解释:可以通过#include filename方式来加载 FastDHT servers的配置【3.5】===========================总体启动流程======================================启动tracker/usr/local/fdfs/bin/fdfs_trackerd/usr/local/fdfs/conf/tracker.conf停止tracker/usr/local/fdfs/bin/stop.sh/usr/local/fdfs/conf/tracker.conf启动storage/usr/local/fdfs/bin/fdfs_storaged/usr/local/fdfs/conf/storage.conf停止storage/usr/local/fdfs/bin/stop.sh/usr/local/fdfs/conf/storage.conf启动nginx/home/softinstall/nginx/nginx-fastdfs-install/sbin/nginx启动/usr/local/fdht/bin/fdhtd/usr/local/fdht/conf/fdhtd.conf停止/usr/local/fdht/bin/stop.sh/usr/local/fdht/conf/fdhtd.conf测试是否有错误:/usr/local/fdht/bin/fdht_test/usr/local/fdht/conf/fdht_client.conf=================================================================
如何在linux下实现event事件机制
一、Libevent简介
libevent是一个基于事件触发的网络库,适用于windows、linux、bsd等多种平台,内部使用select、epoll、kqueue等系统调用管理事件机制。
特点:
事件驱动,高性能;
轻量级,专注于网络,不如ACE那么臃肿庞大,只提供了简单的网络API的封装,线程池,内存池,递归锁等均需要自己实现;
开放源码,代码相当精炼、易读;
跨平台,支持Windows、Linux、BSD和Mac OS;
支持多种I/O多路复用技术(epoll、poll、dev/poll、select和kqueue等),在不同的操作系统下,做了多路复用模型的抽象,可以选择使用不同的模型,通过事件函数提供服务;
支持I/O,定时器和信号等事件;
采用Reactor模式;
二、源码组织结构
Libevent的源代码虽然都在一层文件夹下面,但是其代码分类还是相当清晰的,主要可分为头文件、内部使用的头文件、辅助功能函数、日志、libevent框架、对系统I/O多路复用机制的封装、信号管理、定时事件管理、缓冲区管理、基本数据结构和基于libevent的两个实用库等几个部分,有些部分可能就是一个源文件。
1)头文件
主要就是event.h:事件宏定义、接口函数声明,主要结构体event的声明;
2)内部头文件
xxx-internal.h:内部数据结构和函数,对外不可见,以达到信息隐藏的目的;
3)libevent框架
event.c:event整体框架的代码实现;
4)对系统I/O多路复用机制的封装
epoll.c:对epoll的封装;
select.c:对select的封装;
devpoll.c:对dev/poll的封装;
kqueue.c:对kqueue的封装;
5)定时事件管理
min-heap.h:其实就是一个以时间作为key的小根堆结构;
6)信号管理
signal.c:对信号事件的处理;
7)辅助功能函数
evutil.h和evutil.c:一些辅助功能函数,包括创建socket pair和一些时间操作函数:加、减和比较等。
8)日志
log.h和log.c:log日志函数
9)缓冲区管理
evbuffer.c和buffer.c:libevent对缓冲区的封装;
10)基本数据结构
compat/sys下的两个源文件:queue.h是libevent基本数据结构的实现,包括链表,双向链表,队列等;_libevent_time.h:一些用于时间操作的结构体定义、函数和宏定义;
11)实用网络库
http和evdns:是基于libevent实现的http服务器和异步dns查询库;
Linux下怎么在send的时候,Bad file descriptor
因为是从windows移植到 Linux,而且用到libevent库,很多东西都要改其中有这么一条:
evutil_socketpair(AF_INET,SOCK_STREAM,0,fd);在Linux下如果运行 send(fd[0],"",1,0)总是返回-1,perror(),返回Bad filedescriptor网上查了一下:可能是因为文件描述符错误,或者关闭等原因于是去查libevent的utils.h头文件在Linux下evutil_sockepair()实际调用的是Linux系统函数socketpair()又去Linux man socketpair人家说了,在Linux下socketpair传入的只能是AF_UNIX,OK,找到了问题把原来的evutil_socketpair(AF_INET,SOCK_STREAM,0,fd)改为evutil_socketpair(AF_UNIX,SOCK_STREAM,0,fd)正常运行所以排错思路,和查找资料是很重要的能力啊!!!