运维之OpenResty
目录
- OpenResty简单介绍
- 在win上安装OpenResty
- 在linux上安装OpenResty
- 在Docker上安装OpenResty
OpenResty简单介绍
- OpenResty是一个基于Nginx与Lua的高性能Web平台,其内部集成了大量精良的Lua库、第三方模块以及大多数的依赖项.用于方便的搭建能够处理超高并发、扩展性能极高的动态Web应用、Web服务和动态网关.
在win上安装OpenResty
在linux上安装OpenResty
- 安装依赖
yum install pcre-devel openssl-devel gcc curl postgresql-devel
- 下载安装包
wget -c https://openresty.org/download/openresty-1.15.8.1rc2.tar.gz
- 解压文件
tar -zxvf openresty-1.15.8.1rc2.tar.gz
- 源码编译
//切换目录
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
- 添加环境变量
vim /etc/profile
export PATH=/usr/local/openresty/nginx/sbin:$PATH
- 配置生效
source /etc/profile
- 添加仓库执行命令
yum install yum-utils
yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo
- 执行安装
yum install openresty
- 安装成功后,生成默认的目录:/usr/local/openresty
- 配置nginx
- nginx.conf中的
#user nobody
修改如下
user root;
- 启动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
- 通过
ip
访问nginx,成功
在Docker上安装OpenResty
- 下载镜像
docker pull openresty/openresty
- 启动镜像
docker run -it -d --name openresty --privileged=true -p 80:80 openresty/openresty
- 创建宿主机nginx.conf
mkdir openresty
mkdir conf
- 复制docker中的nginx.conf到宿主机
docker cp openresty:/usr/local/openresty/nginx/conf/nginx.conf /usr/local/my-insall/openresty/conf
- 删除OpenResty容器
docker stop id
docker rm id
- 宿主机配置文件进行关联
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
- 检查是否成功
curl "http://127.0.01"
-
openresty成功图示.png
网友评论