openresty高性能web平台安裝使用
簡介:
OpenResty® 是一個基於 Nginx 與 Lua 的高性能 Web 平台,其內部集成了大量精良的 Lua 庫、第三方模塊以及大多數的依賴項。用於方便地搭建能夠處理超高並發、擴展性極高的動態 Web 應用、Web 服務和動態網關。
OpenResty® 通過匯聚各種設計精良的 Nginx 模塊(主要由 OpenResty 團隊自主開發),從而將 Nginx 有效地變成一個強大的通用 Web 應用平台。這樣,Web 開發人員和系統工程師可以使用 Lua 腳本語言調動 Nginx 支持的各種 C 以及 Lua 模塊,快速構造出足以勝任 10K 乃至 1000K 以上單機並發連接的高性能 Web 應用系統。
OpenResty® 的目標是讓你的Web服務直接跑在 Nginx 服務內部,充分利用 Nginx 的非阻塞 I/O 模型,不僅僅對 HTTP 客戶端請求,甚至於對遠程后端諸如 MySQL、PostgreSQL、Memcached 以及 Redis 等都進行一致的高性能響應。
安裝:
進入官網https://openresty.org/en/download.html 選擇openresty-1.15.8.2.tar.gz版本下載
tar -zxvf openresty-1.15.8.2.tar.gz
cd /www/server/openresty1.15.8
./configure && make && make install
使用nginx模塊搭建負載均衡配置如下:
upstream easyswoole_server { server 127.0.0.1:9501 weight=1; server 127.0.0.1:9502 weight=1; server 127.0.0.1:9503 weight=1; } server { listen 8081; server_name 192.168.0.10; #charset koi8-r; #access_log logs/host.access.log main; location / { root /www/wwwroot/imooc_easyswoole3/webroot; index index.html index.htm; if (!-e $request_filename) { proxy_pass http://easyswoole_server; } } }
配置openresty中的nginx開機自啟:
vim /etc/rc.d/init.d/nginx
添加如下內容
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin NAME=nginx NGINX_BIN=/www/server/openresty1.15.8/nginx/sbin/$NAME CONFIGFILE=/www/server/openresty1.15.8/nginx/conf/$NAME.conf PIDFILE=/www/server/openresty1.15.8/nginx/logs/$NAME.pid ulimit -n 8192 case "$1" in start) echo -n "Starting $NAME... " if [ -f $PIDFILE ];then mPID=`cat $PIDFILE` isStart=`ps ax | awk '{ print $1 }' | grep -e "^${mPID}$"` if [ "$isStart" != '' ];then echo "$NAME (pid `pidof $NAME`) already running." exit 1 fi fi $NGINX_BIN -c $CONFIGFILE if [ "$?" != 0 ] ; then echo " failed" exit 1 else echo " done" fi ;; stop) echo -n "Stoping $NAME... " if [ -f $PIDFILE ];then mPID=`cat $PIDFILE` isStart=`ps ax | awk '{ print $1 }' | grep -e "^${mPID}$"` if [ "$isStart" = '' ];then echo "$NAME is not running." exit 1 fi else echo "$NAME is not running." exit 1 fi $NGINX_BIN -s stop if [ "$?" != 0 ] ; then echo " failed. Use force-quit" exit 1 else echo " done" fi ;; status) if [ -f $PIDFILE ];then mPID=`cat $PIDFILE` isStart=`ps ax | awk '{ print $1 }' | grep -e "^${mPID}$"` if [ "$isStart" != '' ];then echo "$NAME (pid `pidof $NAME`) already running." exit 1 else echo "$NAME is stopped" exit 0 fi else echo "$NAME is stopped" exit 0 fi ;; restart) $0 stop sleep 1 $0 start ;; reload) echo -n "Reload service $NAME... " if [ -f $PIDFILE ];then mPID=`cat $PIDFILE` isStart=`ps ax | awk '{ print $1 }' | grep -e "^${mPID}$"` if [ "$isStart" != '' ];then $NGINX_BIN -s reload echo " done" else echo "$NAME is not running, can't reload." exit 1 fi else echo "$NAME is not running, can't reload." exit 1 fi ;; configtest) echo -n "Test $NAME configure files... " $NGINX_BIN -t ;; *) echo "Usage: $0 {start|stop|restart|reload|status|configtest}" exit 1 ;; esac
創建nginx的軟連接:ln -s /www/server/openresty1.15.8/nginx/sbin/nginx /usr/local/sbin/nginx
重啟服務器
