zoukankan      html  css  js  c++  java
  • OpenResty高性能web平台

    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

    重启服务器

  • 相关阅读:
    浅拷贝和深拷贝问题
    指针遍历数组时用法
    一维数组和指针
    leetcode
    tmux
    git
    einsum详解
    spark快速大数据分析 读书笔记
    maven配置
    bash 学习笔记
  • 原文地址:https://www.cnblogs.com/lty-fly/p/12951588.html
Copyright © 2011-2022 走看看