跳至主要內容

apt安装OpenResty教程

PaperDragon...大约 4 分钟

apt安装OpenResty教程

参考链接: https://blog.openresty.com.cn/cn/ubuntu20-or-install/

适合于Ubuntu各个版本,并非只有20.04。都可以被成功an'z

今天我想演示一下如何通过 apt-get 在 Ubuntu 20.04 上安装 OpenResty 。

截图 1
截图 1

我们将在这个视频中使用这个全新安装的 Ubuntu 20.04 。

我们可以到 openresty.org 网站open in new window上找到相关的说明,这里可以找到所有启用 APT 仓库和安装 OpenResty Deb 包的命令。

截图 3
截图 3

回到我们的 Ubuntu 20.04 系统。如果你已经有服务监听本地 80 端口,那么你应该先禁用它。

sudo lsof -i:80
截图 4
截图 4

在这里,我们没有任何这样的服务。

首先,要确保系统时间正确。

sudo ntpdate -v time.google.com
截图 6
截图 6

你可能想在这里使用你附近的其他 NTP 服务器。

我们应该通过添加 GPG 公钥来安装一些需要的组件。这些可以在之后删除。

sudo apt-get -y install --no-install-recommends wget gnupg ca-certificates
截图 8
截图 8

然后导入我们的 GPG 密钥。

wget -O - https://openresty.org/package/pubkey.gpg | sudo apt-key add -
截图 9
截图 9

接着添加我们的官方 APT 库。

echo "deb http://openresty.org/package/ubuntu $(lsb_release -sc) main" > openresty.list
sudo cp openresty.list /etc/apt/sources.list.d/
截图 10
截图 10

请注意,这是针对 x86_64amd64 系统的。

对于 Aarch64 或 ARM64 系统,你应该使用这个 URL 来代替。

echo "deb http://openresty.org/package/arm64/ubuntu $(lsb_release -sc) main"
截图 12
截图 12

现在更新 APT 索引。

sudo apt-get update
截图 13
截图 13

请注意,这里我们需要 sudo

现在是时候安装我们的主要 RPM 包,openresty

sudo apt-get -y install --no-install-recommends openresty
截图 15
截图 15

检查 openresty 可执行文件是否可用。

which openresty
截图 16
截图 16

这个 openresty 可执行文件只是一个符号链接。

file `which openresty`
截图 17
截图 17

并检查其版本。

openresty -V
截图 18
截图 18

我们可以像这样启动默认的 openresty 服务。

sudo systemctl start openresty
截图 19
截图 19

检查 nginx 进程是否启动并运行。

ps aux|grep nginx
截图 20
截图 20

完美。

curl 命令测试默认主页。

curl 127.0.0.1/
截图 22
截图 22

是的,它的工作。

但请注意,resty 命令行工具还没有安装。

which resty
截图 24
截图 24

如果你想要它,那么你可以从同一个仓库安装 openresty-resty RPM 包。

sudo apt-get -y install openresty-resty
截图 25
截图 25

现在应该可以了。

which resty
resty -e 'print("Hello Resty")'
截图 26
截图 26

同样,如果你想使用 restydoc 命令行工具,你应该安装 openresty-doc 包。

sudo apt-get -y install openresty-restydoc
截图 27
截图 27

现在也有了。

restydoc -s content_by_lua_file
截图 28
截图 28

我们也可以安装 OPM 来安装更多由 OpenResty 社区贡献的 Lua 模块。

sudo apt-get -y install openresty-opm
截图 29
截图 29

现在可以尝试安装 James Hurst 编写的 lua-resty-http 库。

sudo opm get pintsized/lua-resty-http
截图 30
截图 30

试着用 resty 工具加载它。

resty -e 'require "resty.http"'
截图 31
截图 31

成功了!

还有一个 OpenResty 的调试构建,其中包括调试日志和所有启用的内部断言。

sudo apt-get -y install openresty-debug
截图 33
截图 33

我们可以这样调用这个调试版的 openresty 。

which openresty-debug

这个 openresty-debug 可执行文件也是一个符号链接。

file `which openresty-debug`
截图 35
截图 35

我们不应该在生产中使用它,因为它比发行版慢得多。

此外,还有可以通过 Valgrind 检查内存问题的特殊构建。

sudo apt list openresty-valgrind
截图 37
截图 37

当你有内存问题要调试时,可以试试这些。我们可能会在以后的教程中涉及这些内容。

要将 OpenResty 包升级到最新版本,只需运行这些命令。

sudo apt-get update
sudo apt-get --only-upgrade -y install 'openresty*'
截图 39
截图 39

检查我们 openresty 仓库中所有可用的软件包。

apt list 'openresty*' | less
截图 40
截图 40

这里有很多二进制包。

可以在网页上找到所有这些 Deb 包的详细文档,https://openresty.org/en/deb-packages.html ,有很多软件包供用户选择。

截图 42
截图 42
你认为这篇文章怎么样?
  • 0
  • 0
  • 0
  • 0
  • 0
  • 0
评论
  • 按正序
  • 按倒序
  • 按热度
Powered by Waline v3.1.3