Basic experiment of deploying tomcat

实验环境:tomcat服务器部署

lab environment;

  1. tomcat server 1
    192.168.10.1

experiment procedure

1. Install JDK environment:
1) Set ip, disable iptables, selinux, etc.
2) Install JDK and configure.
If there is a java environment in the system, you need to uninstall it first
[root@localhost ~]# yum remove java -y

[root@localhost ~]# tar xf jdk-8u91-linux-x64.tar.gz

[ root @ localhost ~ ] # mv jdk1 .8.0_91 / / usr / local / java

Edit java script
[root@localhost ~]# vim /etc/profile.d/java.sh


#Set the java root directory

export JAVA_HOME=/usr/local/java

#Add the bin subdirectory under the java root directory to the path environment variable

export PATH= P A T H : PATH: PATH:JAVA_HOME/bin

[root@localhost ~]# source /etc/profile.d/java.sh

[root@localhost ~]# echo $PATH

Check whether the running version of java is consistent
[root@localhost ~]# java -version

java version “1.8.0_91”
Java™ SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot™ 64-Bit Server VM (build 25.91-b14, mixed mode)

2. Install and configure tomcat:

1) Install tomcat:
[root@localhost ~]# tar xf apache-tomcat-8.5.16.tar.gz

[root@localhost ~]# mv apache-tomcat-8.5.16 /usr/local/tomcat

##Start apache-tomcat
[root@localhost ~]# /usr/local/tomcat/bin/startup.sh

Command to shut down tomcat: /usr/local/tomcat/bin/shutdown.sh

[root@localhost ~]# netstat -anpt |grep 8080 ##Verify

[root@localhost ~]# yum -y install elinks

[root@localhost ~]# elinks --dump http://192.168.10.1:8080

[root@localhost ~]# yum -y install tree

[root@localhost ~]# cd /usr/local/tomcat/

[root@localhost tomcat]# ls

bin lib logs RELEASE-NOTES temp work
conf LICENSE NOTICE RUNNING.txt webapps

Configure tomcat: main file directory ************

a. Main directory:
bin/: management script file
conf/: configuration file
logs: log file
webapps/: Web publishing directory
work/: stores class files generated after jsp compilation

b. Configuration file: conf/
catalina.policy: permission control
catalina.properies: property configuration file
context.xml: context configuration file
logging.properies: log related configuration file
server.xml: main configuration file
tomcat-users.xml: manager -gui manages user configuration files (backend management interface)
web.xml: tomcat's servlate, servlet-mapping, filter, MIME and other configurations

c.server.xml: Tomcat’s main configuration file, managing Tomcat’s startup port, website directory, virtual host, enabling https, etc.


[root@localhost tomcat]# tree conf/

conf/
├── Catalina
│?? └── localhost
├── catalina.policy
├── catalina.properties
├── context.xml
├── jaspic-providers.xml
├── jaspic-providers.xsd
├── logging.properties
├── server.xml
├── tomcat-users.xml
├── tomcat-users.xsd
└── web.xml

Frequently modified parts of the configuration file
[root@localhost tomcat]# vim /usr/local/tomcat/conf/server.xml


##Close the port. By default, it is only open to the local address
22.

##Start port
69 <Connector port="8080" protocol="HTTP/1.1"
70 connectionTimeout="20000"
71 redirectPort="8443" />

The default port number when starting the AJP 1.3 connector, and receives requests forwarded by other servers through port 8009.
116

Define the configuration of the virtual host
148 <Host name="localhost" appBase="webapps"
149 unpackWARs="true" autoDeploy="true">

Define the configuration of the virtual host log
160 <Valve className="org.apache.catalina.valves.Acce ssLogValve" directory="logs"
161 prefix="localhost_access_log" suffix=".txt "
162 pattern="%h %l %u %t "%r" %s %b" />

Add a custom directory as the web document directory:

[root@localhost ~]# mkdir -pv /web/webapp1

Write a test page:
[root@localhost ~]# vim /web/webapp1/index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

JSP test1 page <% out.println("Welcome to test1 site;http://192.168.10.1");%> .....................

Edit the tomcat main configuration file, define the virtual host, point to the test directory, and add the context field

[root@localhost ~]# vim /usr/local/tomcat/conf/server.xml


.............................docBase ##Web application document base directory path ##Set the default class reloadable ##Set to monitor whether the 'class' changes

Restart tomcat
[root@localhost ~]# /usr/local/tomcat/bin/shutdown.sh
[root@localhost ~]# /usr/local/tomcat/bin/startup.sh

Access test:
access in win7 client:
http://192.168.10.1:8080

实验(二) nginx + tomcat负载均衡集群

lab environment:

  1. tomcat server 1
    192.168.10.1

2.tomcat2 server 2

192.168.10.2

  1. nginx server

192.168.10.3

experiment procedure:

1. Based on Experiment 1, the deployment process of tomcat2 and tomcat1 is the same. You only need to modify the relevant configuration files.

Write a test page:
[root@localhost ~]# vim /web/webapp1/index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

JSP test2 page <% out.println("Welcome to test2 site;http://192.168.10.2");%> .....................

Like tomcat1, restart the service after the deployment is completed, and access the test on the client computer

2. Install the front-end nginx server

yum -y install pcre-devel zlib-devel openssl-devel

groupadd www

useradd -g www -s /bin/false www


The difference between /bin/false and /sbin/nologin
/bin/false is the most stringent login option, and all services cannot be used.
/sbin/nologin only does not allow login to the system


tar xf nginx-1.12.0.tar.gz -C /usr/src/

cd /usr/src/nginx-1.12.0/

./configure --prefix=/usr/local/nginx --user=www --group=www --with-file-aio --with-http_stub_status_module --with-http_gzip_static_module --with-http_flv_module --with-http_ssl_module &&make &&make install


–user=www –group=www Specify the running user and group
–with-file-aio Enable file modification support
–with-http_stub_status_module Enable status statistics
–with-http_gzip_static_module Enable gzip static compression
–with-http_flv_module Enable the flv module, provide Seek memory using time-based offset file
--with-http_ssl_module Enable ssl module
...

vim /usr/local/nginx/conf/nginx.conf
##In http{}:,

34 upstream tomcat_server {
35 server 192.168.10.1:8080 weight=1;
36 server 192.168.10.2:8080 weight=1;
37 }


##Add 46 location / { 47 root html; 48 index index.html index.htm; 49 proxy_pass http://tomcat_server; 50 } in server{ }



/usr/local/nginx/sbin/nginx -t

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

ps aux |grep nginx
netstat -anpt |grep nginx

Verify load balancing:
client access http://192.168.10.3

Refresh access—check whether to switch between tomcat1 and tomcat2

Guess you like

Origin blog.csdn.net/m0_57207884/article/details/119668920