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.準(zhǔn)備工作

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 運(yùn)行openresty測試

  • 編輯/opt/openresty/nginx/conf/nginx.conf文件
    • 注釋server{}
    • 添加include ./conf.d/*.conf;
    • 需要標(biāo)準(zhǔn)輸出選填此項(xiàng)
      • 修改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文件內(nèi)容

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

1.11.啟動(dòng)openresty

啟動(dòng)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 運(yùn)行并測試

運(yùn)行容器

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

測試

curl localhost
<p>hello, world</p>
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末游昼,一起剝皮案震驚了整個(gè)濱河市甘苍,隨后出現(xiàn)的幾起案子尝蠕,更是在濱河造成了極大的恐慌烘豌,老刑警劉巖,帶你破解...
    沈念sama閱讀 217,277評(píng)論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件看彼,死亡現(xiàn)場離奇詭異廊佩,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)靖榕,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,689評(píng)論 3 393
  • 文/潘曉璐 我一進(jìn)店門标锄,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人茁计,你說我怎么就攤上這事料皇。” “怎么了星压?”我有些...
    開封第一講書人閱讀 163,624評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵践剂,是天一觀的道長。 經(jīng)常有香客問我娜膘,道長逊脯,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,356評(píng)論 1 293
  • 正文 為了忘掉前任竣贪,我火速辦了婚禮军洼,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘演怎。我一直安慰自己匕争,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,402評(píng)論 6 392
  • 文/花漫 我一把揭開白布爷耀。 她就那樣靜靜地躺著甘桑,像睡著了一般。 火紅的嫁衣襯著肌膚如雪畏纲。 梳的紋絲不亂的頭發(fā)上扇住,一...
    開封第一講書人閱讀 51,292評(píng)論 1 301
  • 那天,我揣著相機(jī)與錄音盗胀,去河邊找鬼艘蹋。 笑死,一個(gè)胖子當(dāng)著我的面吹牛票灰,可吹牛的內(nèi)容都是我干的女阀。 我是一名探鬼主播宅荤,決...
    沈念sama閱讀 40,135評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼浸策!你這毒婦竟也來了冯键?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 38,992評(píng)論 0 275
  • 序言:老撾萬榮一對(duì)情侶失蹤庸汗,失蹤者是張志新(化名)和其女友劉穎惫确,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體蚯舱,經(jīng)...
    沈念sama閱讀 45,429評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡改化,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,636評(píng)論 3 334
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了枉昏。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片陈肛。...
    茶點(diǎn)故事閱讀 39,785評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖兄裂,靈堂內(nèi)的尸體忽然破棺而出句旱,到底是詐尸還是另有隱情,我是刑警寧澤晰奖,帶...
    沈念sama閱讀 35,492評(píng)論 5 345
  • 正文 年R本政府宣布谈撒,位于F島的核電站,受9級(jí)特大地震影響畅涂,放射性物質(zhì)發(fā)生泄漏港华。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,092評(píng)論 3 328
  • 文/蒙蒙 一午衰、第九天 我趴在偏房一處隱蔽的房頂上張望立宜。 院中可真熱鬧,春花似錦臊岸、人聲如沸橙数。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,723評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽灯帮。三九已至,卻和暖如春逻住,著一層夾襖步出監(jiān)牢的瞬間钟哥,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,858評(píng)論 1 269
  • 我被黑心中介騙來泰國打工瞎访, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留腻贰,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 47,891評(píng)論 2 370
  • 正文 我出身青樓扒秸,卻偏偏與公主長得像播演,于是被迫代替她去往敵國和親冀瓦。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,713評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容