Openrestyベストケース|第3編:Openrestyのインストール


転載は出典を明記してください.http://blog.csdn.net/forezp/article/details/78616645本文は方志朋のブログから
個人ブログの純版:https://www.fangzhipeng.com/openresty/2018/01/01/openresty-best-practice-3-openresty-install.html
私のサーバーは新しいcentos 7のサーバーなので、openrestyを最初からインストールし、インストール中に発生した問題と解決方法を記録しました.
1.まずopenrestyをインストールする
cd /usr
mkdir servers
mkdir downloads 

yum install libreadline-dev libncurses5-dev libpcre3-dev libssl-dev perl 
 
cd /usr/servers
 
wget https://openresty.org/download/openresty-1.11.2.4.tar.gz
tar -zxvf openresty-1.11.2.4.tar.gz
cd /usr/servers/bunble/LuaJIT-2.1-20170405

  Lua
make clean && make && make install  
 

インストール中に次のエラーが発生しました.
gcc: Command not found
2.gccを取り付ける
yum -y install gcc automake autoconf libtool make

3.再make
make clean && make && make install

ln -sf luajit-2.1.0-alpha /usr/local/bin/luajit  


4.ngx_をダウンロードcache_purgeモジュールnginxキャッシュをクリーンアップするためのモジュール
cd/usr/servers/ngx_openresty–1.11.2.4/bundle wget https://github.com/FRiCKLE/ngx_cache_purge/archive/2.3.tar.gz tar -xvf 2.3.tar.gz
5.nginx_をダウンロードするupstream_check_moduleモジュールustream健康診断用
cd/usr/servers/ngx_openresty-1.11.2.4/bundle wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/v0.3.0.tar.gz tar -xvf v0.3.0.tar.gz
6.oprestyの再インストール
cd /usr/servers/ngx_openresty-1.11.2.4

./configure --prefix=/usr/servers --with-http_realip_module  --with-pcre  --with-luajit --add-module=./bundle/ngx_cache_purge-2.3/ --add-module=./bundle/nginx_upstream_check_module-0.3.0/ -j2 


プロンプトエラー、pcreライブラリのインストール
yum install -y pcre pcre-devel


<1>gccインストールnginxは、まず公式サイトからダウンロードしたソースコードをコンパイルする必要があります.コンパイルはgcc環境に依存します.gcc環境がなければ、インストールする必要があります.
yum install gcc-c++

<2>PCRE pcre-develインストール
PCRE(Perl Compatible Regular Expressions)は、Perl互換性のある正規表現ライブラリを含むPerlライブラリです.nginxのhttpモジュールはpcreを使用して正規表現を解析するため、linuxにpcreライブラリをインストールする必要があります.pcre-develはpcreを使用して開発された二次開発ライブラリです.nginxにもこのライブラリが必要です.コマンド:
yum install -y pcre pcre-devel

<3>zlibインストールzlibライブラリは圧縮と解凍の方法を多く提供しており、nginxはzlibを使用してhttpパッケージの内容をgzipするため、Centosにzlibライブラリをインストールする必要がある.
yum install -y zlib zlib-devel

<4>OpenSSLインストールOpenSSLは強力なセキュリティソケット層暗号ライブラリであり、主な暗号アルゴリズム、一般的な鍵と証明書パッケージ管理機能、SSLプロトコルを網羅し、テストまたはその他の目的で豊富なアプリケーションを提供しています.nginxはhttpプロトコルだけでなく、http(すなわち、sslプロトコル上でhttpを転送する)もサポートするので、CentosにOpenSSLライブラリをインストールする必要があります.
yum install -y openssl openssl-devel

<5>.OpenRestyの再インストール
cd /usr/servers/ngx_openresty-1.11.2.4

./configure --prefix=/usr/servers --with-http_realip_module  --with-pcre  --with-luajit --add-module=./bundle/ngx_cache_purge-2.3/ --add-module=./bundle/nginx_upstream_check_module-0.3.0/ -j2 

