NEV_SDK开发环境部署手册

根据项目开发需求,要在MEC服务器上部署如下内容:Nginx、Nginx push stream module、Jason CPP、Spawn-fcgi、libfcgi、Redis、Hiredis、Boost、SCTPlib、Asn1c. 记录下部署过程和遇到的一些坑,以备后用。本文所有包源目录为/usr/src.

1. 安装Nginx依赖包

安装Nginx需要先安装openssl、zlib、pcre这几个依赖包。若未安装参照如下步骤:

(1)Openssl:Openssl用于SSL功能。

  下载openssl包:http://www.openssl.org/source/

  • 解压:# tar -zxvf openssl-1.0.2f.tar.gz
  • 配置:# cd /usr/src/openssl-1.0.2f
  •    # ./configure
  • 编译:# make
  • 安装:# make install

(2)zlib:zlib库用于gzip模块.

  • 下载:http://www.zlib.net/
  • 解压:# xz -d zlib-1.2.8.tar.xz   # tar -xvf zlib-1.2.8.tar
  • 配置:./configure
  • 编译:# make
  • 安装:# make install

(3)pcre:pcre库用于HTTP rewrite模块.

  安装pcre-8.38版本,prce2-10.20最新版本后,在后续编译nginx时会出现找不到pcre.h文件的错误。

  • 下载:http://www.pcre.org/
  • 解压:# tar -zxvf pcre-8.38
  • 配置:# cd /usr/src/pcre-8.38      # ./configure
  • 编译:# make 
  • 安装:# make install

2. 安装Nginx及其订阅发布模块:

     由于本项目开发需要订阅发布功能,需要NNginx的push stream 模块支持,所以在建立Nginx时候要将这个模块加进去一起编译。

  nginx-push-stream-module使用http来实现连接管道。主要用于订阅发布模块的即时消息的推送。

注:建议在安装nginx时一起配置push-stream-module.

(1)下载:

  a. 下载Nginx源码包:http://nginx.org/

  b. 下载nginx-push-stream-module:

    https://github.com/wandenberg/nginx-push-stream-module/releases 

(2)解压:

  # tar –zxvf nginx-1.9.9.tar.gz

  #   tar –zxvf nginx-push-stream-module-0.5.1.tar.gz

 

(3)配置:

  # cd /usr/src/nginx-1.9.9

 

  #  ./ configure --with-pcre=/usr/local/pcre8.38 --add-module=/usr/src/nginx-push-stream-module-0.5.1

(4)编译:# make

(5)安装:# make install

(6)测试:检查服务是否安装成功:正确应返回版本信息。

    # /usr/local/nginx/sbin/nginx –v

(7)配置:修改.conf文件。

  • 查看端口是否被占用:nginx默认绑定80端口。

    # netstat –an |grep 80

   发现80端口已被占用,需要修改下。

  • 修改绑定端口号:

    # cd /usr/local/nginx/conf

    # vi nginx.conf

  • 将server部分的端口号修改为:listen  8080

 (8) 测试配置:

  #/usr/src/nginx/sbin/nginx -c /usr/src/nginx-push-stream-module-0.5.1/misc/nginx.conf -t 

     若出现错误:[emerg] invaild event type "poll" in...../misc/nginx.conf:19 .......test failed时,将push-stream-module/misc目录下的nginx.conf文件中的poll注释掉,然后重新测试。

(9)启动或重启Nginx服务:

  # /usr/local/nginx/sbin/nginx             //启动

  # /usr/local/nginx/sbin/nginx -s reload   //重启

(10)打开浏览器,输入nginx服务器的IP:8080,若返回如下"welcome to nginx!" 则表示安装并运行成功.          

3. 安装JSON CPP

     jsonCPP有两个系列的版本:

  0.y.z:用于旧版本编译器。

  1.y.z:支持 C++11。

  系统中gcc版本为4.8.1,为支持最新标准库,此处安装配置1.6.5版本。

(1)前提条件:

 a. 安装Python:略。

 b. 安装scons:

Scons是一个Python写的自动化构建工具,类似于GNU make. 也可以使用Cmake。

