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的規則是不能保存的,因此咱們要放到開機自啓動腳本中。

相關文章
相關標籤/搜索