概述
tomcat
- 1. tomcat项目部署
- 1.1 java环境安装
- 1.2 tomcat部署
- 2. 搭建LAMT架构
- 2.1 安装httpd
- 2.2 安装mysql
- 2.3 安装Tomcat
- 2.4 配置apache
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.37。
tomcat就是传说中的中间件之一,tomcat本身是一个容器,专门用来运行java程序,java语言开发的网页.jsp就应该运行于tomcat中。而tomcat本身的运行也依赖于jdk环境。
tomcat应用场景:lnmt
1. tomcat项目部署
1.1 java环境安装
[root@yeqixian ~]# yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel
[root@yeqixian ~]# java -version
openjdk version “1.8.0_252”
OpenJDK Runtime Environment (build 1.8.0_252-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)
1.2 tomcat部署
//下载tomcat
[root@yeqixian ~]# cd /usr/src/
[root@yeqixian src]# wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-9/v9.0.37/bin/apache-tomcat-9.0.37.tar.gz
//解压部署
[root@yeqixian src]# ls
apache-tomcat-9.0.37.tar.gz debug kernels
[root@yeqixian src]# tar xf apache-tomcat-9.0.37.tar.gz
[root@yeqixian src]# mv apache-tomcat-9.0.37 /usr/local/
[root@yeqixian src]# cd /usr/local/
[root@yeqixian local]# ln -s apache-tomcat-9.0.37/ tomcat
[root@yeqixian local]# ll
total 0
drwxr-xr-x 9 root root 220 Aug 3 05:17 apache-tomcat-9.0.37
drwxr-xr-x. 2 root root 6 Apr 11 2018 bin
drwxr-xr-x. 2 root root 6 Apr 11 2018 etc
drwxr-xr-x. 2 root root 6 Apr 11 2018 games
drwxr-xr-x. 2 root root 6 Apr 11 2018 include
drwxr-xr-x. 2 root root 6 Apr 11 2018 lib
drwxr-xr-x. 2 root root 6 Apr 11 2018 lib64
drwxr-xr-x. 2 root root 6 Apr 11 2018 libexec
drwxr-xr-x. 2 root root 6 Apr 11 2018 sbin
drwxr-xr-x. 5 root root 49 Jul 9 17:08 share
drwxr-xr-x. 2 root root 6 Apr 11 2018 src
lrwxrwxrwx 1 root root 21 Aug 3 05:26 tomcat -> apache-tomcat-9.0.37/
//写一个hello world的java页面
[root@yeqixian ~]# vim index.jsp
[root@yeqixian ~]# cat index.jsp
<html>
<head>
<title>test page</title>
</head>
<body>
<%
out.println("Hellow World");
%>
</body>
</html>
[root@yeqixian ~]# mkdir /usr/local/tomcat/webapps/test
[root@yeqixian ~]# cp index.jsp /usr/local/tomcat/webapps/test/
[root@yeqixian ~]# ll /usr/local/tomcat/webapps/test/
total 4
-rw-r--r-- 1 root root 141 Aug 3 05:27 index.jsp
//启动tomcat
[root@yeqixian ~]# /usr/local/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
Tomcat started.
[root@yeqixian ~]# ps -ef|grep tomcat
root 1603 1 33 05:29 pts/0 00:00:04 /usr/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start
root 1634 1281 0 05:29 pts/0 00:00:00 grep --color=auto tomcat
[root@yeqixian ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 5 127.0.0.1:25151 *:*
LISTEN 0 5 *:873 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 1 ::ffff:127.0.0.1:8005 :::*
LISTEN 0 5 :::873 :::*
LISTEN 0 100 :::8080 :::*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 128 :::443 :::*
这三个管理页面是不能访问的,要想访问还需要做下面的步骤
[root@yeqixian ~]# vi /usr/local/tomcat/webapps/manager/META-INF/context.xml
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
//添加192.168.116.d+|,这里的网段改为你自己的网段
allow="192.168.116.d+|127.d+.d+.d+|::1|0:0:0:0:0:0:0:1" />
[root@yeqixian ~]# vi /usr/local/tomcat/webapps/host-manager/META-INF/context.xml
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
//和上面一样,改为自己的网段
allow="192.168.116.d+|127.d+.d+.d+|::1|0:0:0:0:0:0:0:1" />
[root@yeqixian ~]# vi /usr/local/tomcat/conf/tomcat-users.xml
//在</tomcat-users>前面添加下面三行
<role rolename="manager-gui"/>
<role rolename="admin-gui"/>
<user username="tomcat" password="123" roles="manager-gui,admin-gui"/>
</tomcat-users>
[root@yeqixian ~]# /usr/local/tomcat/bin/catalina.sh stop
[root@yeqixian ~]# /usr/local/tomcat/bin/catalina.sh start
2. 搭建LAMT架构
环境:
系统 | 主机名 | IP 服务 |
---|---|---|
CentOS 7 | node1 | 192.168.116.145 |
2.1 安装httpd
//下载并解压apr和apr-util
[root@yeqixian ~]# wget http://mirror.bit.edu.cn/apache/apr/apr-1.7.0.tar.gz http://mirror.bit.edu.cn/apache/apr/apr-util-1.6.1.tar.gz
--2020-08-03 05:46:22-- http://mirror.bit.edu.cn/apache/apr/apr-1.7.0.tar.gz
Resolving mirror.bit.edu.cn (mirror.bit.edu.cn)... 202.204.80.77, 219.143.204.117, 2001:da8:204:1205::22
Connecting to mirror.bit.edu.cn (mirror.bit.edu.cn)|202.204.80.77|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1093896 (1.0M) [application/octet-stream]
Saving to: ‘apr-1.7.0.tar.gz’
100%[==============>] 1,093,896 1.31MB/s in 0.8s
2020-08-03 05:46:23 (1.31 MB/s) - ‘apr-1.7.0.tar.gz’ saved [1093896/1093896]
--2020-08-03 05:46:23-- http://mirror.bit.edu.cn/apache/apr/apr-util-1.6.1.tar.gz
Reusing existing connection to mirror.bit.edu.cn:80.
HTTP request sent, awaiting response... 200 OK
Length: 554301 (541K) [application/octet-stream]
Saving to: ‘apr-util-1.6.1.tar.gz’
100%[==============>] 554,301 1.38MB/s in 0.4s
2020-08-03 05:46:23 (1.38 MB/s) - ‘apr-util-1.6.1.tar.gz’ saved [554301/554301]
FINISHED --2020-08-03 05:46:23--
Total wall clock time: 1.4s
Downloaded: 2 files, 1.6M in 1.2s (1.33 MB/s)
[root@yeqixian ~]# ls
anaconda-ks.cfg apr-util-1.6.1.tar.gz
apr-1.7.0.tar.gz index.jsp
[root@yeqixian ~]# tar xf apr-1.7.0.tar.gz
[root@yeqixian ~]# tar xf apr-util-1.6.1.tar.gz
[root@yeqixian ~]# ls
anaconda-ks.cfg apr-util-1.6.1
apr-1.7.0 apr-util-1.6.1.tar.gz
apr-1.7.0.tar.gz index.jsp
//安装依赖包
[root@yeqixian ~]# yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++
//创建apache服务的用户和组
[root@yeqixian ~]# useradd -r -M -s /sbin/nologin apache
[root@yeqixian ~]# id apache
uid=48(apache) gid=48(apache) groups=48(apache)
//安装apr和apr-util
[root@yeqixian ~]# cd apr-1.7.0
[root@yeqixian apr-1.7.0]# vim configure
cfgfile=${ofile}T
trap "$RM "$cfgfile"; exit 1" 1 2 15
$RM "$cfgfile" //将此行注释或者删除
[root@yeqixian apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@yeqixian apr-1.7.0]# make && make install
[root@yeqixian apr-1.7.0]# cd /root/apr-util-1.6.1
[root@yeqixian apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@yeqixian apr-util-1.6.1]# make && make install
//下载并编译安装httpd
[root@yeqixian ~]# wget https://mirror.bit.edu.cn/apache/httpd/httpd-2.4.43.tar.gz
[root@yeqixian ~]# tar xf httpd-2.4.43.tar.gz
[root@yeqixian ~]# cd httpd-2.4.43
[root@yeqixian httpd-2.4.43]# ./configure --prefix=/usr/local/apache
> --sysconfdir=/etc/httpd24
> --enable-proxy
> --enable-proxy-connect
> --enable-so
> --enable-ssl
> --enable-cgi
> --enable-rewrite
> --with-zlib
> --with-pcre
> --with-apr=/usr/local/apr
> --with-apr-util=/usr/local/apr-util/
> --enable-modules=most
> --enable-mpms-shared=all
> --with-mpm=prefork
[root@yeqixian httpd-2.4.43]# make && make install
//配置httpd
[root@yeqixian httpd-2.4.43]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@yeqixian httpd-2.4.43]# source /etc/profile.d/httpd.sh
[root@yeqixian httpd-2.4.43]# ln -s /usr/local/apache/include /usr/include/httpd
[root@yeqixian httpd-2.4.43]# echo 'MANPATH /usr/local/apache/man' >> /etc/man_db.conf
[root@yeqixian httpd-2.4.43]# sed -i '/#ServerName/s/#//g' /etc/httpd24/httpd.conf
//启动httpd
[root@yeqixian ~]# apachectl start
[root@yeqixian ~]# ss -antl |grep 80
2.2 安装mysql
//下载并解压mysql
[root@yeqixian ~]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz
[root@yeqixian ~]# tar xf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
//安装依赖包
[root@yeqixian ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
//创建mysql用户和组
[root@yeqixian ~]# useradd -r -M -s /sbin/nologin -u 306 mysql
[root@yeqixian ~]# id mysql
uid=306(mysql) gid=306(mysql) groups=306(mysql)
//配置mysql
[root@yeqixian ~]# cd /usr/local/
[root@yeqixian local]# ln -s mysql-5.7.30-linux-glibc2.12-x86_64/ mysql
[root@yeqixian local]# chown -R mysql.mysql mysql*
[root@yeqixian local]# ll -d mysql
lrwxrwxrwx 1 mysql mysql 36 Aug 3 06:16 mysql -> mysql-5.7.30-linux-glibc2.12-x86_64/
[root@yeqixian local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@yeqixian local]# source /etc/profile.d/mysql.sh
//创建数据存放目录
[root@yeqixian ~]# mkdir /opt/data
[root@yeqixian ~]# chown -R mysql.mysql /opt/data
[root@yeqixian ~]# ll -d /opt/data
drwxr-xr-x 2 mysql mysql 6 Aug 3 06:17 /opt/data
//初始化数据库,并配置(不用密码)
[root@yeqixian ~]# /usr/local/mysql/bin/mysqld --initiallize-insecure --user=mysql --datadir=/opt/data
[root@yeqixian ~]# ln -s /usr/local/mysql/include /usr/local/include/mysql
[root@yeqixian ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@yeqixian ~]# ldconfig
//生成配置文件
[root@yeqixian ~]# cat > /etc/my.cnf <<EOF
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve
EOF
//配置服务启动脚本
[root@yeqixian ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@yeqixian ~]# sed -ri 's#^(basedir=).*#1/usr/local/mysql#g' /etc/init.d/mysqld
[root@yeqixian ~]# sed -ri 's#^(datadir=).*#1/opt/data#g' /etc/init.d/mysqld
//启动mysql,并修改密码
[root@yeqixian ~]# chkconfig mysqld on //设置为开机自动启动
[root@yeqixian ~]# service mysqld start
[root@yeqixian ~]# ss -antl |grep 3306
[root@yeqixian ~]# mysql -e "set password = password('123')"
2.3 安装Tomcat
同上
2.4 配置apache
//启动代理模块
[root@yeqixian ~]# vim /etc/httpd24/httpd.conf
//将下面三行取消注释
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_http_module modules/mod_proxy_http.so
//创建虚拟主机
[root@yeqixian ~]# vim /etc/httpd24/httpd.conf
...
<IfModule dir_module>
DirectoryIndex index.jsp index.html
</IfModule>
...
<VirtualHost *:80>
DocumentRoot "/usr/local/apache/htdocs/"
ServerName aaa.com
ProxyRequests Off //关闭正向代理
ProxyPass /test http://127.0.0.1:8080/test/ //将80端口的test目录的访问请求转到8080端口的test目录中
ProxyPassReverse /test http://127.0.0.1:8080/test/
<Directory "/usr/local/apache/htdocs/">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
[root@yeqixian ~]# apachectl restart
最后
以上就是孝顺野狼为你收集整理的Tomcat运用和LAMT部署1. tomcat项目部署2. 搭建LAMT架构的全部内容,希望文章能够帮你解决Tomcat运用和LAMT部署1. tomcat项目部署2. 搭建LAMT架构所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复