本次使用scons来编译Json cpp。

  • 下载Scons:http://www.scons.org/
  • 解压:# tar -zxvf scons-2.4.1.tar.gz
  • 设置环境变量:

  # export MYSCONS=/usr/local/scons-2.4.1/               //scons解压目录

  # export SCONS_LIB_DIR=/usr/local/scons-2.4.1/engine    //scons目录下的engine目录.

(2)下载json源码包:

    https://github.com/open-source-parsers/jsoncpp/releases

 

 

(3)

解压:

  # tar –zxvf  jasoncpp-1.6.5.tar.gz

(4)进入 jsoncpp解压目录,执行如下命令:  

  #  python $MYSCONS/script/scons platform=linux-gcc

(5)将在如下目录中生成两个文件:

  # /usr/local/jsoncpp-1.6.5/libs/linux-gcc-4.8.1

  libjson_linux-gcc-4.8,1_libmt.a 和libjson_linux-gcc-4.8.1_libmt.so复制到项目目录中即可。

4. 安装Spawn-fcgi:

Spawn-fcgi是lighttpd的一部分。

(1)下载lighttpd:http://www.lighttpd.net/download/

  • 解压:# tar –zxvf lighttpd-1.4.39.tar.gz
  •  配置:

    # cd /usr/src/lighttpd-1.4.39

    # ./configure 

  • 编译:# make
  • 安装:# make install
  • 初始化脚本:

    # sed -e 's/FOO/lighttpd/g' doc/initscripts/rc.lighttpd.redhat > /etc/init.d/lighttpd

(2)安装Spawn-fcgi:

    # cd /usr/src/spawn-fcgi-1.6.4/

   # ./configure

  • 编译:# make
  • 安装:# make install

    安装在/usr/local/bin/spawn-fcgi目录下。

(3)测试:# spawn-fcgi –v 

(4)复制spawn-fcgi 文件到/usr/local/nginx/sbin:

       # cp spawn-fcgi /usr/local/nginx/sbin/

5. Fastcgi:

(1)下载:http://www.fastcgi.com/drupal/node/5/fcgi.tar.gz

(2)解压:tar -zxvf fcgi.tar.gz

(3)配置:# cd /usr/src/fcgi/

      # ./configure

(4)编译:# make      (5) 安装:# make install

报错解决方法:在源码目录下/include/fcgio.h文件中加上#include <cstdio> ,再重新编译。

(4)安装: # make install

(5)写一个测试代码,然后编译测试生成fcgi程序:

   # g++ -o test.cgi te.c -L /usr/local/lib/ -lfcgi

(6)启动Spawn-fcgi: # spawn-fcgi  -a 127.0.0.1 -p 7000 -u www  -f 

(7)修改配置nginx.conf文件:

      添加如下内容:

location ~ .cgi$
  {
        fastcgi_pass  127.0.0.1:7000;
        fastcgi_index index.cgi;
        fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
        include fastcgi_params;
    }

(8)重启nginx服务:# /usr/local/nginx/sbin/nginx –s reload

6. 安装libfcgi:

(1)下载:https://github.com/toshic/libfcgi

(2)解压:# tar –zxvf libfcgi-2.4.0-8.3 

(3)配置:# cd /usr/src/libfcgi-2.4.0-8.3

      # ./configure

(4)编译: # make

  编译错误解决:在/include/fcgio.h文件中加上 #include <cstdio>

(5)重新配置编译:   # ./configure        # make 

(5)安装:# make install 

7. Redis:

(1)下载:http://download.redis.io/releases/redis-3.0.6.tar.gz

(2)解压:# tar –zxvf redis-3.0.6.tar.gz

(3)编译:# make      

       # make test

(4)安装: # make install

(5)运行:

  # redis-server        或 src /redis-server            //启动服务端

     # redis-cli    //启动客户端

