nginx+tomcat架构实战

1、基础环境优化

1.安装 EPEL 仓库和常用命令

rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
yum install -y net-tools vim wget lrzsz tree screen lsof tcpdump

2.关闭 NetworkManager 和防火墙

systemctl disable firewalld
systemctl disable NetworkManager

3.关闭SELinux并确认处于关闭状态

sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
grep SELINUX=disabled /etc/selinux/config
setenforce 0

4.调整文件描述符

echo '* - nofile 100000 ' >>/etc/security/limits.conf

2、安装nginx

1、安装依赖包

yum -y install gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel

2、下载软件包

wget http://nginx.org/download/nginx-1.10.3.tar.gz

3、编译安装nginx

useradd nginx -s /sbin/nologin -M
tar xf nginx-1.10.3.tar.gz
cd nginx-1.10.3
./configure
make && make install
cd /usr/local/nginx/sbin

4、环境变量设置

[root@localhost nginx]# vim /etc/profile.d/nginx.s
export PATH=$PATH:/usr/local/nginx/sbin

5、启动、重载、停止

/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx  start
/usr/local/nginx/sbin/nginx -s reload

3、安装tomact

3.1 软件准备

http://pan.baidu.com/s/1IpioA

下载相关软件包

3.2部署java环境

[root@tomcat ~]# cd /application/tools/

[root@tomcat tools]# rz
rz waiting to receive.
Starting zmodem transfer.  Press Ctrl+C to cancel.
Transferring apache-tomcat-8.0.27.tar.gz...
  100%    8914 KB    8914 KB/sec    00:00:01       0 Errors  
Transferring jdk-8u60-linux-x64.tar.gz...
  100%  176990 KB    14749 KB/sec    00:00:12       0 Errors  

tar xf jdk-8u60-linux-x64.tar.gz -C /application/

ln -s /application/jdk1.8.0_60 /application/jdk

sed -i.ori '$a export JAVA_HOME=/application/jdk\nexport PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH\nexport CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar' /etc/profile

source /etc/profile

#→出现下面结果证明部署成功
[root@tomcat ~]# java -version
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

3.3安装Tomcat

tar xf apache-tomcat-8.0.27.tar.gz -C /application/

ln -s /application/apache-tomcat-8.0.27 /application/tomcat

echo 'export TOMCAT_HOME=/application/tomcat'>>/etc/profile

source /etc/profile

chown -R root.root /application/jdk/ /application/tomcat/

[root@tomcat ~]# tail -4 /etc/profile
export JAVA_HOME=/application/jdk
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar
export TOMCAT_HOME=/application/tomcat

3.4 启动Tomcat

#→启动程序/application/tomcat/bin/startup.sh
#→关闭程序/application/tomcat/bin/shutdown.sh

[root@tomcat ~]# /application/tomcat/bin/startup.sh
Using CATALINA_BASE:   /application/tomcat
Using CATALINA_HOME:   /application/tomcat
Using CATALINA_TMPDIR: /application/tomcat/temp
Using JRE_HOME:        /application/jdk
Using CLASSPATH:       /application/tomcat/bin/bootstrap.jar:/application/tomcat/bin/tomcat-juli.jar
Tomcat started.

[root@tomcat ~]# netstat -tunlp|grep java
tcp        0      0 :::8009                     :::*                        LISTEN      4743/java           
tcp        0      0 :::8080                     :::*                        LISTEN      4743/java           

[root@tomcat ~]# ps -ef|grep [j]ava
root       4743      1 17 06:10 pts/0    00:00:03 /application/jdk/bin/java -Djava.util.logging.config.file=/application/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/application/tomcat/endorsed -classpath /application/tomcat/bin/bootstrap.jar:/application/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/application/tomcat -Dcatalina.home=/application/tomcat -Djava.io.tmpdir=/application/tomcat/temp org.apache.catalina.startup.Bootstrap start

4、nginx配置

upstream配置
 upstream backend {
   server 192.168.118.16:8080 ;
   server 192.168.118.17:8080 ;
   }
proxy模块配置
location /bbs {
    #root   html;
    proxy_pass http://backend/;
    index  index.html index.htm;

5、tomcat配置

/application/tomcat/webapps/ROOT
mv * /tmp/
vim index.jsp

  

posted @ 2018-03-28 16:45  活的潇洒80  阅读(403)  评论(0编辑  收藏  举报