openresty+GenIP編譯安裝并容器化

openresty+GenIP編譯安裝并容器化

下載地址整理
獲取zlib下載地址 http://www.zlib.net/zlib-1.2.11.tar.gz
獲取pcre下載地址 https://ftp.pcre.org/pub/pcre/pcre-8.00.tar.gz
獲取openssl下載地址 https://github.com/openssl/openssl.git
獲取luajit下載地址 http://luajit.org/download/LuaJIT-2.0.5.tar.gz
獲取openresty下載地址 https://openresty.org/download/openresty-1.15.8.2.tar.gz
libunwind下載地址 http://ftp.yzu.edu.tw/nongnu/libunwind/libunwind-1.1.tar.gz
gperftools下載地址 https://github.com/gperftools/gperftools/releases/download/gperftools-2.4/gperftools-2.4.tar.gz
libmaxminddb下載地址 https://github.com/maxmind/libmaxminddb/releases/download/0.5.5/libmaxminddb-0.5.5.tar.gz

1.編譯安裝

1.1.準備工作

yum install gcc-c++ systemtap-sdt-devel perl-CPAN  git vim -y
mkdir /opt/openresty

1.2.編譯安裝openssl

git clone https://github.com/openssl/openssl.git /opt/
cd /opt/openssl/
./config --prefix=/opt/openresty/openssl
make
make install

1.3.編譯安裝pcre

wget https://ftp.pcre.org/pub/pcre/pcre-8.00.tar.gz
tar xvf pcre-8.00.tar.gz
cd pcre-8.00/
./configure --prefix=/opt/openresty/pcre
make
make install

1.4.編譯安裝zlib

wget http://www.zlib.net/zlib-1.2.11.tar.gz
tar xvf zlib-1.2.11.tar.gz 
./configure --prefix=/opt/openresty/zlib
make
make install

1.5.編譯安裝libuwind

google-pertools需要libuwind

wget http://ftp.yzu.edu.tw/nongnu/libunwind/libunwind-1.1.tar.gz
tar xvf libunwind-1.1.tar.gz
cd libunwind-1.1
./configure
make
make install

1.6.編譯安裝google-pertools

openresty編譯需要google-pertools

wget -c -O gperftools-2.4.tar.gz  https://github.com/gperftools/gperftools/releases/download/gperftools-2.4/gperftools-2.4.tar.gz
tar xvf gperftools-2.4.tar.gz
cd gperftools-2.4
./configure
make check
make install

1.7.編譯安裝libmaxminddb

GenIP需要改Lib庫

wget https://github.com/maxmind/libmaxminddb/releases/download/0.5.5/libmaxminddb-0.5.5.tar.gz
tar -zxvf libmaxminddb-0.5.5.tar.gz
cd libmaxminddb-0.5.5
./configure
make check
make install
echo "/usr/local/lib" >> /etc/ld.so.conf
ldconfig

1.8.編譯安裝openresty

wget https://openresty.org/download/openresty-1.15.8.2.tar.gz
tar xvf openresty-1.15.8.2.tar.gz
cd openresty-1.15.8.2
./configure --prefix=/opt/openresty --with-ld-opt='-Wl,-rpath,/opt/openresty/luajit/lib -L/opt/openresty/zlib/lib -L/opt/openresty/pcre/lib -L/opt/openresty/openssl/lib -Wl,-rpath,/opt/openresty/zlib/lib:/opt/openresty/pcre/lib:/opt/openresty/openssl/lib' --with-cc-opt='-O2 -DNGX_LUA_ABORT_AT_PANIC -I/opt/openresty/zlib/include -I/opt/openresty/pcre/include -I/opt/openresty/openssl/include' --with-http_ssl_module --add-module=/opt/openresty-1.15.8.2/bundle/ngx_http_geoip2_module --with-pcre-jit --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_v2_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_auth_request_module --with-http_secure_link_module --with-http_random_index_module --with-http_gzip_static_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-threads --with-dtrace-probes --with-stream --with-stream_ssl_preread_module 
gmake
gmake install

1.9 運行openresty測試

  • 編輯/opt/openresty/nginx/conf/nginx.conf文件
    • 注釋server{}
    • 添加include ./conf.d/*.conf;
    • 需要標準輸出選填此項
      • 修改accesslog輸出位置access_log /dev/stdout;
      • 修改errorlog輸出位置error_log /dev/stderr;
#user  nobody;
worker_processes  1;

error_log  /dev/stderr;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    include ./conf.d/*.conf;

    geoip2 GeoLite/GeoLite2-Country_20191203/GeoLite2-Country.mmdb{
        $geoip2_data_country_code  country iso_code ;
        $geoip2_data_country_name  source=$http_x_forwarded_for default=中國 country names zh-CN;
    }

    geoip2 GeoLite/GeoLite2-City_20191203/GeoLite2-City.mmdb{
        $geoip2_data_city_name source=$http_x_forwarded_for default=北京 city names zh-CN;
    }

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;
    access_log  /dev/stdout;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

#    server {
#        listen       80;
#        server_name  localhost;
#
#        #charset koi8-r;
#
#        #access_log  logs/host.access.log  main;
#
#        location / {
#            default_type text/html;
#            content_by_lua '
#                ngx.say("<p>hello, world</p>")
#       ';
#        }
#
#        #error_page  404              /404.html;
#
#        # redirect server error pages to the static page /50x.html
#        #
#        error_page   500 502 503 504  /50x.html;
#        location = /50x.html {
#            root   html;
#        }
#
#        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
#        #
#        #location ~ \.php$ {
#        #    proxy_pass   http://127.0.0.1;
#        #}
#
#        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#        #
#        #location ~ \.php$ {
#        #    root           html;
#        #    fastcgi_pass   127.0.0.1:9000;
#        #    fastcgi_index  index.php;
#        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
#        #    include        fastcgi_params;
#        #}
#
#        # deny access to .htaccess files, if Apache's document root
#        # concurs with nginx's one
#        #
#        #location ~ /\.ht {
#        #    deny  all;
#        #}
#    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

1.10.創(chuàng)建測試文件

mkdir /opt/openresty/nginx/conf/conf.d
vim /opt/openresty/nginx/conf/conf.d/default.conf

default.conf文件內容

server {
    listen       80;
    server_name  localhost;
    location / {
        default_type text/html;
        content_by_lua '
            ngx.say("<p>hello, world</p>")
       ';
    }
}

1.11.啟動openresty

啟動openresty

/opt/openresty/bin/openresty

測試openresty

curl localhost:80
<p>hello, world</p>

2.容器化測試openresty

2.2 安裝Docker

yum install docker -y
systemctl start docker

2.1. 編寫DockerFile

FROM centos
ADD openresty /opt/openresty
ADD libmaxminddb-0.5.5.tar.gz /opt/
RUN cd /opt/libmaxminddb-0.5.5; \
    yum update -y; \
    yum install git vim gc.x86_64  gcc.x86_64  gcc-c++.x86_64 make.x86_64 -y; \
    ./configure; \
    make check; \
    make install; \
    echo "/usr/local/lib" >> /etc/ld.so.conf; \
    ldconfig
CMD ["/opt/openresty/bin/openresty","-g","daemon off;"]

2.3 編譯鏡像

docker build -t openresty-genip:v0.1 .

2.4 運行并測試

運行容器

docker run -ti --rm -p 80:80 openresty-genip:v0.1

測試

curl localhost
<p>hello, world</p>
?著作權歸作者所有,轉載或內容合作請聯系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容