CentOS 설치 OpenResty (Nginx + Lua) 개발 환경
OpenResty® Nginx 와 Lua 를 바탕 으로 하 는 고성능 웹 플랫폼 으로 그 내부 에 대량의 우수한 Lua 라 이브 러 리, 제3자 모듈 과 대부분의 의존 항 이 통합 되 었 다.초고 동시 다발, 확장 성 이 높 은 동적 웹 응용, 웹 서비스 와 동적 게 이 트 웨 이 를 편리 하 게 구축 할 수 있 습 니 다.
OpenResty® 각종 디자인 이 우수한 Nginx 모듈 (주로 OpenResty 팀 이 자체 개발) 을 모 아 Nginx 를 강력 한 유 니 버 설 웹 응용 플랫폼 으로 효과적으로 만 듭 니 다.이렇게 하면 웹 개발 자 와 시스템 엔 지 니 어 는 Lua 스 크 립 트 언어 로 Nginx 가 지원 하 는 각종 C 및 Lua 모듈 을 동원 하여 10K 내지 1000 K 이상 의 단일 컴퓨터 와 동시 연결 할 수 있 는 고성능 웹 응용 시스템 을 신속하게 구축 할 수 있다.
OpenResty® 웹 서 비 스 를 Nginx 서비스 내부 로 직접 달 려 가 Nginx 의 비 차단 I / O 모델 을 충분히 이용 하 는 것 이 목표 입 니 다. HTTP 클 라 이언 트 에 대한 요청 뿐만 아니 라 원 격 백 엔 드, 예 를 들 어 MySQL, PostgreSQL, Memcached 와 Redis 등 도 일치 하 는 고성능 응답 을 하 는 것 입 니 다.OpenResty®홈 페이지
정리 와 확장:
Nginx + Lua 구조 사고 지도:
2. SELinux 닫 기
먼저 임시로 닫 은 후에 영구적 으로 닫 습 니 다.
setenforce 0 #
sed -i "s#SELINUX=enforcing#SELINUX=disabled#g" /etc/selinux/config # . 80
먼저 80 포트 를 임시 오픈 한 후 영구적 으로 오픈 합 니 다.
iptables -I INPUT -p tcp --dport 80 -j ACCEPT #
/etc/init.d/iptables save # ,
/etc/init.d/iptables status # iptables
4. yum 설치
일반적인 리 눅 스 버 전, OpenResty® 제공 하 다. 공식 번역 가방.당신 이 먼저 이런 방식 으로 설치 하도록 보장 합 니 다.
CentOS 시스템 에 openresty 창 고 를 추가 하면 미래 에 우리 의 패 키 지 를 설치 하거나 업데이트 할 수 있 습 니 다 (yum update 명령 을 통 해).다음 명령 을 실행 하면 창 고 를 추가 할 수 있 습 니 다.
yum install yum-utils -y
yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo
그리고 아래 와 같이 소프트웨어 패 키 지 를 설치 할 수 있 습 니 다. 예 를 들 어 openresty:
yum install openresty -y
명령 행 도구 resty 를 설치 하고 싶다 면 아래 처럼 openresty - resty 패 키 지 를 설치 할 수 있 습 니 다.
yum install openresty-resty -y
명령 행 도구 opm 는 openresty - opm 가방 에 있 고 restydoc 도 구 는 openresty - doc 가방 에 있 습 니 다.
모든 openresty 창고 에 있 는 패 키 지 를 보 여 줍 니 다:
yum --disablerepo="*" --enablerepo="openresty" list available
레 퍼 런 스 OpenResty RPM 패키지 페이지 에서 이 가방 들 의 자세 한 정 보 를 가 져 옵 니 다.
5. 소스 패키지 컴 파일 설치
다운로드 하 다.
다운로드 페이지 에서 최신 OpenResty 다운로드® 원본 패키지, 그리고 아래 예시 와 같이 압축 풀기:
wget https://openresty.org/download/openresty-1.13.6.2.tar.gz
설치 전 준비
이 라 이브 러 리 perl 5.6.1 +, libpcre, libssl 을 컴퓨터 에 설치 해 야 합 니 다.Linux 에 대해 서 는 시스템 환경 경로 에서 찾 을 수 있 도록 ldconfig 명령 을 사용 하 는 지 확인 해 야 합 니 다.
yum 을 사용 하여 아래 개발 라 이브 러 리 를 설치 하 는 것 을 추천 합 니 다:
yum install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel libxslt-devel gd-devel pcre-devel -y
yum -y install GeoIP GeoIP-devel GeoIP-data
groupadd nginx && useradd -r -g nginx -s /sbin/nologin -M nginx
설치 하 다.
tar -zxvf openresty-1.13.6.2.tar.gz
cd openresty-1.13.6.2
./configure
make
make install
컴퓨터 가 다 중 핵 make 작업 의 특성 을 지원 한다 면 이렇게 컴 파일 할 수 있 습 니 다.
# 。
make -j2
기본적으로, -- prefix = / usr / local / openresty 프로그램 은 / usr / local / openresty 디 렉 터 리 에 설 치 됩 니 다.다음 과 같은 다양한 옵션 을 지정 할 수 있 습 니 다.
./configure --prefix=/opt/openresty --conf-path=/etc/nginx/nginx.conf --pid-path=/var/run/nginx.pid \
--lock-path=/var/lock/nginx.lock --user=nginx --group=nginx \
--with-http_ssl_module --with-http_stub_status_module --with-http_realip_module \
--with-http_addition_module --with-cc-opt=-O2 --with-mail_ssl_module \
--with-pcre-jit --with-http_geoip_module --with-http_gzip_static_module \
--with-http_image_filter_module --with-http_sub_module --with-http_xslt_module \
--with-stream --with-stream_ssl_module --with-http_ssl_module --with-luajit \
--with-ld-opt="-Wl,-rpath,/usr/local/lib"
... / configure -- help 를 사용 하여 더 많은 옵션 을 보십시오.
설정 파일 (... / configure script) 이 잘못 되 었 습 니 다. build/nginx-VERSION/objs/autoconf.err 찾 아. VERSION OpenResty 버 전 번호 와 대응 해 야 합 니 다. 예 를 들 어 0.8.54.6。
배치
첫 번 째 일반적인 설정 방안
nginx. conf 프로필 수정
cd /usr/local/openresty/nginx/confmv nginx.conf nginx.conf.$(date +%Y%m%d)vim nginx.confworker_processes 1;
error_log logs/error.log;
events {
worker_connections 1024;
}
http {
server {
listen 8080;
location / {
default_type text/html;
content_by_lua '
ngx.say("hello, world
")
';
}
}
}
환경 변수 추가
echo "export PATH=$PATH:/usr/local/openresty/nginx/sbin" >> /etc/profile
source /etc/profile
그리고 openresty 를 시작 합 니 다. 시작 명령 은 nginx 와 일치 합 니 다.
nginx -c /usr/local/openresty/nginx/conf/nginx.conf
시작 후 서비스 확인
ps -ef | grep nginx
웹 서비스 방문
curl http://localhost:8080/
만약 모든 것 이 정상 이 라면, 우 리 는 수출 을 받 아야 한다.
hello, world
웹 서비스 다시 시작
nginx -s reload
두 번 째 lua 설정 방안
lua. conf 프로필 추가
server {
listen 8080;
location / {
default_type text/html;
content_by_lua '
ngx.say("hello, world Lua!
")
';
}
}
nginx. conf 프로필 수정
cd /usr/local/openresty/nginx/confmv nginx.conf nginx.conf.$(date +%Y%m%d)vim nginx.conf
worker_processes 1;
error_log logs/error.log;
events {
worker_connections 1024;
}
http {
#lua , ”;” , ”;;” , /usr/servers/nginx
lua_package_path "/usr/local/openresty/lualib/?.lua;;"; #lua
lua_package_cpath "/usr/local/openresty/lualib/?.so;;"; #c
include lua.conf; #lua.conf nginx.conf
}
환경 변수 추가
echo "export PATH=$PATH:/usr/local/openresty/nginx/sbin" >> /etc/profile
source /etc/profile
그리고 openresty 를 시작 합 니 다. 시작 명령 은 nginx 와 일치 합 니 다.
nginx -c /usr/local/openresty/nginx/conf/nginx.conf
\ # 시작 후 서비스 확인
ps -ef | grep nginx
웹 서비스 방문
curl http://localhost:8080/
만약 모든 것 이 정상 이 라면, 우 리 는 수출 을 받 아야 한다.
hello, world Lua!
lua 코드 파일 설정
lua 코드 를 nginx 설정 에 두 면 lua 코드 가 증가 함 에 따라 설정 파일 이 너무 길 고 유지 하기 어 려 울 수 있 으 므 로 lua 코드 를 외부 파일 로 옮 겨 저장 해 야 합 니 다.
conf 폴 더 에 lua 폴 더 를 만 들 고 lua 파일 을 저장 합 니 다.
mkdir /usr/local/openresty/nginx/conf/lua
test. lua 파일 만 들 기
cd /usr/local/openresty/nginx/conf/luavim test.luangx.say("test lua");
conf / lu. conf 파일 수정
vim /usr/local/openresty/nginx/conf/lua.confserver {
listen 8080;
location / {
default_type text/html;
lua_code_cache off; # lua , ,
content_by_lua_file conf/lua/test.lua; # nginx
}
}
캐 시 를 닫 으 면 다음 과 같은 경 고 를 볼 수 있 습 니 다. (무시 하고 상관 하지 않 습 니 다)
nginx: [alert] lua_code_cache is off; this will hurt performance in /usr/local/openresty/nginx/conf/lua.conf:5
웹 서비스 다시 시작
nginx -s reload
성능 테스트
압력 테스트 도구 ab 설치
yum -y install httpd-tools
압력 테스트
ab -c10 -n50000 http://localhost:8080/
테스트 보고서 상세 설명
Server Software: Apache #
Server Hostname: localhost #
Server Port: 80 #
Document Path: / #
Document Length: 40888 bytes #
Concurrency Level: 10 #
Time taken for tests: 27.300 seconds #
Complete requests: 1000 #
Failed requests: 0 #
Write errors: 0Total transferred: 41054242 bytes # ( header )
HTML transferred: 40888000 bytes #html
Requests per second: 36.63 [#/sec] (mean) # , ,
Time per request: 272.998 [ms] (mean) #
Time per request: 27.300 [ms] (mean, across all concurrent requests)
# ,
Transfer rate: 1468.58 [Kbytes/sec] received #
Connection Times (ms) min mean[+/-sd] median maxConnect: 43 47 2.4 47 53Processing: 189 224 40.7 215 895Waiting: 102 128 38.6 118 794Total: 233 270 41.3 263 945Percentage of the requests served within a certain time (ms) 50% 263 #50% 263ms 66% 271 #66% 271ms 75% 279 #75% 279ms 80% 285 #80% 285ms 90% 303 #90% 303ms 95% 320 #95% 320ms 98% 341 #98% 341ms 99% 373 #99% 373ms 100% 945 (longest request)
8. 스 크 립 트 시작 (Centos 6)
시작 스 크 립 트 추가
vim /etc/init.d/openresty
스 크 립 트 내용 은 다음 과 같 습 니 다.
#!/bin/sh#
# openresty - this script starts and stops the openresty daemin
#
# chkconfig: - 85 15# description: OpenResty is a full-fledged web platform that integrates \
# the standard Nginx core, LuaJIT, many carefully written Lua libraries, \
# lots of high quality 3rd-party Nginx modules, and most of their external dependencies.
# processname: openresty
# config: /usr/local/openresty/nginx/conf/nginx.conf# pidfile: /usr/local/openresty/nginx/logs/nginx.pid
# Url http://www.cnblogs.com/wushuaishuai/
# Last Updated 2018.07.15# Source function library.. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0nginx="/usr/local/openresty/nginx/sbin/nginx"prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/openresty/nginx/conf/nginx.conf"NGINX_PID="/usr/local/openresty/nginx/logs/nginx.pid"[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$? echo
#service php-fpm start
[ $retval -eq 0 ] && touch $lockfile return $retval
}stop() { echo -n $"Stopping $prog: "
$nginx -s stop
echo_success
retval=$? echo
#service php-fpm stop
[ $retval -eq 0 ] && rm -f $lockfile return $retval
}
restart() { stop
start
}
reload() {
configtest || return $? echo -n $"Reloading $prog: "
$nginx -s reload
RETVAL=$? echo}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1}
case "$1" in
start)
rh_status_q && exit 0
$1
;; stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*) echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2esac
실행 권한 부여
chmod u+x /etc/init.d/openrest
9. 스 크 립 트 시작 (Centos 7)
시작 스 크 립 트 추가
vim /usr/lib/systemd/system/nginx.service
스 크 립 트 내용 은 다음 과 같 습 니 다.
[Service]
Type=forking
PIDFile=/usr/local/openresty/nginx/logs/nginx.pid
ExecStartPre=/usr/local/openresty/nginx/sbin/nginx -t
ExecStart=/usr/local/openresty/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
로 딩 설정:
systemctl daemon-reload
가입 시작:
systemctl enable openresty.service
시작 | 다시 시작 | 닫 기:
# openresty
systemctl start openresty.service
# openresty
systemctl status openresty.service
# openresty
systemctl restart openresty.service
# openresty
systemctl stop openresty.service
# openresty
systemctl disable openresty.service
참고 자료
OpenResty (Nginx + Lua) 개발 디 렉 터 리 스티커 배 워 주세요.
다음으로 전송:https://blog.51cto.com/qiangsh/1842944
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
셸 입문 부터 정통 한 for 순환 및 6 가지 난수 생 성 법순환 용 1. [문법 구조] 2. 문법 linux 에서 무 작위 수 를 만 드 는 여섯 가지 방법 방법 1: 방법 2: openssl 을 통 해 난수 생 성 방법 3: date 시간 을 통 해 얻 을 수 있 습 니 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.