Mac環境でのNginx+Tomcatクラスタ、テストOK
11460 ワード
次の手順に従います.
第一歩:私たちのNginxをインストールして、Macの上でbrewを利用してインストールします;
このステップでは、インストールに成功したことを確認します.
ここにインストールされているのは1.4です.4バージョン
ちなみに、brewがインストールしたファイルパスは、一般的にデフォルトでは次のとおりです.
しかし、nginxの真のパスは:
nginxサーバを起動します.
あなたのパスワードを入力して、起動しても:
これで起動します.簡単でしょ~
nginx起動プロセスを表示する場合
nginxサーバを閉じるには、次の手順に従います.
============今からnginxのインストールを説明するところです.OKですか?
第二歩:私たちは本機に2台のTomcat容器を配置し、正常に走り出す.具体的には、
Tomcatをダウンロードする必要があります.これはTomcatのダウンロード方法を言う必要はないと思います.私は普通公式にtarバッグをダウンロードします.
ダウンロード後、名前を次のように変更します.
私のところはとりあえず2から名前をつけましょう~私の地元にはtomcat-7-1があるので、自分で開発して使います.どうせこれはただのフォルダの名前だから、混同されないはずだ.tomcat-7-2、tomcat-7-3を例に挙げます.
2台のTomcatを同時に起動する必要がある場合は、設定ファイルを変更する必要があります.Tomcatにバインドされているポート番号は唯一ですが、実際にはポート番号が衝突しないようにします.これで2台のTomcatが走れるようになりました.
tomcat-7-2の構成に入ります
serverを開きます.xmlファイル、ここは私たちが配置する必要がある場所で、openコマンドを利用して開いて、とても爽やかなコマンドで、私のここはデフォルトでSublime Text 2に開いて、一般的にデフォルトでVIMになります.
この3つの肝心な場所のportは、よく覚えています.私は今修正して81で始まります.その後のtomcat-7-3は82で始まります.
ここでは、構成が完了しても、異なるtomcatに直接公開する明目を確立したり、直接走ったりすることができます.私は直接発表したwarパッケージです.ROOT.warからwebapp:
2つのTomcatを別々に起動します.これはtomcatのbinディレクトリの下にあります.
OK、私たちは訪問します:私は直接図に行きます:
これは、2台の起動に成功したことを示しています.
ステップ3:nginx構成を変更し、tomcatのジャンプを完了させる:
入力:
その中のnginxを開きます.confファイル:最も基本的なすべてのファイルを貼って参考にします.
注意すべき点:
その後、nginxサーバを再起動します.または、閉じた後に起動します.
最後に入力しますhttp://localhost
ステップ4:別のサーバにジャンプできるかどうかをテストします. tomcat-7-2のJSPページを変更しますが、tomcat-7-3は変更しません.私达はひっきりなしに更新して、私达はしばらく変化があることを见ることができて、しばらく変化しないで、このようにOKを说明しました. tomcat-7-2を停止し、tomcat-7-3は依然として開いていて、依然としてアクセスすることができます. tomcat-7-3を停止し、tomcat-7-2は依然として開いていて、依然としてアクセスすることができます.
これでNginx+Tomcat 7ができたとしても.0クラスタ难しくないでしょう~私も初心者で、みんながレンガを撮るのを忘れました...
第一歩:私たちのNginxをインストールして、Macの上でbrewを利用してインストールします;
[chenyuan@Mac:~]$ brew install nginx
==> Installing nginx dependency: pcre
==> Downloading http://downloads.sourceforge.net/project/pcre/pcre/8.34/pcre-8.3 ######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/pcre/8.34 --enable-utf8 --enable-unic
==> make
==> make test
==> make install /usr/local/Cellar/pcre/8.34: 140 files, 4.1M, built in 58 second>
==> Installing nginx
このステップでは、インストールに成功したことを確認します.
[chenyuan@chenyuan-MBP:~]$ nginx -V
nginx version: nginx/1.4.4
TLS SNI support enabled
configure arguments: --prefix=/usr/local/Cellar/nginx/1.4.4 --with-http_ssl_module --with-pcre --with-ipv6 --sbin-path=/usr/local/Cellar/nginx/1.4.4/bin/nginx --with-cc-opt=-I/usr/local/include --with-ld-opt=-L/usr/local/lib --conf-path=/usr/local/etc/nginx/nginx.conf --pid-path=/usr/local/var/run/nginx.pid --lock-path=/usr/local/var/run/nginx.lock --http-client-body-temp-path=/usr/local/var/run/nginx/client_body_temp --http-proxy-temp-path=/usr/local/var/run/nginx/proxy_temp --http-fastcgi-temp-path=/usr/local/var/run/nginx/fastcgi_temp --http-uwsgi-temp-path=/usr/local/var/run/nginx/uwsgi_temp --http-scgi-temp-path=/usr/local/var/run/nginx/scgi_temp --http-log-path=/usr/local/var/log/nginx/access.log --error-log-path=/usr/local/var/log/nginx/error.log --with-http_gzip_static_module
ここにインストールされているのは1.4です.4バージョン
ちなみに、brewがインストールしたファイルパスは、一般的にデフォルトでは次のとおりです.
[chenyuan@chenyuan-MBP:Cellar]$ pwd
/usr/local/Cellar
しかし、nginxの真のパスは:
[chenyuan@chenyuan-MBP:nginx]$ pwd
/usr/local/etc/nginx
nginxサーバを起動します.
[chenyuan@chenyuan-MBP:~]$ sudo nginx
Password:
nginx: [emerg] bind() to 0.0.0.0:80 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (48: Address already in use)
nginx: [emerg] still could not bind()
あなたのパスワードを入力して、起動しても:
これで起動します.簡単でしょ~
nginx起動プロセスを表示する場合
[chenyuan@chenyuan-MBP:~]$ ps -ef|grep nginx
0 8220 1 0 9:07PM ?? 0:00.00 nginx: master process nginx
502 8322 8220 0 9:34PM ?? 0:00.87 nginx: worker process
502 8323 8220 0 9:34PM ?? 0:00.15 nginx: worker process
502 8704 8598 0 8:27PM ttys000 0:00.00 grep nginx
nginxサーバを閉じるには、次の手順に従います.
[chenyuan@chenyuan-MBP:~]$ sudo nginx -s stop
============今からnginxのインストールを説明するところです.OKですか?
第二歩:私たちは本機に2台のTomcat容器を配置し、正常に走り出す.具体的には、
Tomcatをダウンロードする必要があります.これはTomcatのダウンロード方法を言う必要はないと思います.私は普通公式にtarバッグをダウンロードします.
apache-tomcat-7.0.37
ダウンロード後、名前を次のように変更します.
drwxr-xr-x 16 chenyuan staff 544 Jun 21 18:39 tomcat-7-2
drwxr-xr-x 16 chenyuan staff 544 Jun 21 18:41 tomcat-7-3
私のところはとりあえず2から名前をつけましょう~私の地元にはtomcat-7-1があるので、自分で開発して使います.どうせこれはただのフォルダの名前だから、混同されないはずだ.tomcat-7-2、tomcat-7-3を例に挙げます.
2台のTomcatを同時に起動する必要がある場合は、設定ファイルを変更する必要があります.Tomcatにバインドされているポート番号は唯一ですが、実際にはポート番号が衝突しないようにします.これで2台のTomcatが走れるようになりました.
tomcat-7-2の構成に入ります
[chenyuan@chenyuan-MBP:conf]$ pwd
/Users/chenyuan/Library/tomcat-7-2/conf
[chenyuan@chenyuan-MBP:conf]$ ls -l
total 408
drwxr-xr-x 3 chenyuan staff 102 Jun 21 18:39 Catalina
-rw-r--r-- 1 chenyuan staff 12377 Jun 21 18:39 catalina.policy
-rw-r--r-- 1 chenyuan staff 6528 Jun 21 18:39 catalina.properties
-rw-r--r-- 1 chenyuan staff 1392 Jun 21 18:39 context.xml
-rw-r--r-- 1 chenyuan staff 3352 Jun 21 18:39 logging.properties
-rw-r--r-- 1 chenyuan staff 6455 Jun 21 18:52 server.xml
-rw-r--r-- 1 chenyuan staff 1528 Jun 21 18:39 tomcat-users.xml
-rw-r--r-- 1 chenyuan staff 162892 Jun 21 18:39 web.xml
[chenyuan@chenyuan-MBP:conf]$
serverを開きます.xmlファイル、ここは私たちが配置する必要がある場所で、openコマンドを利用して開いて、とても爽やかなコマンドで、私のここはデフォルトでSublime Text 2に開いて、一般的にデフォルトでVIMになります.
[chenyuan@chenyuan-MBP:conf]$ open server.xml
[chenyuan@chenyuan-MBP:conf]$
<Server port="8105" shutdown="SHUTDOWN">
<Connector URIEncoding="UTF-8" connectionTimeout="20000" port="8180" protocol="HTTP/1.1" redirectPort="8443"/>
<Connector port="8109" protocol="AJP/1.3" redirectPort="8443"/>
この3つの肝心な場所のportは、よく覚えています.私は今修正して81で始まります.その後のtomcat-7-3は82で始まります.
<Server port="8205" shutdown="SHUTDOWN">
<Connector URIEncoding="UTF-8" connectionTimeout="20000" port="8280" protocol="HTTP/1.1" redirectPort="8443"/>
<Connector port="8209" protocol="AJP/1.3" redirectPort="8443"/>
ここでは、構成が完了しても、異なるtomcatに直接公開する明目を確立したり、直接走ったりすることができます.私は直接発表したwarパッケージです.ROOT.warからwebapp:
[chenyuan@chenyuan-MBP:tomcat-7-2]$ cd webapps/
[chenyuan@chenyuan-MBP:webapps]$ ls -l
total 23352
drwxr-xr-x 10 chenyuan staff 340 Jun 21 19:03 ROOT
-rw-r--r-- 1 chenyuan staff 11953340 Jun 21 19:00 ROOT.war
drwxr-xr-x 53 chenyuan staff 1802 Jun 21 18:39 docs
drwxr-xr-x 7 chenyuan staff 238 Jun 21 18:39 examples
drwxr-xr-x 7 chenyuan staff 238 Jun 21 18:39 host-manager
drwxr-xr-x 8 chenyuan staff 272 Jun 21 18:39 manager
[chenyuan@chenyuan-MBP:webapps]$
2つのTomcatを別々に起動します.これはtomcatのbinディレクトリの下にあります.
[chenyuan@chenyuan-MBP:bin]$ sh startup.sh
OK、私たちは訪問します:私は直接図に行きます:
これは、2台の起動に成功したことを示しています.
ステップ3:nginx構成を変更し、tomcatのジャンプを完了させる:
入力:
[chenyuan@chenyuan-MBP:nginx]$ pwd
/usr/local/etc/nginx
その中のnginxを開きます.confファイル:最も基本的なすべてのファイルを貼って参考にします.
user chenyuan staff ;
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 0;
keepalive_timeout 65;
#gzip on;
upstream localhost {
#ip_hash;
server localhost:8180;
server localhost:8280;
}
server {
listen 80;
server_name localhost;
charset utf-8;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
proxy_pass http://localhost;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect HOST default;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443;
# server_name localhost;
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_timeout 5m;
# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
#include /usr/local/etc/nginx/conf.d/*.conf;
}
注意すべき点:
upstream localhost {
#ip_hash;
server localhost:8180;
server localhost:8280;
}
location / {
root html;
index index.html index.htm;
proxy_pass http://localhost;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect HOST default;
}
その後、nginxサーバを再起動します.または、閉じた後に起動します.
最後に入力しますhttp://localhost
ステップ4:別のサーバにジャンプできるかどうかをテストします.
これでNginx+Tomcat 7ができたとしても.0クラスタ难しくないでしょう~私も初心者で、みんながレンガを撮るのを忘れました...