tomcat简介
Tomcat是Apache 软件基金会(Apache Software Foundation)的Jakarta 项目中的一个核心项目,由Apache、Sun 和其他一些公司及个人共同开发而成。由于有了Sun 的参与和支持,最新的Servlet 和JSP 规范总是能在Tomcat 中得到体现,Tomcat 5支持最新的Servlet 2.4 和JSP 2.0 规范。因为Tomcat 技术先进、性能稳定,而且免费,因而深受Java 爱好者的喜爱并得到了部分软件开发商的认可,成为目前比较流行的Web 应用服务器。
Tomcat 服务器是一个免费的开放源代码的Web 应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试JSP 程序的首选。对于一个初学者来说,可以这样认为,当在一台机器上配置好Apache 服务器,可利用它响应HTML(标准通用标记语言下的一个应用)页面的访问请求。实际上Tomcat是Apache 服务器的扩展,但运行时它是独立运行的,所以当你运行tomcat 时,它实际上作为一个与Apache 独立的进程单独运行的。
诀窍是,当配置正确时,Apache 为HTML页面服务,而Tomcat 实际上运行JSP 页面和Servlet。另外,Tomcat和IIS等Web服务器一样,具有处理HTML页面的功能,另外它还是一个Servlet和JSP容器,独立的Servlet容器是Tomcat的默认模式。不过,Tomcat处理静态HTML的能力不如Apache服务器。目前Tomcat最新版本为9.0。
tomcat就是传说中的中间件之一,tomcat本身是一个容器,专门用来运行java程序,java语言开发的网页.jsp就应该运行于tomcat中。而tomcat本身的运行也依赖于jdk环境。
安装tomcat
//安装依赖包
[root@localhost ~]# yum -y install java-11-openjdk-devel java-11-openjdk
//解压安装包
[root@localhost ~]# tar xf apache-tomcat-9.0.46.tar.gz
[root@localhost ~]# ls
anaconda-ks.cfg apache-tomcat-9.0.46 apache-tomcat-9.0.46.tar.gz scripts
//移动到/usr/local/tomcat下
[root@localhost ~]# mv apache-tomcat-9.0.46 /usr/local/tomcat
//启动tomcat
[root@localhost tomcat]# /usr/local/tomcat/bin/startup.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Tomcat started.
[root@localhost tomcat]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 1 [::ffff:127.0.0.1]:8005 *:*
LISTEN 0 100 *:8080 *:*
[root@localhost tomcat]# vim /conf/server.xml
//把注释取消
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector protocol="AJP/1.3"
address="::1"
port="8009"
redirectPort="8443" />
[root@localhost tomcat]# ./bin/catalina.sh stop
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:
NOTE: Picked up JDK_JAVA_OPTIONS: --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
[root@localhost tomcat]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
[root@localhost tomcat]# ./bin/catalina.sh start
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Tomcat started.
[root@localhost tomcat]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 1 [::ffff:127.0.0.1]:8005 *:*
LISTEN 0 100 [::1]:8009 [::]:*
LISTEN 0 100 *:8080 *:*
配置管理界面Manager App
[root@localhost conf]# vim tomcat-users.xml
//把下列两行加到这个配置文件的倒数第二行
<role rolename="manager-gui"/>
<user username="tomcat" password="s3cret" roles="manager-gui"/>
[root@localhost tomcat]# ls
bin conf lib logs README.md RUNNING.txt webapps
BUILDING.txt CONTRIBUTING.md LICENSE NOTICE RELEASE-NOTES temp work
[root@localhost tomcat]# cd webapps/
[root@localhost webapps]# ls
docs examples host-manager manager ROOT
[root@localhost webapps]# cd manager/
[root@localhost manager]# ls
css images index.jsp META-INF status.xsd WEB-INF xform.xsl
[root@localhost manager]# cd META-INF/
[root@localhost META-INF]# ls
context.xml
[root@localhost META-INF]# vim context.xml
allow="192\.168\.100\.\d+|127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
在这个文件中加入要访问的ip网段。
配置Host Manager
[root@localhost conf]# ls
Catalina context.xml logging.properties tomcat-users.xsd
catalina.policy jaspic-providers.xml server.xml web.xml
catalina.properties jaspic-providers.xsd tomcat-users.xml
[root@localhost conf]# vim tomcat-users.xml
<role rolename="manager-gui"/>
<role rolename="admin-gui"/> //在配置文件中加入此行
<user username="zdj" password="123456" roles="manager-gui,admin-gui"/> //加入admin-gui
因为修改了配置文件,,这里需要重启
[root@localhost tomcat]# ./bin/catalina.sh stop
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:
NOTE: Picked up JDK_JAVA_OPTIONS: --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
[root@localhost tomcat]# ./bin/catalina.sh start
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using CATALINA_OPTS:
Tomcat started.
[root@localhost tomcat]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 1 [::ffff:127.0.0.1]:8005 *:*
LISTEN 0 100 [::1]:8009 [::]:*
LISTEN 0 100 *:8080 *:*
[root@localhost tomcat]# cd webapps/host-manager/META-INF/
[root@localhost META-INF]# ls
context.xml
[root@localhost META-INF]# vim context.xml
allow="192\.168\.100\.\d+|127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
//在这个文件中加入要访问的网段
查看一下服务器状态
添加jenkins服务
[root@localhost ~]# ls
anaconda-ks.cfg jenkins.war scripts
[root@localhost ~]# cp jenkins.war /usr/local/tomcat/webapps/
[root@localhost ~]# cd /usr/local/tomcat/webapps/
[root@localhost webapps]# ls
docs examples host-manager jenkins jenkins.war manager ROOT
查看密码
[root@localhost webapps]# cat /root/.jenkins/secrets/initialAdminPassword
f9770e45cc67460586e22f049b96e91d
配置完成。
到此这篇关于tomcat下部署jenkins的实现方法的文章就介绍到这了,更多相关tomcat部署jenkins内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!