#文件准备 ##nginx: [nginx-1.10.3.tar.gz](http://nginx.org/download/nginx-1.10.3.tar.gz) ##tomcat8: [apache-tomcat-8.0.43.zip](http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.0.43/bin/apache-tomcat-8.0.43.zip) ##redis: [redis-3.2.8.tar.gz](http://download.redis.io/releases/redis-3.2.8.tar.gz) ##ruby(当使用redis cluster时需要): [ruby-2.4.1.tar.gz](https://cache.ruby-lang.org/pub/ruby/2.4/ruby-2.4.1.tar.gz) ##TomcatRedisSessionManager(From [GitHub](https://github.com/ran-jit/TomcatClusterRedisSessionManager)): [TomcatRedisSessionManager-1.1.1.zip](https://github.com/ran-jit/TomcatClusterRedisSessionManager/releases/download/1.1.1/TomcatRedisSessionManager-1.1.1.zip) ##jdk :[jdk-8u131-linux-x64.tar.gz](http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz)
#环境安装 >**PS:建议将所有文件下载后上传至/usr/local/src ;若无其他说明,本教程所有操作均以/usr/local/src作为起手目录**
##redis
``` tar -zxvf redis-3.2.8.tar.gz cd redis-3.2.8 make ``` >建议安装后, 将redis移动到/usr/local/redis3.2或相似的好记的目录,方便后续操作 安装后查看是否安装成功
``` cd src ./redis-server ../redis.conf ``` 具体参考: [redis安装|菜鸟教程](http://www.runoob.com/redis/redis-install.html) ##nginx ``` yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz tar zxvf pcre-8.35.tar.gz cd pcre-8.35 ./configure make && make install tar -zxvf nginx-1.10.3.tar.gz
cd nginx-1.10.3
./confignre --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35
make && make install ```
安装完成后,进入sbin目录, 输入
`nginx -s start ` 默认端口80,尝试访问 >nginx源码安装较为复杂,参考网上完整安装教程: [Nginx安装配置 | 菜鸟教程](http://www.runoob.com/linux/nginx-install-setup.html)
##tomcat
```
tar -zxvf apache-tomcat-8.0.43.zip cd apache-tomcat-8.0.43 cd bin ./startup.sh ```
解压即安装,启动后默认端口为8080, 自行测试server是否正常开启,若失败,尝试以下命令 ```
systemctl stop firewalld systemctl stop iptabled
```
#nginx+tomcat集群搭建
##复制一份tomcat8
```
mv apache-tomcat-8.0.43 /usr/local/tomcat8/8081 cp /usr/local/tomcat8/8081 /usr/local/tomcat8/8082
```
##修改tomcat的启动及关闭端口
###更改配置文件 ####tomcat/conf/server.xml 更改关闭端口,例如8005->8015
```
.....
```
更改启动端口,例如8080->8081
```
```
##配置nginx
###nginx.conf
```
#user nobody; worker_processes 1; #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 tomcatcluster{ server 127.0.0.1:8081 weight=1; server 127.0.0.1:8082 weight=1; } server { listen 80; server_name localhost; charset utf-8;
#access_log logs/host.access.log main; location / { proxy_pass http://tomcatcluster; proxy_redirect 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; } } }
```
其中核心是 >upstream tomcatcluster{ server 127.0.0.1:8081 weight=1; server 127.0.0.1:8082 weight=1; } 定义一个upstream 标识为tomcatcluster; server:定义一个服务器 ip:port:指定URL weight:权重, 越大 >location / { proxy_pass http://tomcatcluster; proxy_redirect default; } http:// 后接upstream指定的标识 ,如 tomcatcluster
##启动nginx 进入nginx目录, 比如我的/usr/local/nginx ``` cd /usr/local/nignx cd sbin ./nginx -s start ``` 启动前可使用` nignx -t` 检验配置文件是否错误. 浏览器访问80端口, 若无意外, 则显示tomcat的欢迎界面,于是为tomcat添加项目 ##修改tomcat/webapps/ROOT ``` cd /usr/local/tomcat8/8081 cd webapps/ROOT rm -rf * vi index.jsp ``` 输入以下内容: ```