nginx 설치 와 부하 균형

5578 단어
rewrite 와 upstream 이 nginx 의 포인트 입 니 다.
1, 컴 파일 nginx 1.4.5
./configure --help
  --prefix=PATH                      set installation prefix
--user=USER                        set non-privileged user for worker processes
--group=GROUP                      set non-privileged group forworker processes
--with-http_ssl_module             enable ngx_http_ssl_module
--with-http_stub_status_module     enable ngx_http_stub_status_module     ---지원 모니터링
--with-http_gzip_static_module     enable ngx_http_gzip_static_module     ---압축 지원
/ / 컴 파일 매개 변수
./configure --prefix=/usr/local/nginx --user=apache --group=apache --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module 
 make && make install

2.start nginx
 /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 
 netstat -ntlp|grep nginx
tcp        0      0 0.0.0.0:80         0.0.0.0:*     LISTEN      7539/nginx

3. 닫 기
cat /usr/local/nginx/logs/nginx.pid | xargs kill -TERM

다시 시작
 cat /usr/local/nginx/logs/nginx.pid | xargs kill -HUP

HUP      다시 시작
TERM, INT 빠 른 정지
USR1    로그 파일 을 다시 열 어 로그 절단 에 사용 합 니 다.
USR2    부 드 러 운 업그레이드 실행 가능 프로그램
QUIT     침착하게 폐쇄 하 다
WINCH    작업 프로 세 스 를 여 유 롭 게 닫 습 니 다.
/ / 테스트 프로필
 /usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
nginx 프로필 형식:
user  apache apache;
worker_processes  2;   ---cpu 핵 - 1
....
event{}
http{
....
upstream {}
server{}
}
#######################
1. IP 기반 가상 호스트
/ / 프로필 수정
vim /usr/local/nginx/cong/nginx.conf
 server {
        listen       10.10.54.231:80;
        server_name  10.10.54.231;
        root /var/www/html;
        charset utf-8;
        access_log  logs/www.access.log  main;
        location / {
            index  index.html index.htm;
        }
}
/ / IP 주소 추가
ifconfig eth0:0 10.10.54.231 netmask 255.255.255.0
2. 도 메 인 이름 기반 가상 호스트
http{
......
    server {
        listen       80;
        server_name  www.nclub.com;
        charset utf-8;
        access_log  logs/www.access.log  main;
        location / {
            index  index.html index.htm;
            root /var/www/html;
        }
    }
    server {
        listen 80;
        server_name bbs.nclub.com;
        location / {
        root /var/www/bbs;
        index index.html;
        access_log logs/bbs.nclub.com.log;
        }
    }
}
3. tomcat 설치
[root@s01 jdk]# tar xvf apache-tomcat-7.0.52.tar.gz 
[root@s01 jdk]# mv apache-tomcat-7.0.52 /usr/local/tomcat
/ / tomcat 에 JAVA 홈 디 렉 터 리 추가
[root@s01 bin]# vim /usr/local/tomcat/bin/catalina.sh    ---96 줄
JAVA_HOME=/usr/java/jdk1.7.0_51
CATALINA_HOME=/usr/local/tomcat
/ / 자동 시작 스 크 립 트 만 들 기
[root@s01 bin]# cp catalina.sh /etc/init.d/tomcat
[root@s01 bin]# chmod +x /etc/init.d/tomcat 
[root@s01 bin]# vim /etc/init.d/tomcat 
[root@s01 bin]# chkconfig --add tomcat
/ / tomcat 설정 사용자 관리
[root@s01 conf]# pwd
/usr/local/tomcat/conf
[root@s01 conf]# vim tomcat-users.xml 
 
 
 
4. nginx 부하 균형
/ / 프로필
vim /usr/local/nginx/conf/virtual/www.nclub.com.conf
user  apache apache;
worker_processes  2;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
error_log  logs/error.log  info;
pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  logs/access.log  main;
    sendfile        on;
    tcp_nopush     on;
    keepalive_timeout  65;
    gzip  on;
include virtual/www.nclub.com.conf;
}
/ / 프로필
vim /usr/local/nginx/conf/virtual/www.nclub.com.conf
upstream www_nclub_com {
    server 10.10.54.222:10080 max_fails=3 weight=1 fail_timeout=60s;
    server 10.10.54.226:8090 max_fails=3 weight=2 fail_timeout=60s;
    }
server {
    listen       80;
    server_name  www.nclub.com;
    charset utf-8;
    access_log  logs/www.access.log  main;
    index index.html;
    location / {
        proxy_pass http://www_nclub_com;
        proxy_set_header HOST $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }
######################
./configure --prefix=/usr/local/nginx --user=apache --group=apache --with-http_stub_status_module   --with-http_gzip_static_module --with-http_ssl_module
make
make install

좋은 웹페이지 즐겨찾기