OpenWAF 安装

2018-06-06 13:39 更新

名称

OpenWAF 支持源码安装和 Docker 安装

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

Table of Contents

源码安装

Debian&Ubuntu

  1. 安装OpenWAF依赖

  1. cd /opt
  2. apt-get install wget git swig make perl build-essential zlib1g-dev libgeoip-dev libncurses5-dev libreadline-dev -y
  3. wget https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gz
  4. wget https://www.openssl.org/source/openssl-1.0.2k.tar.gz
  5. wget https://openresty.org/download/openresty-1.11.2.2.tar.gz
  6. tar -zxvf pcre-8.40.tar.gz
  7. tar -zxvf openssl-1.0.2k.tar.gz
  8. tar -zxvf openresty-1.11.2.2.tar.gz
  9. rm -rf pcre-8.40.tar.gz \
  10. openssl-1.0.2k.tar.gz \
  11. openresty-1.11.2.2.tar.gz

  1. PS:
  2. 1.1 OpenSSL 版本要求
  3. OpenResty 要求 OpenSSL 最低版本在 1.0.2e 以上,但 apt-get 安装 openssl 并不满足此版本,因此提供解决方法如下:
  4. 方法 1. apt-get 使用 backports 源安装 openssl,如 jessie-backports
  5. echo "deb http://mirrors.163.com/debian/ jessie-backports main" >> /etc/apt/sources.list
  6. apt-get update
  7. apt-get install -t jessie-backports openssl
  8. 方法 2. 下载 openssl 源代码,如 1.0.2k 版本
  9. wget -c http://www.openssl.org/source/openssl-1.0.2k.tar.gz
  10. tar -zxvf openssl-1.0.2k.tar.gz
  11. ./config
  12. make && make install
  13. 若用方法 1 方法 2 后, openssl version 命令显示的版本依旧低于 1.0.2e 版本,请求方法 3
  14. 方法 3. 编译 openresty 时指定 openssl 安装目录
  15. wget -c http://www.openssl.org/source/openssl-1.0.2k.tar.gz
  16. tar -zxvf openssl-1.0.2k.tar.gz
  17. 编译 openresty 时通过 --with-openssl=/path/to/openssl-xxx/ 指定 openssl 安装路径
  18. 本示例使用方法 3
  19. 1.2 pcre-jit
  20. OpenResty 依赖 PCRE ,但通过 apt-get 安装无法开启 pcre-jit,解决方法:
  21. 方法 1. 源码编译
  22. wget https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gz
  23. tar -zxvf pcre-8.40.tar.gz
  24. cd pcre-8.40
  25. ./configure --enable-jit
  26. make && make install
  27. 方法 2. 编译 openresty 时指定 openssl 安装目录
  28. wget https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gz
  29. tar -zxvf pcre-8.40.tar.gz
  30. 编译 openresty 时通过 --with-pcre=/path/to/pcre-xxx/ 指定 pcre 安装路径
  31. 本示例使用方法 2
  1. 安装 OpenWAF

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

  1. PS:
  2. 2.1 ngx_openwaf.conf
  3. ngx_openwaf.conf OpenResty [nginx](http://nginx.org/en/docs/) 配置文件
  4. 2.2 configure
  5. configure OpenResty 的编译文件
  6. OpenWAF 修改了此文件,用于编译 OpenWAF 所依赖的第三方模块

  1. 编译 openresty

  1. cd /opt/openresty-1.11.2.2/
  2. ./configure --with-pcre-jit --with-ipv6 \
  3. --with-http_stub_status_module \
  4. --with-http_ssl_module \
  5. --with-http_realip_module \
  6. --with-http_sub_module \
  7. --with-http_geoip_module \
  8. --with-openssl=/opt/openssl-1.0.2k \
  9. --with-pcre=/opt/pcre-8.40 \
  10. make && make install

CentOS

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

  1. 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. 1. pull docker images from repository
  2. docker pull titansec/openwaf
  3. 2. start-up docker
  4. docker run -d --name openwaf \
  5. -p 80:80 -p 443:443 \
  6. -v /opt/openwaf/conf/ngx_openwaf.conf:/etc/ngx_openwaf.conf \
  7. -v /opt/openwaf/conf/twaf_access_rule.json:/opt/OpenWAF/conf/twaf_access_rule.json \
  8. -v /opt/openwaf/log/openwaf_error.log:/var/log/openwaf_error.log \
  9. titansec/openwaf

  1. PS:
  2. 1. docker pull titansec/openwaf
  3. 默认 pull titansec/openwaf:latest Debian 的最新版
  4. 2. 挂载配置文件和日志
  5. 将配置文件保留在宿主机中,更新 OpenWAF 只需更新 Docker 镜像即可
  6. 2.1 挂载 nginx 配置文件
  7. 如,事先将 ngx_openwaf.conf 放在宿主机 /opt/openwaf/conf/ 目录下,然后启动 docker 容器时添加参数如下:
  8. -v /opt/openwaf/conf/ngx_openwaf.conf:/etc/ngx_openwaf.conf
  9. 2.2 挂载 twaf_access_rule.json 接入规则配置文件
  10. 如,事先将 twaf_access_rule.json 放在宿主机 /opt/openwaf/conf/ 目录下,然后启动 docker 容器时添加参数如下:
  11. -v /opt/openwaf/conf/twaf_access_rule.json:/opt/OpenWAF/conf/twaf_access_rule.json
  12. 2.3 挂载 nginx 错误日志
  13. -v /opt/openwaf/log/openwaf_error.log:/var/log/openwaf_error.log
  14. 3. restart
  15. 修改宿主机中的配置文件后,执行 docker restart openwaf(容器名称) 即可
以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号