(6)warning解决:启动服务后可能会有几个warning。

  • warning:overcommit_memory

  Overcommit_memory用于设置内存分配测量。位置/proc/sys/vm/overcommit_memory

   可选值:0、1、2 。

  0:检查是否有足够可用内存给应用进程使用。若有,则允许内存申请;若没有,内存申请失败,并返回给应用。

  1:允许分配所有物理内存,而不管当前内存状态。

  3:允许分配超过所有物理内存和swap总和的内存。

  比较优化的内存分配策略应该设置为 1(表示内核允许分配所有的物理内存,而不管当前的内存状态如何。overcommit的策略通过vm.overcommit_memory设置. 

  解决方法: # echo “vm.overcommit_memory=1” > /etc/sysctl.conf

                    # reboot

  • warning:The TCP backlog setting of 511 cannot be enforced 

  解决方法:#echo 511 > /proc/sys/net/core/somaxconn

(7)重启redis服务端。

(8)检查是否启动成功:

   # ps –ef |grep redis 

(9)修改配置文件(可选):# vi /usr/local/redis-3.0.6/redis.conf

  a. 将slavof  部分的masterip 、masterport修改为redis 服务端的IP地址和端口号。

  b. 修改redis后台运行:默认daemonize 为no,修改为daemonize yes

  c. 端口号:默认端口号为6379.

8. Hiredis:

(1)下载:https://github.com/redis/hiredis/releases 

(2)解压:# tar –zxvf hiredis-0.13.3.tar.gz

(3)编译:# make

(4)安装:# make install 

将生成的.so文件复制到/usr/local/lib和/usr/local/include目录。

(5)使用:代码中include <hiredis/hiredis.h>,在编译时选项加上 –lhiredis

9. 安装Boost:

(1)下载源码包:http://www.boost.org/users/download/

(2)解压:# tar –zxvf boost_1_60_0.tar.gz

(3)编译bjam:

  • 运行bootstrp.sh脚本,生成bjam文件和b2文件。

    # cd /usr/local/boost_1_60_0/

    # ./bootstrap.sh

  • 运行bjam文件:运行b2脚本文件开始编译。

        # ./b2 

(4)安装:#./b2 install

(5)更新动态链接库:# ldconfig

(6)使用:代码中要include<boost>头文件

10. 安装SCTPlib库:

(1)安装依赖包:llibffi

  下载:https://www.sourceware.org/libffi/

  • 解压:# tar –zxvf libffi-3.2.1.tar.gz
  • 配置:# cd /usr/src/libffi-3.2.1
  •         # ./configure
  • 编译:# make
  • 安装:# make install

(2)安装依赖包:glib

  • 下载:http://ftp.acc.umu.se/pub/GNOME/sources/glib/
  • 解压:# xz –d glib-2.47.4.tar.xz

          # tar –xvf glib-2.47.tar

  • 配置:

    # cd /glib-2.47.4/

    # ./ configure        或       # ./ configure  --prefix=/usr    

    //指定安装目录到/usr下,库文件就会放在/usr/lib中,sctplib就可以找到glib。

  • 若提示找不到libffi,解决方法:配置环境变量

  # export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

  • 重新配置:# ./configurre
  • 编译: # make
  • 安装:# make install

(3)下载:sctplib-1.0.15:  http://www.sctp.de/sctp-download.html

(4)解压:# tar –zxvf stcplib-1.0.11

(5)配置:

    # cd  /usr/local/sctplib-1.0.11/

    # ./ configure

(6)出错:出现错误找不到GLIB库。

   配置glib环境变量:

  # export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig           //glib-2.0.pc的目录

  # export LD_LIBRARY_PATH=/usr/local/lib                               //glib-2.0目录

(7)使用pkg-config  --modversion glib-2.0 测试glib版本。

  重新配置:#./ configure

(8)编译:# make

(9)安装:# make install

11. Asn1c:

(1)下载:http://lionet.info/asn1c/download.html

(2)解压:# tar –zxvf  asn1c-0.9.27.tar.gz

(3)配置,生成Makefile:

   # cd /usr/local/asn1c-0.9.27/

   # ./configure  

(4)编译:# make

(5)安装:# make install

(6)测试:# asn1c -v

原文地址:https://www.cnblogs.com/kevinji/p/5198634.html