openresty安装篇

环境版本

OS:CentOS Linux release 7.1.1503 (Core)html

openresty:1.9.15.1nginx

安装准备

除非你要修改源码,若是只是运行官方的包,官方建议优先考虑预编译包,centos 系统支持以下:centos

版本号 支持的体系结构
5.x x86_64, i386
6.x x86_64, i386
7.x x86_64

配置yum源

你能够在你的 CentOS 系统中添加 openresty 资源库,这样就能够方便的安装咱们的包,之后也能够更新(经过 yum update 命令)。添加资源库,你只用建立一个名为 /etc/yum.repos.d/OpenResty.repo 的文件,内容以下:app

[openresty]
name=Official OpenResty Repository
baseurl=https://copr-be.cloud.fedoraproject.org/results/openresty/openresty/epel-$releasever-$basearch/
skip_if_unavailable=True
gpgcheck=1
gpgkey=https://copr-be.cloud.fedoraproject.org/results/openresty/openresty/pubkey.gpg
enabled=1
enabled_metadata=1

显示支持的包

sudo yum –disablerepo=”*” –enablerepo=”openresty” list availabletcp

Loaded plugins: fastestmirror
openresty                                         | 3.5 kB     00:00     
openresty/7/x86_64/primary_db                       |  32 kB   00:01     
Determining fastest mirrors
Available Packages
openresty.x86_64                         1.9.15.1-16.el7.centos openresty
openresty-debug.x86_64                   1.9.15.1-7.el7.centos  openresty
openresty-debug-debuginfo.x86_64         1.9.15.1-7.el7.centos  openresty
openresty-debuginfo.x86_64               1.9.15.1-16.el7.centos openresty
openresty-doc.noarch                     1.9.15.1-16.el7.centos openresty
openresty-openssl.x86_64                 1.0.2h-3.el7.centos    openresty
openresty-openssl-debug.x86_64           1.0.2h-4.el7.centos    openresty
openresty-openssl-debug-debuginfo.x86_64 1.0.2h-4.el7.centos    openresty
openresty-openssl-debug-devel.x86_64     1.0.2h-4.el7.centos    openresty
openresty-openssl-debuginfo.x86_64       1.0.2h-3.el7.centos    openresty
openresty-openssl-devel.x86_64           1.0.2h-3.el7.centos    openresty
openresty-resty.noarch                   1.9.15.1-16.el7.centos openresty
openresty-valgrind.x86_64                1.9.15.1-6.el7.centos  openresty
openresty-valgrind-debuginfo.x86_64      1.9.15.1-6.el7.centos  openresty
perl-Lemplate.noarch                     0.07-3.el7.centos      openresty
perl-Test-Nginx.noarch                   0.25-3.el7.centos      openresty

安装

关于openresty的rpm包的介绍见这里:http://openresty.org/cn/rpm-packages.html测试

按照文档的说明,咱们暂时只须要安装openresty,openresty-resty,openresty-doc三个包就能够了网站

yum install openresty
yum install openresty-resty
yum install openresty-doc

运行

sudo /sbin/service openresty start

stop, restart, 和 reload 这些指令也是支持的。url

默认网站实例是加载在/usr/local/openresty/nginx/ 目录下的,若是要改变成自定义的目录使用 -p 选项:centos7

sudo openresty -p /opt/my-fancy-app/

这个命令实测,是须要手动建立目录的,记得要先中止openresty。spa

其余问题

防火墙

在centos7下面,防火墙由iptables变动为firewalld,测试时须要增长相应的80端口,或者暂时关闭防火墙。

配置firewalld 使用firewall-cmd,默认须要安装:

yum install firewalld firewalld-config

查看当前开放zone,端口,服务:

firewall-cmd --get-active-zones
firewall-cmd --zone=public --list-ports
firewall-cmd --zone=public --list-service

增长80端口:

firewall-cmd --zone=public --add-port=80/tcp

自启动

添加openresty的开机自启动:

chkconfig --add openresty
chkconfig openresty on

因为centos已经用systemD代替了systemV,系统再也不有rc-local服务了,因此咱们也不能简单添加rc.local了(网上流传的给增长运行权限的,在本机验证不成功)。标准的作法就是建立新的任务,经过chkconfig来启动了。

由于firewallD的规则是不能保存的,因此咱们要放到开机自启动脚本中。

相关文章
相关标签/搜索