1. 程式人生 > >Ubuntu虛擬機安裝evpp開源庫說明

Ubuntu虛擬機安裝evpp開源庫說明

trying 127.0.0.1 style deb 執行文件 apt linux w libboost 使用

Ubuntu虛擬機安裝開源庫說明:

EVPP為奇虎360基於libevent開發的現代化的支持C++11特性的高性能網絡庫,自帶TCP/UDP/HTTP等協議的異步非阻塞式的服務器和客戶端庫。擁有如下特性:

* 現代版的C++11接口
* 非阻塞異步接口都是C++11的functional/bind形式的回調仿函數(不是libevent中的C風格的函數指針)
* 非阻塞純異步多線程TCP服務器/客戶端
* 非阻塞純異步多線程HTTP服務器/客戶端
* 非阻塞純異步多線程UDP服務器
* 支持多進程模式
* 優秀的跨平臺特性和高性能(繼承自libevent的優點)

evpp的編譯需要依賴如下動態庫, 分別介紹如下:

libevent glog gtest gflags boost evpp

linevent:
1、window訪問: http://libevent.org/libevent-2.0.22.tar.gz, 拷貝到linux機器上
(或者了Linux wget http://libevent.org/libevent-2.0.22.tar.gz)
2、tar -zxvf libevent-2.0.22-stable.tzr.gz
3、cd libevent-2.0.22-stable
4、./configure --prefix=/usr
5、make
6、sudo make install
7、檢查是否安裝成功, ls -al /usr/lib | grep libevent

glog:


1、下載源碼: git clone https://github.com/google/glog
(git clone下載慢可以參考:
ubuntu上解決訪問github慢的方法:
1、進入終端命令行模式,輸入sudo vi /etc/hosts
2、輸入i進入編輯命令,英文輸入法輸入G,vim編輯器跳到hosts文件的最後一行
3、用瀏覽器訪問 IPAddress.com 使用 IP Lookup 工具獲得github.com和github.global.ssl.fastly.net域名的ip地址
4、在vi打開的hosts文件中添加如下格式:
192.30.253.112 github.com

151.101.44.249 github.global.ssl.fastly.net
5、esc退出編輯模式,輸入:wq,保存hosts文件,修改hosts結束
6、更新DNS緩存,輸入sudo /etc/init.d/networking restart
)
2、配置: sudo apt-get install autoconf automake libtool
3、編譯安裝:
進入源碼根目錄(glog文件夾)
./autogen.sh
./configure
make -j 24
sudo make install

gflags:
1、下載源碼:git clone https://github.com/gflags/gflags
2、編譯安裝:
進入源碼目錄(即gflags文件夾)
cmake .
make -j 24
sudo make install

gtest:
1、安裝源代碼:sudo apt-get install libgtest-dev
2、編譯源代碼:
cd /usr/src/gtest
$ sudo mkdir build
$ cd build
$ sudo cmake ..
$ sudo make
3、拷貝生成的庫到系統目錄下(將生成的libgtest.a 和 libgtest_main.a 拷貝到系統的lib路徑下.):
$ sudo cp libgtest*.a /usr/local/lib

boost:
使用apt-get直接進行安裝: sudo apt-get install libboost-dev
(這個安裝成功了,但是使用失敗,應該是包不全,沒有boost_system與boost_thread等)

1、下載安裝包源碼:
https://www.boost.org/users/download/
2、解壓編譯:
tar -zxvf boost_1_67_0.tar.gz
cd boost_1_67_0
./bootstrap.sh(不用加 --prefix=dir,會默認安裝到/usr/local/目錄下,成功會生成b2可執行文件)

sudo ./b2 install(時間較長,20分鐘)

evpp:
1、下載源碼與子模塊源碼:
$ git clone https://github.com/Qihoo360/evpp
$ cd evpp
$ git submodule update --init --recursive
2、編譯源碼:
$ mkdir -p build && cd build
$ cmake -DCMAKE_BUILD_TYPE=Debug ..
$ make -j(不需要並行編譯,直接make就好了,我用make -j的時候虛擬機掛了兩次)
3、運行用例:
$ make test(這個會跑unittest用例,需要3~5分鐘後)
$ cd evpp/build/bin
* Run a HTTP client example:

  $ ./example_http_client_request01
WARNING: Logging before InitGoogleLogging() is written to STDERR
I0306 11:45:09.464159 13230 inner_pre.cc:37] ignore SIGPIPE
I0306 11:45:09.464896 13230 client01.cc:30] Do http request
I0306 11:45:09.493073 13231 client01.cc:14] http_code=200 [ok]
I0306 11:45:09.493124 13231 client01.cc:16] HTTP HEADER Connection=close
I0306 11:45:09.493242 13231 event_loop.cc:103] EventLoop is stopping now, tid=140722561709824
I0306 11:45:09.993921 13231 event_loop.cc:93] EventLoop stopped, tid: 140722561709824
I0306 11:45:09.994107 13230 client01.cc:38] EventLoopThread stopped.

*** Run a HTTP server example:
  $ ./example_httpecho
WARNING: Logging before InitGoogleLogging() is written to STDERR
I0306 12:15:31.703927 21228 inner_pre.cc:37] ignore SIGPIPE
I0306 12:15:31.706221 21228 http_server.cc:99] http server is running
*** And in another console(模擬客戶端,要在服務器運行的時候):
  $ curl "http://127.0.0.1:9009/echo" -d "Hello, world"
  ello, world

*Run a TCP echo server example:
  $ ./example_tcpecho
* And in another console(模擬客戶端,要在服務器運行的時候):
  $ telnet 127.0.0.1 9099
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is ‘^]‘.

Ubuntu虛擬機安裝evpp開源庫說明