美文网首页
运维之OpenResty

运维之OpenResty

作者: felixfeijs | 来源:发表于2020-08-11 14:12 被阅读0次

运维之OpenResty

目录

  • OpenResty简单介绍
  • 在win上安装OpenResty
  • 在linux上安装OpenResty
  • 在Docker上安装OpenResty

OpenResty简单介绍

  • OpenResty是一个基于Nginx与Lua的高性能Web平台,其内部集成了大量精良的Lua库、第三方模块以及大多数的依赖项.用于方便的搭建能够处理超高并发、扩展性能极高的动态Web应用、Web服务和动态网关.

在win上安装OpenResty

在linux上安装OpenResty

  1. 安装依赖
    yum install pcre-devel openssl-devel gcc curl postgresql-devel
  2. 下载安装包
    wget -c https://openresty.org/download/openresty-1.15.8.1rc2.tar.gz
  3. 解压文件
    tar -zxvf openresty-1.15.8.1rc2.tar.gz
  4. 源码编译
//切换目录 
cd openresty-1.15.8.1rc2 
//开始安装 
./configure #或者下面,后面是参数 不写默认就行 
./configure --prefix=/usr/local/openresty/ --with-http_stub_status_module --with-luajit --without-http_redis2_module --with-http_iconv_module --with-http_postgres_module --with-stream gmake && gmake install
  1. 添加环境变量
  • vim /etc/profile
  • export PATH=/usr/local/openresty/nginx/sbin:$PATH
  1. 配置生效
    source /etc/profile
  2. 添加仓库执行命令
yum install yum-utils
yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo
  1. 执行安装
    yum install openresty
  • 安装成功后,生成默认的目录:/usr/local/openresty
  1. 配置nginx
  • nginx.conf中的 #user nobody修改如下
user root;
  1. 启动nginx
    nginx -s reload
  • 可能出现问题nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed
  • 原因:找不到nginx.conf配置文件路径
  • 使用nginx -c指定配置文件路径/usr/local/openresty/nginx/sbin/nginx -c /usr/local/openresty/nginx/conf/nginx.conf
  1. 通过ip访问nginx,成功

在Docker上安装OpenResty

  1. 下载镜像
    docker pull openresty/openresty
  2. 启动镜像
    docker run -it -d --name openresty --privileged=true -p 80:80 openresty/openresty
  3. 创建宿主机nginx.conf
mkdir openresty  
mkdir conf
  1. 复制docker中的nginx.conf到宿主机
    docker cp openresty:/usr/local/openresty/nginx/conf/nginx.conf /usr/local/my-insall/openresty/conf
  2. 删除OpenResty容器
    docker stop id
    docker rm id
  3. 宿主机配置文件进行关联
    docker run -it -d -p 80:80 --name openresty --privileged=true --restart always \
    -v /usr/local/my-insall/openresty/conf/nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf \
    -v /etc/localtime:/etc/localtime openresty/openresty
  4. 检查是否成功
    curl "http://127.0.01"
  5. openresty成功图示.png

相关文章

网友评论

      本文标题:运维之OpenResty

      本文链接:https://www.haomeiwen.com/subject/dgtydktx.html