OpenWAF 安装

2018-06-06 13:39 更新

名称

OpenWAF 支持源码安装和 Docker 安装

学习、开发、需求变动大、有一定维护能力,建议源码安装
仅使用 OpenWAF 进行防护,建议 Docker 安装

Table of Contents

源码安装

Debian&Ubuntu

  1. 安装OpenWAF依赖

    cd /opt
    apt-get install wget git swig make perl build-essential zlib1g-dev libgeoip-dev libncurses5-dev libreadline-dev -y
    wget https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gz
    wget https://www.openssl.org/source/openssl-1.0.2k.tar.gz
    wget https://openresty.org/download/openresty-1.11.2.2.tar.gz
    tar -zxvf pcre-8.40.tar.gz
    tar -zxvf openssl-1.0.2k.tar.gz
    tar -zxvf openresty-1.11.2.2.tar.gz
    rm -rf pcre-8.40.tar.gz \
           openssl-1.0.2k.tar.gz \
           openresty-1.11.2.2.tar.gz

PS: 
    1.1 OpenSSL 版本要求

    
        OpenResty 要求 OpenSSL 最低版本在 1.0.2e 以上,但 apt-get 安装 openssl 并不满足此版本,因此提供解决方法如下:

        
        方法 1. apt-get 使用 backports 源安装 openssl,如 jessie-backports  
            echo "deb http://mirrors.163.com/debian/ jessie-backports main" >> /etc/apt/sources.list  
            apt-get update  
            apt-get install -t jessie-backports openssl  

            
        方法 2. 下载 openssl 源代码,如 1.0.2k 版本  
            wget -c http://www.openssl.org/source/openssl-1.0.2k.tar.gz  
            tar -zxvf openssl-1.0.2k.tar.gz
            ./config  
            make && make install  

            
        若用方法 1 和 方法 2 后, openssl version 命令显示的版本依旧低于 1.0.2e 版本,请求方法 3

        
        方法 3. 编译 openresty 时指定 openssl 安装目录
            wget -c http://www.openssl.org/source/openssl-1.0.2k.tar.gz
            tar -zxvf openssl-1.0.2k.tar.gz
            编译 openresty 时通过 --with-openssl=/path/to/openssl-xxx/ 指定 openssl 安装路径  

 
        本示例使用方法 3

    
    1.2 pcre-jit

    
        OpenResty 依赖 PCRE ,但通过 apt-get 安装无法开启 pcre-jit,解决方法:  

        
        方法 1. 源码编译
            wget https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gz  
            tar -zxvf pcre-8.40.tar.gz  
            cd pcre-8.40  
            ./configure --enable-jit  
            make && make install  

            
        方法 2. 编译 openresty 时指定 openssl 安装目录
            wget https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gz  
            tar -zxvf pcre-8.40.tar.gz  
            编译 openresty 时通过 --with-pcre=/path/to/pcre-xxx/ 指定 pcre 安装路径 

        
        本示例使用方法 2
  1. 安装 OpenWAF

    cd /opt  
    git clone https://github.com/titansec/OpenWAF.git
    mv /opt/OpenWAF/lib/openresty/ngx_openwaf.conf /etc
    mv /opt/OpenWAF/lib/openresty/configure /opt/openresty-1.11.2.2
    mv /opt/OpenWAF/lib/openresty/* /opt/openresty-1.11.2.2/bundle/
    rm -rf /opt/OpenWAF/lib/openresty

PS:
    2.1 ngx_openwaf.conf
        ngx_openwaf.conf 是 OpenResty 的 [nginx](http://nginx.org/en/docs/) 配置文件

        
    2.2 configure 
        configure 是 OpenResty 的编译文件
        OpenWAF 修改了此文件,用于编译 OpenWAF 所依赖的第三方模块

  1. 编译 openresty

    cd /opt/openresty-1.11.2.2/  
    ./configure --with-pcre-jit --with-ipv6 \  
                --with-http_stub_status_module \  
                --with-http_ssl_module \  
                --with-http_realip_module \  
                --with-http_sub_module  \  
                --with-http_geoip_module \  
                --with-openssl=/opt/openssl-1.0.2k \ 
                --with-pcre=/opt/pcre-8.40 \ 
    make && make install 

CentOS

Debian 安装几乎一致,只需在安装依赖时,将 apt-get 一行命令换成以下命令即可:

    yum install gcc gcc-c++ wget GeoIP-devel git swig make perl perl-ExtUtils-Embed readline-devel zlib-devel -y

Others

其他操作系统安装 OpenWAF,可参考 OpenResty 安装
再安装 OpenWAF 依赖的 swig 即可

Docker容器安装

1. pull docker images from repository
   docker pull titansec/openwaf


2. start-up docker 
    docker run -d --name openwaf \
               -p 80:80 -p 443:443 \
               -v /opt/openwaf/conf/ngx_openwaf.conf:/etc/ngx_openwaf.conf \
               -v /opt/openwaf/conf/twaf_access_rule.json:/opt/OpenWAF/conf/twaf_access_rule.json \
               -v /opt/openwaf/log/openwaf_error.log:/var/log/openwaf_error.log \
               titansec/openwaf 

PS:
    1. docker pull titansec/openwaf 
        默认 pull titansec/openwaf:latest 是 Debian 的最新版

        
    2. 挂载配置文件和日志
        将配置文件保留在宿主机中,更新 OpenWAF 只需更新 Docker 镜像即可
        2.1 挂载 nginx 配置文件
            如,事先将 ngx_openwaf.conf 放在宿主机 /opt/openwaf/conf/ 目录下,然后启动 docker 容器时添加参数如下:
            -v /opt/openwaf/conf/ngx_openwaf.conf:/etc/ngx_openwaf.conf
        2.2 挂载 twaf_access_rule.json 接入规则配置文件
            如,事先将 twaf_access_rule.json 放在宿主机 /opt/openwaf/conf/ 目录下,然后启动 docker 容器时添加参数如下:
            -v /opt/openwaf/conf/twaf_access_rule.json:/opt/OpenWAF/conf/twaf_access_rule.json
        2.3 挂载 nginx 错误日志
            -v /opt/openwaf/log/openwaf_error.log:/var/log/openwaf_error.log

        
    3. restart 
        修改宿主机中的配置文件后,执行 docker restart openwaf(容器名称) 即可
以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号