make && make install  

<6>.Nginxの起動
/usr/servers/nginx/sbin/nginx

ブラウザアクセスhttp://116.196.177.123:
Welcome to OpenResty!

If you see this page, the OpenResty web platform is successfully installed and working. Further configuration is required.

For online documentation and support please refer to openresty.org.

Thank you for flying OpenResty.

インストールに成功しました.
6.nginxの構成
vim /usr/servers/nginx/conf/nginx.conf  

エラーメッセージvimがインストールされていません
 yum -y install vim*

1、http部分に以下の構成を追加する
luaモジュールパス、複数の間」;区切るデフォルトの検索パスを表し、デフォルトは/usr/servers/nginxで検索されます.
lua_package_path “/usr/servers/lualib/?.lua;;”; #luaモジュールlua_package_cpath “/usr/servers/lualib/?.so;;”; #cモジュール
2、nginx.confのhttp部分にinclude luaを追加する.confはこのファイルクリップJavaコードコレクションコードinclude luaを含む.conf;
/usr/server/nginx/confで
vim lua.conf
#lua.conf  
server {  
    listen       80;  
    server_name  _;  
    
    location /lua {  
    default_type 'text/html';  
        content_by_lua 'ngx.say("hello world")';  
    } 
}  



7.環境変数:
vim/etc/profile
JAVA_HOME=/usr/local/jdk/jdk1.8.0_144
JRE_HOME=$JAVA_HOME/jre
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
CLASSPATH=:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib/dt.jar
export JAVA_HOME JRE_HOME PATH CLASSPATH
export PATH=$PATH:/usr/servers/nginx/sbin


source/etc/profile
テスト:
nginx -t
nginx: the configuration file/usr/servers/nginx/conf/nginx.conf syntax is ok nginx: configuration file/usr/servers/nginx/conf/nginx.conf test is successful
nginx -s reload
ブラウザアクセスhttp://116.196.177.123/luaを選択します.
hello world
8.Luaをプロジェクト化する:
mkdir/usr/example cp -r/usr/servers/lualib//usr/example/mkdir/usr/example/lua
cd/usr/example vim example.conf
server {  
    listen       80;  
    server_name  _;  
  
    location /lua {  
        default_type 'text/html';  
        lua_code_cache off;  
        content_by_lua_file /usr/example/lua/test.lua;  
    }  
} 


vim/usr/example/lua/test.lua
ngx.say("hello world");  

cd/usr/servers/nginx/conf/
vim nginx.conf
httpモジュール:
http {
    include       mime.types;
    default_type  application/octet-stream;
    lua_package_path "/usr/example/lualib/?.lua;;";  #lua     
    lua_package_cpath "/usr/example/lualib/?.so;;";  #c     
    include /usr/example/example.conf;
 ....
 ....

}

nginx -t
nginx: [alert] lua_code_cache is off; this will hurt performance in/usr/example/example.conf:7 nginx: the configuration file/usr/servers/nginx/conf/nginx.conf syntax is ok nginx: configuration file/usr/servers/nginx/conf/nginx.conf test is successful
nginx -s reload
ブラウザアクセスhttp://116.196.177.123/lua ,
hello world
historyのすべてのコマンドをエクスポートします.
                
ls -a   
   .bash_history
          。
    :
cat   .bash_history >> history.txt


参考資料
http://www.linuxidc.com/Linux/2016-09/134907.htm
http://jinnianshilongnian.iteye.com/blog/2186270
https://openresty.org/en/
詳細
史上最も簡単なSpringCloudチュートリアルの概要
SpringBootチュートリアルの概要
Java面接問題シリーズまとめ
Openresty最佳案例 | 第3篇:Openresty的安装_第1张图片スキャンコード公衆番号に注目サプライズ
(当駅の文章を転載するには作者と出典方志朋のブログを明記してください)