openresty+GenIP编译安装并容器化
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;
- 修改accesslog输出位置
- 注释
#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>