195.203.1.1 安装tomcat nginx
195.203.1.2 安装tomcat nginx
195.203.1.3 安装tomcat
195.203.1.4安装tomcat
(1)首先安装tomcat
(2)解压tomcat
[root@localhost tomcat]# tar -xzvf apache-tomcat-6.0.48.tar.gz
(3)将tomcat重命名
[root@localhost tomcat]# mv apache-tomcat-6.0.48 tomcat6.0
(4)启动tomcat
[root@localhost bin]# ./startup.sh
(5)验证tomcat是否已经被成功安装。
curl http://localhost:8080/index.html
页面出现tomcat首页的内容,tomcat安装成功!
[同理在其他的三台服务器上面安装tomcat]
添加用户组 和用户
groupadd nginx
useradd -g nginx nginx
然后安装nginx
(1)将nginx安装包放到/usr/local 目录下
(2)将其解压
(3)tar -zxvf nginx-1.10.2.tar.gz
(4)将nginx-1.10.2.tar.gz重命名
(5)mv nginx-1.10.2.tar.gz nginx
(6)进入nginx目录下
(7)进入conf目录下将nginx.conf移动到nginx目录下然后对其进行修改
(8)修改内容如下:
user nginx nginx;
worker_processses 2;
errpr_log /usr/local/nginx/logs/nginx_error.log;
pid /usr/local/nginx/logs/nginx.pid;
events{
worker_connections 65535;
}
然后将server里面的servername改为与之相对应的IP
(9)然后进行初始化配置
(10)./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_sslmodule --with-http_sub_module --with-http_stub_status_module
此时可能会遇到的问题:
||cp conf/nginx.conf 'user/local/nginx/conf/' cp :'conf/nginx.conf' and 'user/local/nginx/conf/nginx.conf' are the sane file
则可以输入以下内容:
(11)./configure --prefix =/usr/local/nginx/ --conf-path=/usr/local/nginx/nginx.conf
(12)make
(13)make install
(14)然后启动nginx
(15)进入/nginx/sbin 目录下
(16)./nginx
(17)此时可能遇到的问题是:
./nginx:error while loading shared libraries:libpre.so.1 accnot open shared object file :No such file or directory
如果出现以上问题则解决方法如下:
建立软链接:ln -s /usr/local/lib/libpre.so.1 /lib64/
(18)再次启动nginx ./nginx 启动nginx成功
(19)访问nginx
(20)curl http://localhost:80/
(21)即可以出现nginx的欢迎页面
注意:启动nginx命令:./nginx 关闭nginx命令:./nginx -s stop
这样tomcat和nginx都安装成功。
开始配置nginx和tomcat的负载均衡
(1)这里只需要修改/nginx 目录下的nginx.conf 配置文件即可。
(2)配置内容如下:
(3)在http的大括号里面的access_log下面加上以下内容:
upstream tomcats{
server 198.203.180.46:8080;
server 198.203.180.47:8080;
server 198.203.180.48:8080;
server 198.203.180.49:8080;
}
(4)然后在location /{}里加入以下内容:
root html;
index index.html index.htm;
proxy_pass http://tomcats;
proxy_redirect default;
(5)到此为止负载均衡配置完成。
(6)此时将四台服务器的tomcat都开启,然后开启两台nginx。
然后在nginx服务器上面分别访问
curl http://localhost/
就可以随机访问四台tomcat的欢迎页面了。