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.创建测试文件

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>
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,088评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,715评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,361评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,099评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 60,987评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,063评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,486评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,175评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,440评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,518评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,305评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,190评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,550评论 3 298
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,880评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,152评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,451评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,637评论 2 335

推荐阅读更多精彩内容