Tomcat部署
第一种安装
yum install tomcat.noarch -y
yum install tomcat-webapps.noarch -y
#启动脚本
[root@localhost ~]# systemctl start tomcat
这时可以通过IP地址+端口访问
第二种安装
点击此处找到apache-tomcat-8.5.70.tar.gz
官网下载JDK
#先安装JDK
[root@localhost ~]# yum install jdk-8u261-linux-x64.rpm -y
[root@localhost ~]# tar xf apache-tomcat-8.5.70.tar.gz -C /usr/local
[root@localhost ~]# ln -sv /usr/local/apache-tomcat-8.5.70/ /usr/local/tomcat
‘/usr/local/tomcat’ -> ‘/usr/local/apache-tomcat-8.5.70/’
[root@localhost ~]# groupadd -g 53 tomcat
[root@localhost ~]# useradd -u 53 -g 53 -c "Apache Tomcat" -d /usr/local/tomcat/ -s /sbin/nologin tomcat
[root@localhost ~]# chown -R tomcat.tomcat /usr/local/tomcat/*
#从另一台虚拟机中拷贝过来
[root@localhost ~]# scp /etc/tomcat/tomcat.conf 192.168.40.128:/usr/local/tomcat/conf/
[root@localhost ~]# vim /usr/local/tomcat/conf/tomcat.conf
#修改
TOMCATS_BASE="/usr/local/tomcat/"
JAVA_HOME="/usr/java/jdk1.8.0_261-amd64/jre"
CATALINA_HOME="/usr/local/tomcat"
CATALINA_TMPDIR="/usr/local/tomcat/temp"
#如果不拷贝直接vim /usr/local/tomcat/conf/tomcat.conf,将以下内容添加进去
TOMCAT_CFG_LOADED="1"
TOMCATS_BASE="/usr/local/tomcat/"
JAVA_HOME="/usr/java/jdk1.8.0_261-amd64/jre"
CATALINA_HOME="/usr/local/tomcat"
CATALINA_TMPDIR="/usr/local/tomcat/temp"
JAVA_OPTS="-Djavax.sql.DataSource.Factory=org.apache.commons.dbcp.BasicDataSourceFactory"
SECURITY_MANAGER="false"
[root@localhost ~]# vim /usr/lib/systemd/system/tomcat.service
[Unit]
Description=Apache Tomcat
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
Environment=JAVA_HOME=/usr/java/jdk1.8.0_261-amd64
Environment=CATALINA_HOME=/usr/local/tomcat
ExecStart=/usr/local/tomcat/bin/startup.sh
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
User=tomcat
Group=tomcat
PrivateTmp=true
[Install]
WantedBy=multi-user.target
此时可以成功在浏览器中访问
若访问本地:http://localhost:8080/正确。但局域网内无法访问。
1、通过 systemctl start firewalld 开启防火墙
2、如果是firewalld防火墙 (对于Centos7系统),开启防火墙端口 firewall-cmd --zone=public --add-port=8080/tcp --permanent 并且重新加载防火墙 firewall-cmd --reload
此时便成功访问
部署jpress应用
[root@localhost ~]# cd /usr/local/tomcat/conf
[root@localhost conf]# vim tomcat-users.xml
#添加
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<role rolename="manager-gui"/>
<role rolename="manager-jmx"/>
<role rolename="manager-script"/>
<role rolename="manager-status"/>
<user username="tomcat" password="tomcat" roles="admin-gui,manager-gui,manager-jmx,manager-script,manager-status,admin-script"/>
#允许方式Manager App
[root@localhost conf]# vim /usr/local/tomcat/webapps/manager/META-INF/context.xml
#修改
allow=".*"
#允许访问Host Manager
[root@localhost conf]# vim /usr/local/tomcat/webapps/host-manager/META-INF/context.xml
#修改
allow=".*"
重启服务生效
[root@localhost conf]# systemctl restart tomcat.service
输入用户密码后进入
Web站点部署
两种方式
第一种方式是直接将程序目录放在webapps目录下面
第二种方式是使用开发工具将程序打包成war包,然后上传到webapps目录下面
部署开源站点(jpress)
jpress官网:http://jpress.io
下载地址:https://github.com/JpressProjects/jpress
#安装配置数据库
[root@localhost conf]# yum -y install mariadb-server
[root@localhost conf]# systemctl start mariadb.service
#创建授权用户
[root@localhost webapps]# mysql -e "create database jpress DEFAULT CHARACTER SET utf8;"
[root@localhost webapps]# mysql -e "grant all on jpress.* to jpress@'localhost' identified by '123456';"
#将war导入到这个路径
[root@localhost webapps]# pwd
/usr/local/tomcat/webapps
[root@localhost webapps]# ll
total 20316
drwxr-x--- 15 tomcat tomcat 4096 Jul 5 13:25 docs
drwxr-x--- 7 tomcat tomcat 99 Jul 5 13:25 examples
drwxr-x--- 6 tomcat tomcat 79 Jul 5 13:25 host-manager
drwxr-x--- 7 tomcat tomcat 102 Jul 5 13:35 jpress-web-newest
-rw-r--r-- 1 root root 20797013 Aug 1 2023 jpress-web-newest.war
drwxr-x--- 6 tomcat tomcat 114 Jul 5 13:25 manager
drwxr-x--- 3 tomcat tomcat 223 Jul 5 13:25 ROOT
浏览器访问
http://IP:8080/jpress-web-newest/install
部署memtest.war
点击后
通过http://ip:8080/memtest/meminfo.jsp访问