我是靠谱客的博主 斯文花卷,最近开发中收集的这篇文章主要介绍Tomcat部署以及LAMT搭建,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

Tomcat部署

java环境安装

本地源
[root@localhost ~]# yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel
查看版本
[root@localhost yum.repos.d]# java -version
openjdk version "1.8.0_242"
OpenJDK Runtime Environment (build 1.8.0_242-b08)
OpenJDK 64-Bit Server VM (build 25.242-b08, mixed mode)

安装tomcat

[root@localhost ~]# wget https://archive.apache.org/dist/tomcat/tomcat-10/v10.0.0-M10/bin/apache-tomcat-10.0.0-M10.tar.gz
--2020-11-27 09:49:21--  https://archive.apache.org/dist/tomcat/tomcat-10/v10.0.0-M10/bin/apache-tomcat-10.0.0-M10.tar.gz
Resolving archive.apache.org (archive.apache.org)... 138.201.131.134, 2a01:4f8:172:2ec5::2
Connecting to archive.apache.org (archive.apache.org)|138.201.131.134|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 11310078 (11M) [application/x-gzip]
Saving to: ‘apache-tomcat-10.0.0-M10.tar.gz’

apache-tomcat- 100%[====>]  10.79M  7.15KB/s    in 22m 20s 

2020-11-27 10:11:43 (8.24 KB/s) - ‘apache-tomcat-10.0.0-M10.tar.gz’ saved [11310078/11310078]

[root@localhost ~]# ls
apache-tomcat-10.0.0-M10.tar.gz
[root@localhost ~]# tar xf apache-tomcat-10.0.0-M10.tar.gz -C /usr/local/
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ls
apache-tomcat-10.0.0-M10  games    lib64    share
bin                       include  libexec  src
etc                       lib      sbin
制作软链接
[root@localhost local]# ln -s apache-tomcat-10.0.0-M10/ tomcat
[root@localhost local]# ll
total 0
drwxr-xr-x  9 root root 220 Nov 27 10:32 apache-tomcat-10.0.0-M10
drwxr-xr-x. 2 root root   6 Aug 12  2018 bin
drwxr-xr-x. 2 root root   6 Aug 12  2018 etc
drwxr-xr-x. 2 root root   6 Aug 12  2018 games
drwxr-xr-x. 2 root root   6 Aug 12  2018 include
drwxr-xr-x. 2 root root   6 Aug 12  2018 lib
drwxr-xr-x. 2 root root   6 Aug 12  2018 lib64
drwxr-xr-x. 2 root root   6 Aug 12  2018 libexec
drwxr-xr-x. 2 root root   6 Aug 12  2018 sbin
drwxr-xr-x. 5 root root  49 Aug 26 19:55 share
drwxr-xr-x. 2 root root   6 Aug 12  2018 src
lrwxrwxrwx  1 root root  25 Nov 27 10:34 tomcat -> apache-tomcat-10.0.0-M10

创建测试文件,检验服务是否启动

[root@localhost tomcat]# cd webapps/
[root@localhost webapps]# ls
docs  examples  host-manager  manager  ROOT
[root@localhost webapps]# mkdir test
[root@localhost webapps]# cd test/
[root@localhost test]# pwd
/usr/local/tomcat/webapps/test

## 写一个hello world的java页面
[root@localhost ~]# vim index.jsp
[root@localhost ~]# cat index.jsp
<html>
<head>
        <title>test page</title>
</head>
<body>
        <%
            out.println("Hellow World");
        %>
</body>
</html>


## 启动tomcat
[root@localhost ~]# /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.
新版本查看端口号没有8009
[root@localhost ~]# ss -antl
State  Recv-Q Send-Q      Local Address:Port   Peer Address:Port                                                        
LISTEN 0      128               0.0.0.0:22          0.0.0.0:*                                                           
LISTEN 0      1      [::ffff:127.0.0.1]:8005              *:*                                                           
LISTEN 0      100                     *:8080              *:*                                                           
LISTEN 0      128                  [::]:22             [::]:*                        

验证测试文件
在这里插入图片描述

LAMT搭建

部署Mysql

# 下载环境包
[root@localhost src]# yum install -y ncurses-devel openssl-devel openssl cmake mariadb-devel

# 创建mysql用户
# [root@localhost local]# useradd -r -M -s /sbin/nologin mysql

# 创建软连接
[root@localhost local]# ln -s mysql-5.7.22-linux-glibc2.12-x86_64/ mysql;chown -R mysql.mysql mysql*

# 环境变量设置
[root@localhost local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@localhost local]# source /etc/profile.d/mysql.sh

