17_ installation and deployment Tomcat server, using Tomcat deploy virtual host, using Web acceleration Varnish

1. Install Tomcat server deployment
official website: HTTPS: //tomcat.apache.org/

Proxy 10.10.11.10
Client 10.10.11.11
web1 10.10.11.12
web2 10.10.11.13

web1:
1.1 using JDK RPM installation environment
] # yum -y install java- openjdk-1.8.0
] # yum -y install the Java-1.8.0-openjdk-headless
] # # View JAVA version of the Java -version
openjdk version "1.8.0_222-ea"
the openJDK Runtime Environment (Build 1.8.0_222-ea-B03 )
the OpenJDK the VM 64-Bit Server (Build-B03 25.222, Mixed MODE)

1.2 installation package apache-tomcat-9.0.30
] # Music Videos apache-tomcat-9.0.30 / usr / local / Tomcat
] # LS / usr / local / Tomcat
bin / # main program directory
lib / # library directory
logs / # log directory  
temp / # temporary directory
work / # directory automatically compiled jsp transcoding the servlet
conf / # configuration file directory
webapps / # // page catalog
] # /usr/local/tomcat/bin/startup.sh LN -s / sbin /
] # LN -s / usr /local/tomcat/bin/shutdown.sh / sbin /

Tip:
If the inspection port, the port 8005 to start very slowly,
can be used using the following command urandom Alternatively random (non-essential operation)
] # Music Videos / dev / Random / dev / random.bak
] # LN -s / dev / urandom / dev / Random
] # startup.sh
] # netstat -nutlp | grep the Java (8005 must be open)
tcp6 0 0 ::: 8080 ::: * LISTEN 12448 / the Java          
0 0 127.0.0.1:8005 ::: * tcp6 LISTEN 12448 / the Java          
tcp6 0 0 ::: 8009 ::: * LISTEN 12448 / the Java          
 
Proxy test whether open tomcat home :()
] # Firefox HTTP: //10.10. 11.12: 8080

1.3 modify Tomcat configuration file to create a test JSP page
] Vim /usr/local/tomcat/webapps/ROOT/test.jsp #
<HTML>
   <body>
        <Center>
Now Time IS: <% = new new java.util.Date ()%> // display server current time
        < / Center>
   </ body>
</ HTML>
] # shutdown.sh
] # startup.sh
] # netstat -nutlp | grep the Java
Proxy test: (jsp page)
] # Firefox http://10.10.11.12:8080/test .jsp
 
2. use deploy Tomcat Hosting requirements:
#############################
achieve two name-based virtual hosting, domain name respectively: www.a.com and www.b.com
use www.a.com domain name to access a page root path is / usr / local / tomcat / a / rOOT
use www.b.com domain names to the root path of the page / usr / local / tomcat / b / base
access www.a.com / time test, the page automatically jump to the / var / www / html page in the catalog
to support SSL encrypted communication when the page is accessed
the private key, the certificate store path is / usr / local / tomcat / conf / cert
each virtual host has independent access log file
Configuring tomcat cluster environment
#############################
2.1 modify server.xml configuration file, create a virtual host two domain name
] # /usr/local/tomcat/conf/server.xml Vim
...
<the Host name = "www.a.com" the appBase = "A" = unpackWARs "to true" the autoDeploy = "to true"> </ the Host>
<the Host name = "www.b.com" the appBase = "B" = unpackWARs "to true" the autoDeploy = "to true"> </ the host>
<the host name = "localhost" ...
2.1.1 create a virtual page corresponding to a host root
] mkdir -p # / usr / local / Tomcat / {A, B} / the ROOT
] # echo "the AAA"> /usr/local/tomcat/a/ROOT/index.html
] # echo "the BBB"> / usr / local /tomcat/b/ROOT/index.html
2.1.2 restart Tomcat server
] # shutdown.sh
] # the Startup.SH
] # netstat -nutlp | grep the Java
2.1.3 client settings host file and view the test page for testing (proxy acts as a client role)
] # vim / etc / hosts
...
Www.a.com www.b.com 10.10.11.12
] # Firefox http://www.a.com:8080/
] # http://www.b.com:8080/ Firefox
 
2.2 modify www.b.com the site home directory Base
] # vim /usr/local/tomcat/conf/server.xml
amended as:
<Host name = "www.b.com" the appBase = "b" = unpackWARs "to true" autoDeploy = "to true" > <the Context path = "" the docBase = "Base" /> </ the Host>
] # mkdir / usr / local / Tomcat / B / Base
] # echo "BASE"> / usr / local / Tomcat / B / Base / index .html
restart Tomcat server
] # shutdown.sh
] # startup.sh
] # netstat -nutlp | grep the Java
test page to see if the correct (proxy acts as a client role)
# http://www.b.com:8080/ Firefox
 
