Tomcat是Apache软件基金会的Jakarta项目中开发的一个Servlet容器,实现了对Servlet和JavaServerPage(JSP)的支持,Tomcat本身也是一个HTTP服务器,Tomcat主要用来解析JSP语言、HTML格式的网页页面。
本实验需要用到的软件:
apache-tomcat-8.5.57.tar.gz
jdk-8u261-linux-i586.tar.gz
安装JDK
[root@localhost ~]# yum install glibc.i686 -y
[root@localhost ~]# cd /usr/local
[root@localhost local]# mkdir {java,tomcat}
[root@localhost local]# cd ~
[root@localhost ~]# tar -xf jdk-8u261-linux-i586.tar.gz
[root@localhost ~]# mv jdk1.8.0_261/ /usr/local/java
[root@localhost ~]# vim /etc/profile # 在配置文件最后添加如下三行JDK环境
export JAVA_HOME=/usr/local/java/jdk1.8.0_261
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
[root@localhost ~]# source /etc/profile
[root@localhost ~]# which java
/usr/local/java/jdk1.8.0_261/bin/java
[root@localhost ~]# java -version
java version "1.8.0_261"
Java(TM) SE Runtime Environment (build 1.8.0_261-b12)
Java HotSpot(TM) Client VM (build 25.261-b12, mixed mode)
[root@localhost ~]#
安装Tomcat
[root@localhost ~]# tar -xf apache-tomcat-8.5.57.tar.gz
[root@localhost ~]# mv apache-tomcat-8.5.57 /usr/local/tomcat
[root@localhost ~]# echo 'export TOMCAT_HOME=/usr/local/tomcat' >> /etc/profile # 添加Tomcat环境
[root@localhost ~]# source /etc/profile
[root@localhost ~]# tail -4 /etc/profile # 查看倒数4行内容
export JAVA_HOME=/usr/local/java/jdk1.8.0_261
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export TOMCAT_HOME=/usr/local/tomcat
[root@localhost ~]# /usr/local/tomcat/apache-tomcat-8.5.57/bin/startup.sh # 启动Tomcat
Using CATALINA_BASE: /usr/local/tomcat/apache-tomcat-8.5.57
Using CATALINA_HOME: /usr/local/tomcat/apache-tomcat-8.5.57
Using CATALINA_TMPDIR: /usr/local/tomcat/apache-tomcat-8.5.57/temp
Using JRE_HOME: /usr/local/java/jdk1.8.0_261
Using CLASSPATH: /usr/local/tomcat/apache-tomcat-8.5.57/bin/bootstrap.jar:/usr/local/tomcat/apache-tomcat-8.5.57/bin/tomcat-juli.jar
Tomcat started.
配置SELinux 和防火墙
[root@localhost ~]# setenforce 0
[root@localhost ~]# firewall-cmd --zone=public --add-port=8080/tcp --permanent
success
[root@localhost ~]# getenforce
Permissive
在浏览器中输入:192.168.203.129:8080,即可访问Tomcat默认页面
基于端口的虚拟机,修改Tomcat的server.xml配置文件,将port="8080"改成port="80",还可以在下面继续添加端口
[root@localhost ~]# cd /usr/local/tomcat/apache-tomcat-8.5.57/conf/
[root@localhost conf]# vim server.xml
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
# 重启Tomcat
[root@localhost conf]# /usr/local/tomcat/apache-tomcat-8.5.57/bin/shutdown.sh
[root@localhost conf]# /usr/local/tomcat/apache-tomcat-8.5.57/bin/startup.sh
通过Tomcat部署zrlog博客网站
下载zrlog软件包
[root@localhost ~]# wget http://dl.zrlog.com/release/zrlog-2.1.3-b5f0d63-release.war?attname=ROOT.war&ref=index
[root@localhost ~]# ls | grep *.war
zrlog-2.1.3-b5f0d63-release.war?attname=ROOT.war
[root@localhost ~]# cd /usr/local/tomcat/apache-tomcat-8.5.57/webapps
[root@localhost webapps]# cd
[root@localhost ~]# mv zrlog-2.1.3-b5f0d63-release.war\?attname\=ROOT.war /usr/local/tomcat/apache-tomcat-8.5.57/webapps/zrlog.war
[root@localhost ~]# cd /usr/local/tomcat/apache-tomcat-8.5.57/webapps/
[root@localhost webapps]# ls
docs examples host-manager manager ROOT zrlog zrlog.war
[root@localhost webapps]# mv ROOT ROOT.bak
[root@localhost webapps]# mv zrlog ROOT
[root@localhost webapps]#
安装mariadb数据库
[root@localhost ~]# yum install mariadb mariadb-server
...........省略部分安装步骤..............
Updated:
mariadb.x86_64 1:5.5.65-1.el7 mariadb-server.x86_64 1:5.5.65-1.el7
Dependency Updated:
mariadb-libs.x86_64 1:5.5.65-1.el7
Complete!
[root@localhost ~]# systemctl start mariadb # 启动Mariadb数据库
[root@localhost ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@localhost ~]# mysql_secure_installation # 初始化Mariadb数据库
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
Enter current password for root (enter for none): # 敲回车
OK, successfully used password, moving on...
Set root password? [Y/n] y # 创建数据库管理员登录密码
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
Remove anonymous users? [Y/n] y # 删除匿名用户
... Success!
Disallow root login remotely? [Y/n] y # 禁止root远程登陆
... Success!
Remove test database and access to it? [Y/n] y # 删除test数据库
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reload privilege tables now? [Y/n] y # 刷新授权表
... Success!
Cleaning up...
Thanks for using MariaDB!
[root@localhost ~]#
将MySQL服务加入到防火墙并重启
[root@localhost ~]# firewall-cmd --permanent --add-service=mysql
success
[root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]#
在Mariadb数据库中创建zrlog数据库、zrlog用户,并给用户授权
[root@localhost ~]# mysql -uroot -p123456
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 5.5.65-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database zrlog;
Query OK, 1 row affected (0.05 sec)
MariaDB [(none)]> grant all on zrlog.* to 'zrlog'@'192.168.203.129' identified by '123456';
Query OK, 0 rows affected (0.03 sec)
MariaDB [(none)]> quit
用户:zrlog ,密码:123456 ,授权host主机:192.168.203.129(如果上面没有修改端口,则默认是8080端口)
打开浏览器访问:http://192.168.203.129:80(tomcat端口)
配置管理员账号信息
至此,Linux系统下安装Tomcat并完成部署网站!