标签:image apr-util yum load 加载 指令 远程 进制 图片
Tomcat是apache软件基金会(apache Software Foundation)的Jakarta 项目中的一个核心项目,由apache、Sun和其他一些公司及个人共同开发而成。
Tomcat服务器是一个免费的开放源代码的Web应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试JSP程序的首选。
Tomcat和Nginx、apache(httpd)、lighttpd等Web服务器一样,具有处理HTMl页面的功能,另外它还是一个Servlet和JSP容器,独立的Servlet容器是Tomcat的默认模式。不过,Tomcat处理静态HTMl的能力不如Nginx/apache服务器。目前Tomcat最新版本为9.0。Java容器还有resin、weblogic等。
tomcat官网:https://tomcat.apache.org/
下载最新的apache-tomcat-9.0.19 .zip
[root@localhost ~]# rz
[root@localhost ~]# ls anaconda-ks.cfg apr-1.5.2.tar.gz httpd-2.4.20 apache-tomcat-9.0.19.zip apr-util-1.5.4 httpd-2.4.20.tar.gz apr-1.5.2 apr-util-1.5.4.tar.gz
[root@localhost ~]#unzip apache-tomcat-9.0.19.zip [root@localhost ~]# ls apache-tomcat-9.0.19
[root@localhost ~]# cp -a apache-tomcat-9.0.19 /usr/local/tomcat
[root@localhost ~]# cd /usr/local/tomcat [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 bin [root@localhost bin]# ll -rw-r--r--. 1 root root 2020 apr 12 15:24 shutdown.bat -rw-r--r--. 1 root root 1902 apr 12 15:24 shutdown.sh -rw-r--r--. 1 root root 2022 apr 12 15:24 startup.bat -rw-r--r--. 1 root root 1904 apr 12 15:24 startup.sh [root@localhost bin]# chmod -R a+x /usr/local/tomcat -rwxr-xr-x. 1 root root 1902 apr 12 15:24 shutdown.sh -rwxr-xr-x. 1 root root 2022 apr 12 15:24 startup.bat -rwxr-xr-x. 1 root root 1904 apr 12 15:24 startup.sh
选择yum安装tomcat需要的jdk,就不用再手动配置环境变量
[root@localhost /]# mount /dev/cdrom /mnt mount: /dev/sr0 is write-protected, mounting read-only [root@localhost /]# yum install java -y
[root@localhost 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 Tomcat started. [root@localhost 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 Tomcat started. [root@localhost bin]# ss -tnl #查看端口 liSTEN 0 100 :::8080 :::* liSTEN 0 1 ::ffff:127.0.0.1:8005 :::* liSTEN 0 100 :::8009 :::* #三个端口均已开启
2.9 windows端访问,要加端口
[root@localhost bin]# ./shutdown.sh #当前目录下关闭
[root@localhost ~]# vim /etc/profile.d/tomcat.sh export PATH=/usr/local/tomcat/bin/:$PaTH :wq [root@localhost ~]# source /etc/profile.d/tomcat.sh #重新加载文件确保其生效 [root@localhost ~]# startup.sh #再次启动 Tomcat started. [root@localhost ~]# ss -tnl State Recv-Q Send-Q local address:Port Peer address:Port liSTEN 0 100 :::8080 :::* liSTEN 0 1 ::ffff:127.0.0.1:8005 :::* liSTEN 0 100 :::8009 :::*
[root@localhost ~]# cd /usr/local/tomcat/ [root@localhost tomcat]# tree -l 1 #以树形列出 . ├── bin #用以启动、关闭Tomcat或者其它功能的脚本(.bat文件和.sh文件) ├── BUilDiNG.txt ├── conf #用以配置Tomcat的XML及DTD文件 ├── CONTRiBUTiNG.md ├── lib #存放web应用能访问的JAR包 ├── LICENSE #许可证 ├── logs #Catalina和其它Web应用程序的日志文件 ├── NOTICE ├── README.md ├── RElEASE-NOTES ├── RUNNING.txt ├── temp #临时文件 ├── webapps #Web应用程序根目录 └── work #用以产生有JSP编译出的Servlet的.java和.class文件
[root@localhost tomcat]# cd logs/ [root@localhost logs]# ls catalina.out #tomcat的实时日志
[root@localhost tomcat]# cd conf 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 srever.xml <Server port="8005" shutdown="SHUTDOWN"> <Connector port="8080" protocol="HTTP/1.1" <Connector port="8009" protocol="aJP/1.3" redirectPort="8443" /> ……….. <Host name="localhost" appBase="webapps" unpackWaRs="true" autoDeploy="true">
#WaR压缩包放在webapps下会自动解压 自动部署
8005端口:接收shutdown指令。
port指定Tomcat监听shutdown命令端口。终止服务器运行时,必须在Tomcat服务器所在的机器上发出shutdown命令,该属性是必须的。 shutdown指定终止Tomcat服务器运行时,发给Tomcat服务器的shutdown监听端口的字符串,该属性必须设置。
<Server port="8005" shutdown="SHUTDOWN">
8080端口:接收HTTP协议。
connector:接收用户请求,类似于httpd的listen配置监听端口。
port指定服务器端要创建的端口号,并在这个端口监听来自客户端的请求。
redirectPort指定服务器正在处理http请求时收到了一个SSl传输请求后重定向的端口号
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
8009端口:接收AJP协议
protocol连接器使用的协议,支持HTTP和AJP。AJP(Apache Jserv Protocol)专用于tomcat与apache建立通信的, 在httpd反向代理用户请求至tomcat时使用(可见Nginx反向代理时不可用aJP协议)
<Connector port="8009" protocol="aJP/1.3" redirectPort="8443" />
[root@localhost conf]# telnet 127.0.0.1 8005 #进入8005端口 Trying 127.0.0.1... Connected to 127.0.0.1. Escape character is ‘^]‘. SHUTDOWN #关闭端口 Connection closed by foreign host. [root@localhost conf]# ss -tnl State Recv-Q Send-Q local address:Port Peer address:Port liSTEN 0 128 *:111 *:* liSTEN 0 128 *:22 *:* liSTEN 0 100 127.0.0.1:25 *:* liSTEN 0 128 :::111 :::* liSTEN 0 128 :::80 :::* liSTEN 0 128 :::22 :::* liSTEN 0 100 ::1:25 :::* #tomcat关闭
/usr/local/tomcat/webapps/ROOT :网站根目录;网站访问默认为ROOT目录,访问文件也可以在webapps下创建目录将index.html拷入,再写入文件,访问时必须将非ROOT的目录跟上。如在webapps创建目录zxj,拷入index.html后写入211111111:telnet:远程登录指令
[root@localhost tomcat]# cd webapps/ [root@localhost webapps]# echo "2111111111" > index.html [root@localhost webapps]# cp index.html zxj
[root@localhost local]# cp -a tomcat tomcat1 #复制多实例,
[root@localhost local]# cp -a tomcat tomcat2 [root@localhost local]# ls tomcat tomcat1 tomcat2 #一共3个tomcat服务,为避免端口冲突, 需要修改复制实例的端口,使端口号不冲突即可 [root@localhost local]# vim tomcat1/conf/server.xml <Server port="8006" shutdown="SHUTDOWN"> <Connector port="8081" protocol="HTTP/1.1" ;wq [root@localhost local]# vim tomcat2/conf/server.xml <Server port="8007" shutdown="SHUTDOWN"> <Connector port="8082" protocol="HTTP/1.1" :wq [root@localhost local]# tomcat1/bin/startup.sh #启动tomcat1 [root@localhost local]# tomcat2/bin/startup.sh #启动tomcat2
windows端访问
多实例部署成功
以Nginx为调度器,三台tomcat为集群节点搭建集群
以192.168.16.部署Nginx
#Nginx: #检查80端口是否被占用,若有,则关掉占用端口的http [root@localhost ~]# ss -tnl [root@localhost ~]# systemctl restart nginx #启动Nginx [root@localhost ~]# ss -tnl liSTEN 0 128 :::80 :::*
#配置负载均衡 [root@localhost ~]# vim /etc/nginx/nginx.conf upstream zxj { #负载均衡 server 192.168.16.3:8080 weight=2 max_fails=2 fail_timeout=2 server 192.168.16.3:8081 weight=2 max_fails=2 fail_timeout=2 server 192.168.16.3:8082 weight=2 max_fails=2 fail_timeout=2 } server { listen 80 default_server; listen [::]:80 default_server; server_name _; root /var/www/html; index index.php index.html; # load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { proxy_pass http://zxj; #集群名 } :wq [root@localhost ~]# nginx -t #检查 nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful [root@localhost ~]# systemctl restart nginx #重启
只在在浏览器查询.4即可,记得要关闭防火墙
jpress类似于wordpress的一个开源博客系统。
https://gitee.com/fuhai/jpress/blob/alpha/wars/jpress-web-newest.war
[root@localhost ~]# cd /usr/local/tomcat/webapps/ROOT/
[root@localhost ROOT]# rz
[root@localhost ROOT]#unzip fuhai-jpress-alpha-zip [root@localhost ROOT]#ls fuhai-jpress-alpha-zip jpress #无法自动解压,继续手动解压 [root@localhost ROOT]# cd jpress [root@localhost jpress]# ls DOC.md jpress liCENSE REaDME.md wars [root@localhost jpress]# cd wars/ [root@localhost wars]# ls jpress-web-newest.war [root@localhost wars]# cp jpress-web-newest.war /usr/local/tomcat/webapps/ROOT [root@localhost wars]#cd /usr/local/tomcat/webapps/ROOT [root@localhost ROOT]#unzip jpress-web-newest.war
在windows端访问
配置数据库
[root@localhost ROOT]# cd [root@localhost ~]# systemctl restart mariadb [root@localhost ~]# mysql -uroot MariaDB [(none)]> create database zxj; MariaDB [(none)]> grant all on *.* to zxj@‘localhost‘ identified by ‘123‘; #授权给所有用户 MariaDB [(none)]> exit Bye [root@localhost ~]# systemctl restart mariadb
重启tomcat
[root@localhost ~]# shutdown.sh [root@localhost ~]# ss -tnl liSTEN 0 100 :::8080 :::*
标签:image apr-util yum load 加载 指令 远程 进制 图片
原文地址:https://www.cnblogs.com/ajunyu/p/10886714.html