2.3 Jump
when users visit http: //www.a.com / test open page under / var / www / html directory
] # vim /usr/local/tomcat/conf/server.xml
amended as follows:
<Host name = "www.a.com" appBase = "a" unpackWARS = "true" autoDeploy = "true"> <Context path = "/ test" docBase = "/ var / www / html /" /> </ Host>
restart Tomcat server

] # mkdir -p / var / the WWW / HTML
] # echo "the WWW"> /var/www/html/index.html
] # shutdown.sh
] # startup.sh
] # netstat -nutlp | grep java
 
test to see whether the page is correct (proxy acts as a client role)
] # Firefox http://www.a.com:8080/test
 
configure Tomcat to support SSL encrypted site 2.4
2.4.1 create a private key and certificate file encryption used
] # keytool -genkeypair -alias tomcat -keyalg RSA -validity 36500 -storepass 123456 -keystore / usr / local / tomcat / keystore
your first and last name What is?
  [Unknown]: www.a.com
(just fill in the other, finally)
CN = www.a.com, OU = s, O = Unknown, L = s, ST = s, C = cn correct?
  [NO]:Y

# -genkeypair generate a key pair
# -Alias tomcat key alias
# -validity 36500 certificate is valid, 36,500 days, or 100 years
# -storepass 123456 certificate password
# -keyalg RSA key algorithm is defined as the RSA algorithm
# -keystore define the key file is stored in: / usr / local / Tomcat / the keystore
] # LS / usr / local / Tomcat / the keystore
/ usr / local / Tomcat / the keystore

view items in the key:
Tomcat] # the keytool -list -keystore the keystore
enter the keystore password:  
key database type : jks
keystore provider: SUN
your keystore contains an entry
tomcat, 2020-1-7, PrivateKeyEntry,
certificate fingerprint (SHA1): 5E: 64: 53: 1A: 6E: 67: 6A: 26: E9: 96: 2A: 3A: 9E: F6: D6: 40: A7: 82: F4: 92

The certificate key derivation keystore.cer
Tomcat] # -exportcert the keytool -alias -file ./keystore.cer Tomcat -storepass 123456 -keystore keystore -v

will just copy the generated key store file to your tomcat's conf directory, with the same level server.xml.
Note: This must be placed under the conf directory you actually run the tomcat.
conf] # LS the keystore
the keystore

2.4.2 modify server.xml configuration file, create a support Connector encrypted connection
] # vim /usr/local/tomcat/conf/server.xml

Open this comment:
<Connector Port = "8443" Protocol = "org.apache.coyote.http11.Http11NioProtocol" the maxThreads = "150" = SSLEnabled "to true">
    <SSLHostConfig>
        <Certificate certificateKeystoreFile = "the conf / localhost-rsa.jks" type = "the RSA" />
    </ SSLHostConfig>
</ Connector>

insert secret key information
<Connector Port = "8443" Protocol = "org.apache.coyote.http11.Http11NioProtocol" the maxThreads = "150" = SSLEnabled "to true" scheme = "HTTPS" Secure = "to true">
    <
        <Certificate certificateKeystoreFile = "conf / the keystore" certificateKeystorePassword = "123456" of the type = "RSA" />
    </ SSLHostConfig>
</ Connector>

Restart Tomcat server
] # shutdown.sh
] # startup.sh
] # netstat -nutlp | grep the Java
It adds a: 8443 port
tcp6 0 0 ::: 8443 ::: * LISTEN 12546 / the Java
 
Proxy access test :( add trust)
] # Firefox https://www.a.com:8443/
this time will keystore.cer import windows system, install the certificate trust.

2.5 Configuring Tomcat log
set a different log file for each virtual host
] # vim /usr/local/tomcat/conf/server.xml
entire value replicate virtual host, inserted into each site inside the host,
modifying the prefix = a__access_log www.a.com
modified www.b.com = b__access_log the prefix
...
<Valve className = "org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix = "localhost_access_log" suffix = "TXT."
               pattern = "% H% L% U% T & quot;% R & lt & quot;% S% B" />
</ the Host>

restart Tomcat server
] # the shutdown.sh
] # Startup. SH
] # netstat -nutlp | grep the Java
view the server log file:
] # LS / usr / local / Tomcat / logs /
a_access_log.2020-01-07.txt
b_access_log.2020-01-07.txt

Guess you like

Origin www.cnblogs.com/luwei0915/p/12164320.html