centos7编译安装openresty+lua-resty-http+lua-resty-openssl-master

目录

主要特点

1. 环境准备

2. 下载并安装 OpenResty 1.25.3.1

2.1 下载 OpenResty

2.2 编译和安装 OpenResty

2.3 设置环境变量

1. 下载 lua-resty-http

2. 解压缩文件

3. 移动模块到 OpenResty 的合适目录

1. 下载 lua-resty-openssl

2. 移动模块到 OpenResty 的合适目录


OpenResty 是一个基于 Nginx 的高性能 Web 平台,它将 Nginx 服务器与 Lua 脚本语言紧密集成在一起,从而使得用户可以使用 Lua 编写各种 Web 应用和服务。OpenResty 提供了一系列的模块和工具,使得开发人员可以轻松地构建动态 Web 应用程序、RESTful API、微服务等。

主要特点

  1. 高性能:OpenResty 基于 Nginx,这使得它可以处理大量并发连接和请求,表现出色。

  2. Lua 脚本支持:通过将 Lua 脚本语言嵌入 Nginx,开发人员可以用 Lua 编写复杂的业务逻辑,包括处理 HTTP 请求、操作数据库等。

  3. 丰富的模块:OpenResty 附带了许多实用的模块(如 lua-resty-httplua-resty-sessionlua-resty-redis 等),这些模块可以帮助开发人员实现各种功能,如 API 调用、会话管理、缓存等。

  4. 良好的扩展性:开发人员可以方便地编写自定义的 Lua 模块,扩展 OpenResty 的功能。

  5. 友好的开发体验:OpenResty 提供了良好的开发工具和文档支持,使得开发人员能够快速上手。

  6. 广泛应用:由于其高性能和灵活性,OpenResty 已被许多大型网站和应用广泛采用,如 GitHub、Taobao、知乎等。

在 CentOS 7 上编译安装 OpenResty 1.25.3.1:

1. 环境准备

确保系统是最新的,并安装必要的依赖包:

sudo yum update
sudo yum install -y gcc gcc-c++ make curl unzip zlib-devel pcre-devel openssl-devel git

2. 下载并安装 OpenResty 1.25.3.1

2.1 下载 OpenResty

访问 OpenResty 下载页面 或直接使用 wget 下载指定版本:

wget https://openresty.org/download/openresty-1.25.3.1.tar.gz
tar -zxvf openresty-1.25.3.1.tar.gz
cd openresty-1.25.3.1/
2.2 编译和安装 OpenResty
./configure --prefix=/usr/local/openresty
make
sudo make install
  • 如果系统中安装了多个版本的 OpenSSL,需要明确指定 OpenResty 使用的 OpenSSL源码路径。

   --with-openssl=/usr/local/ssl

2.3 设置环境变量

将 OpenResty 的二进制文件路径添加到路径中:

echo 'export PATH=$PATH:/usr/local/openresty/bin' >> ~/.bashrc
source ~/.bashrc

在OpenResty中安装插件lua-resty-http

1. 下载 lua-resty-http

首先,使用 curl 或 wget 下载指定版本的 tar.gz 压缩包:

# 使用 curl 下载
curl -LO https://github.com/ledgetech/lua-resty-http/archive/refs/tags/v0.17.2.tar.gz

# 或使用 wget 下载
wget https://github.com/ledgetech/lua-resty-http/archive/refs/tags/v0.17.2.tar.gz

2. 解压缩文件

解压缩下载的文件:

tar -xzvf v0.17.2.tar.gz

这将创建一个名为 lua-resty-http-0.17.2 的文件夹。

3. 移动模块到 OpenResty 的合适目录

将解压后的 lua-resty-http 模块移动到 OpenResty 的 lualib/resty/ 目录下。例如,如果 OpenResty 安装在 /usr/local/openresty 目录下,执行以下命令:

sudo mkdir -p /usr/local/openresty/lualib/resty/  # 创建目标目录(如果不存在)
sudo mv lua-resty-http-0.17.2/lib/resty/http.lua /usr/local/openresty/lualib/resty/
sudo mv lua-resty-http-0.17.2/lib/resty/http_headers.lua /usr/local/openresty/lualib/resty/
sudo mv lua-resty-http-0.17.2/lib/resty/http_connect.lua /usr/local/openresty/lualib/resty/

在OpenResty中安装插件lua-resty-openssl

1. 下载 lua-resty-openssl

使用 git 克隆源代码库:

git clone https://github.com/fffonion/lua-resty-openssl.git

如果没有安装 git,你也可以直接访问 该链接 并下载 ZIP 文件,然后解压。

2. 移动模块到 OpenResty 的合适目录

假设你在 /usr/local/openresty 目录中安装了 OpenResty,使用以下命令将模块移动到 OpenResty 的 lualib 目录:

# 创建目标目录(如果不存在)
sudo mkdir -p /usr/local/openresty/lualib/resty/
sudo mkdir -p /usr/local/openresty/lualib/resty/openssl

# 移动 lua-resty-openssl 的目录到目标位置
sudo mv lua-resty-openssl/lib/resty/openssl.lua /usr/local/openresty/lualib/resty/
sudo mv lua-resty-openssl/lib/resty/openssl/* /usr/local/openresty/lualib/resty/openssl/
<think>好的,用户想在CentOS 7安装OpenResty,我需要根据提供的引用内容整理步骤。首先,引用1和2提到了安装依赖项,包括yum-utils和添加仓库源。然后引用3提到安装OpenResty本身以及resty工具。需要把这些步骤按顺序排列,确保用户能一步步操作。要注意权限问题,可能需要使用sudo或者root权限。另外,安装后的验证步骤也很重要,比如检查版本和启动服务。可能还需要提示用户配置防火墙或者开机启动,但引用里没有提到这些,所以暂时不加入。最后要生成相关问题,覆盖依赖项作用、验证安装、卸载方法以及OpenRestyNginx的区别,这样用户能有更全面的了解。要确保回答结构清晰,步骤正确,符合用户的需求。</think>以下是CentOS 7安装OpenResty的详细步骤: ### 一、安装依赖项 1. 使用root权限登录服务器 2. 执行以下命令安装基础工具: ```bash yum install -y yum-utils ``` 3. 添加OpenResty官方仓库源: ```bash yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo ```[^1][^2] ### 二、安装OpenResty 1. 通过yum安装主程序包: ```bash yum install -y openresty ```[^3] 2. (可选)安装命令行工具: ```bash yum install -y openresty-resty ```[^3] ### 三、验证安装 1. 查看安装版本: ```bash openresty -v ``` 2. 启动服务: ```bash systemctl start openresty ``` 3. 检查运行状态: ```bash systemctl status openresty ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值