# 创建mysql数据存放文件
[root@localhost local]# mkdir /var/mysql_data;chown mysql.mysql /var/mysql_data
# 初始化
[root@localhost local]# /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --datadir=/v
ar/mysql_data/
# 创建配置文件
[root@localhost local]# vim /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /var/mysql_data
socket = /tmp/mysql.sock
port = 3306
pid-file = /var/mysql_data/mysql.pid
user = mysql
skip-name-resolve
# 配置服务控制
[root@localhost local]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost local]# vim /etc/init.d/mysqld 
......
# overwritten by settings in the MySQL configuration files.

basedir=/usr/local/mysql
datadir=/var/mysql_data
# 开启mysql
root@localhost local]# service mysqld start
Starting MySQL.Logging to '/var/mysql_data/localhost.localdomain.err'.
 SUCCESS! 
[root@localhost local]# ss -antl
State       Recv-Q      Send-Q                Local Address:Port            Peer Address:Port      
LISTEN      0           128                         0.0.0.0:22                   0.0.0.0:*         
LISTEN      0           1                [::ffff:127.0.0.1]:8005                       *:*         
LISTEN      0           80                                *:3306                       *:*         
LISTEN      0           100                               *:8080                       *:*         
LISTEN      0           128                            [::]:22   

部署HTTP

# 下载环境及依赖文件
[root@localhost local]#yum -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++
# 解压下载好的apr,aprutil,httpd包
[root@localhost src]# tar xf apr-1.7.0.tar.bz2
[root@localhost src]# tar xf apr-util-1.6.1.tar.bz2 
[root@localhost src]# tar xf httpd-2.4.46.tar.bz2 
# 编译安装apr
[root@localhost src]# cd apr-1.7.0
[root@localhost apr-1.7.0]# vim configure
......
 cfgfile=${ofile}T
    trap "$RM "$cfgfile"; exit 1" 1 2 15
   # $RM "$cfgfile   ###注释此行
......
[root@localhost apr-1.7.0]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.7.0]# make && make install

# 编译安装http
[root@localhost apr-util-1.6.1]# cd ../httpd-2.4.46


[root@localhost httpd-2.4.46]# ./configure --prefix=/usr/local/httpd 
> --sysconfdir=/etc/httpd24 --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
......
configure: summary of build options:

    Server Version: 2.4.46
    Install prefix: /usr/local/httpd
    C compiler:     gcc
    CFLAGS:          -g -O2 -pthread  
    CPPFLAGS:        -DLINUX -D_REENTRANT -D_GNU_SOURCE  
    LDFLAGS:           
    LIBS:             
    C preprocessor: gcc -E
[root@localhost httpd-2.4.46]# make && make install

# 配置httpd
## 配置环境变量
[root@localhost ~]# echo 'export PATH=/usr/local/httpd/bin:$PATH' > /etc/profile.d/httpd.sh
[root@localhost httpd-2.4.46]# source /etc/profile.d/httpd.sh


# include文件软链接
[root@ocalhost httpd-2.4.46 ~]# ln -s /usr/local/apache/include/ /usr/include/httpd

# 修改服务名字
[root@localhost httpd-2.4.46]# vim /etc/httpd24/httpd.conf ......
# If your host doesn't have a registered DNS name, enter its IP address here.
#
ServerName localhost:80  #取消注释并修改为本机地址

# 开启apache服务
[root@localhost httpd-2.4.46]# apachectl start
[root@localhost httpd-2.4.46]# ss -antl
State       Recv-Q      Send-Q                Local Address:Port            Peer Address:Port      
LISTEN      0           128                         0.0.0.0:22                   0.0.0.0:*         
LISTEN      0           1                [::ffff:127.0.0.1]:8005                       *:*         
LISTEN      0           80                                *:3306                       *:*         
LISTEN      0           128                               *:80                         *:*         
LISTEN      0           100                               *:8080                       *:*         
LISTEN      0           128                            [::]:22               

# apache启用代理模块
[root@localhost httpd-2.4.46] vim /etc/httpd24/httpd.conf 
......
LoadModule proxy_module modules/mod_proxy.so  取消注释
LoadModule proxy_connect_module modules/mod_proxy_connect.so 取消注释
#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so 取消注释

# 配置虚拟主机文件
[root@localhost httpd24]# vim /etc/httpd24/httpd.conf
# 末尾处添加
......
<VirtualHost *:80>
    DocumentRoot "/usr/local/httpd/htdocs"
    ProxyPass / http://192.168.163.135:8080/
    ProxyPassReverse / http://192.168.163.135:8080/
    <Directory "/usr/local/httpd/htdocs">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
</VirtualHost>

验证在这里插入图片描述

最后

以上就是斯文花卷为你收集整理的Tomcat部署以及LAMT搭建的全部内容,希望文章能够帮你解决Tomcat部署以及LAMT搭建所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(32)

评论列表共有 0 条评论

立即
投稿
返回
顶部