簡介:
OpenResty® 是一個基於 Nginx 與 Lua 的高性能 Web 平臺,其內部集成了大量精良的 Lua 庫、第三方模塊以及大多數的依賴項。用於方便地搭建可以處理超高併發、擴展性極高的動態 Web 應用、Web 服務和動態網關。html
OpenResty® 經過匯聚各類設計精良的 Nginx 模塊(主要由 OpenResty 團隊自主開發),從而將 Nginx 有效地變成一個強大的通用 Web 應用平臺。這樣,Web 開發人員和系統工程師能夠使用 Lua 腳本語言調動 Nginx 支持的各類 C 以及 Lua 模塊,快速構造出足以勝任 10K 乃至 1000K 以上單機併發鏈接的高性能 Web 應用系統。nginx
OpenResty® 的目標是讓你的Web服務直接跑在 Nginx 服務內部,充分利用 Nginx 的非阻塞 I/O 模型,不單單對 HTTP 客戶端請求,甚至於對遠程後端諸如 MySQL、PostgreSQL、Memcached 以及 Redis 等都進行一致的高性能響應。web
安裝:
進入官網https://openresty.org/en/download.html 選擇openresty-1.15.8.2.tar.gz版本下載vim
tar -zxvf openresty-1.15.8.2.tar.gz後端
cd /www/server/openresty1.15.8服務器
./configure && make && make installswoole
使用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
重啓服務器