Article Directory
1. Install JDK&Tomcat
Turn off the firewall and selinux
安装Tomcat & JDK
安装时候选择tomcat软件版本要与程序开发使用的版本一致。jdk版本要进行与tomcat保持一致。
###### 1、系统环境说明
关闭防火墙和selinux
```shell
[root@java-tomcat1 ~]# getenforce
Disabled
[root@java-tomcat1 ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
Install JDK
上传jdk1.8到服务器。安装jdk
[root@java-tomcat1 ~]# tar xzf jdk-8u191-linux-x64.tar.gz -C /usr/local/
[root@java-tomcat1 ~]# cd /usr/local/
[root@java-tomcat1 local]# mv jdk1.8.0_191/ java
设置环境变量:
[root@java-tomcat1 local]# vim /etc/profile.d/jdk.sh
export JAVA_HOME=/usr/local/java #指定java安装目录
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH #用于指定java系统查找命令的路径
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar #类的路径,在编译运行java程序时,如果有调用到其他类的时候,在classpath中寻找需要的类。
检测JDK是否安装成功:
[root@java-tomcat1 local]# source /etc/profile.d/jdk.sh
[root@java-tomcat1 local]# java -version
java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)
Install Tomcat
[root@java-tomcat1 ~]# mkdir /data/application -p
[root@java-tomcat1 ~]# cd /usr/src/
[root@java-tomcat1 src]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.49/bin/apache-tomcat-8.5.49.tar.gz
[root@java-tomcat1 src]# tar xzf apache-tomcat-8.5.49.tar.gz -C /data/application/
[root@java-tomcat1 src]# cd /data/application/
[root@java-tomcat1 application]# mv apache-tomcat-8.5.49/ tomcat
设置环境变量:
[root@java-tomcat1 application]# vim /etc/profile
#这里没有把Tomcat的启动、关闭命令、添加到环境变量里面,原因是方便给实现多实例部署
export TOMCAT_HOME=/data/application/tomcat #指定tomcat的安装目录
[root@java-tomcat1 application]# source /etc/profile
查看tomcat是否安装成功:
[root@java-tomcat1 tomcat]# /data/application/tomcat/bin/version.sh
Using CATALINA_BASE: /data/application/tomcat
Using CATALINA_HOME: /data/application/tomcat
Using CATALINA_TMPDIR: /data/application/tomcat/temp
Using JRE_HOME: /usr/local/jdk
Using CLASSPATH: /data/application/tomcat/bin/bootstrap.jar:/data/application/tomcat/bin/tomcat-juli.jar
Server version: Apache Tomcat/8.5.49
Server built: Nov 17 2019 18:45:30 UTC
Server number: 8.5.49.0
OS Name: Linux
OS Version: 3.10.0-514.el7.x86_64
Architecture: amd64
JVM Version: 1.8.0_211-b12
JVM Vendor: Oracle Corporation
Access the management page
Click the button to be denied access.
Follow the prompts to configure the following
[root@tomcat ~]# vim /usr/local/tomcat/conf/tomcat-users.xml
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<user username="user" password="password" roles="tomcat,manager-gui,manager-script,admin-gui,admin-script"/>
[root@tomcat ~]# vim /usr/local/tomcat/webapps/host-manager/META-INF/context.xml
[root@tomcat ~]# vim /usr/local/tomcat/webapps/manager/META-INF/context.xml
# 修改权限,可以允许所有,可以允许ip,支持正则
# 内容均修改为如下图片,然后重启tomcat
Visit after restart
Add a little Tomcat configuration file
2、server.xml配置文件
<?xml version='1.0' encoding='utf-8'?>
4、Connector主要参数说明
```shell
port:指定服务器端要创建的端口号,并在这个端口监听来自客户端的请求。
protocol:连接器使用的协议,支持HTTP和AJP。AJP(Apache Jserv Protocol)专用于tomcat与apache建立通信的.
redirectPort:指定服务器正在处理http请求时收到了一个SSL传输请求后重定向的端口号
maxThreads:接收最大请求的并发数
connectionTimeout 指定超时的时间数(以毫秒为单位)
5. Detailed explanation of host parameters
host:表示一个虚拟主机
name:指定主机名
appBase:应用程序基本目录,即存放应用程序的目录.一般为appBase="webapps",相对于CATALINA_HOME而言的,也可以写绝对路径。
unpackWARs:如果为true,则tomcat会自动将WAR文件解压,否则不解压,直接从WAR文件中运行应用程序
autoDeploy:在tomcat启动时,是否自动部署
2. Use war package to deploy web site (jenkins)
Tomcat single-node configuration
There are two ways to go online code: The
first way is to directly put the program directory under the webapps directory The
second way is to use the development tool to package the program into a war package, and then upload it to the webapps directory
使用war包部署web站点**
[root@java-tomcat1 ~]# pwd
/root
下载jenkins的war包
[root@java-tomcat1 ~]# wget http://updates.jenkins-ci.org/download/war/2.129/jenkins.war
[root@java-tomcat1 ~]# ls
jenkins.war
[root@java-tomcat1 ~]# cd /data/application/tomcat #进入tomcat目录
[root@java-tomcat1 tomcat]# cp -r webapps/ /opt/ #将原来的发布网站目录备份
[root@java-tomcat1 tomcat]# cd webapps/
[root@java-tomcat1 webapps]# ls
docs examples host-manager manager ROOT
[root@java-tomcat1 webapps]# rm -rf * #清空发布网站里面的内容
[root@java-tomcat1 webapps]# cp /root/jenkins.war . #将war包拷贝到当前目录
[root@java-tomcat1 webapps]# ../bin/startup.sh #启动
Using CATALINA_BASE: /data/application/tomcat
Using CATALINA_HOME: /data/application/tomcat
Using CATALINA_TMPDIR: /data/application/tomcat/temp
Using JRE_HOME: /usr/local/java
Using CLASSPATH: /data/application/tomcat/bin/bootstrap.jar:/data/application/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@java-tomcat1 webapps]# ls
jenkins jenkins.war
二、手动解压:
[root@java-tomcat1 webapps]# ../bin/shutdown.sh #关闭tomcat
[root@java-tomcat1 ~]# cd /data/application/tomcat/webapps/
[root@java-tomcat1 webapps]# rm -rf *
[root@java-tomcat1 webapps]# mkdir ROOT #创建一个ROOT目录存放war包
[root@java-tomcat1 webapps]# ls
ROOT
[root@java-tomcat1 webapps]# cd ROOT/
[root@java-tomcat1 ROOT]# cp /root/jenkins.war .
[root@java-tomcat1 ROOT]# unzip jenkins.war
3. Deploy an open source site (jspgou mall)
The first milestone: Install the configuration database
[root@java-tomcat1 ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
[root@java-tomcat1 ~]# rpm -ivh mysql80-community-release-el7-3.noarch.rpm
[root@java-tomcat1 ~]# cd /etc/yum.repos.d/
[root@java-tomcat1 yum.repos.d]# vim mysql-community.repo
注意enabled中0表示关闭,1表示开启
安装
yum clean all
yum makecache
[root@java-tomcat1 yum.repos.d]# yum -y install mysql-server mysql
[root@java-tomcat1 yum.repos.d]# cd
[root@java-tomcat1 ~]# systemctl start mysqld
[root@java-tomcat1 ~]# systemctl enable mysqld
查找密码并修改密码
[root@java-tomcat1 ~]# grep pass /var/log/mysqld.log #过滤查找密码
2019-07-05T15:57:15.294365Z 1 [Note] A temporary password is generated for root@localhost: %6yx817IeX-J
[root@java-tomcat1 ~]# mysqladmin -u root -p'%6yx817IeX-J' password 'QianFeng@123' #修改密码
Configuration database
[root@java-tomcat1 ~]# mysql -u root -p'QianFeng@123'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.26 MySQL Community Server (GPL)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database jspgou default charset=utf8; #创建数据库设置字符集
Query OK, 1 row affected (0.00 sec)
mysql> \q
Bye
The second milestone: jspgou mall goes online
上传jspgou商城的代码
[root@java-tomcat1 ~]# unzip jspgouV6.1-ROOT.zip
[root@java-tomcat1 ~]# cp -r ROOT/ /data/application/tomcat/webapps/
[root@java-tomcat1 ~]# cd /data/application/tomcat/webapps/
[root@java-tomcat1 webapps]# ls
ROOT
[root@java-tomcat1 webapps]# vim ROOT/WEB-INF/config/jdbc.properties
Configure database connection----jdbc
将数据导入数据库:
[root@java-tomcat1 ~]# cd DB/
[root@java-tomcat1 DB]# ls
jspgou.sql
[root@java-tomcat1 DB]# mysql -uroot -p'QianFeng@123' -D jspgou < jspgou.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1067 (42000) at line 97: Unknown error 1067
[root@java-tomcat1 DB]# vim /etc/my.cnf ----添加sql_mod
sql_mode=STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUB
explicit_defaults_for_timestamp=1
[root@java-tomcat1 DB]# systemctl restart mysqld
[root@java-tomcat1 DB]# mysql -uroot -p'QianFeng@123' -D jspgou < jspgou.sql
启动tomcat访问:
[root@java-tomcat1 ~]# /data/application/tomcat/bin/startup.sh
[root@java-tomcat1 ~]# netstat -lntp