zoukankan      html  css  js  c++  java
  • Tomcat及LAMT架构搭建

    Tomcat介绍

    Tomcat 服务器是一个免费的开放源代码的Web 应用服务器,是开发和调试JSP 程序的首选。

    实际上Tomcat是Apache 服务器的扩展,但运行时它是独立运行的,所以当你运行tomcat 时,它实际上作为一个与Apache 独立的进程单独运行的.

    配置LAMT

    实验环境

    系统 主机IP 服务
    CenOS8 192.168.197.147 HTTP
    Mysql
    Tomcat

    部署Tomcat

    • 配置JAVA环境(JDK)
    # 安装JDK环境
    [root@localhost ~]# yum install -y java-1.8.0-openjdk*
    ......
    Complete!
    
    • 下载解压tomcat
    [root@localhost src]# wget https://archive.apache.org/dist/tomcat/tomcat-10/v10.0.0-M10/bin/apache-tomcat-10.0.0-M10.tar.gz
    --2020-11-26 10:27:49--  https://archive.apache.org/dist/tomcat/tomcat-10/v10.0.0-M10/bin/apache-tomcat-10.0.0-M10.tar.gz
    ......
    2020-11-26 10:30:57 (59.3 KB/s) - ‘apache-tomcat-10.0.0-M10.tar.gz’ saved [11310078/11310078]
    
    [root@localhost src]# tar xf apache-tomcat-10.0.0-M10.tar.gz -C /usr/local
    [root@localhost src]# cd /usr/local
    [root@localhost local]# ls
    apache-tomcat-10.0.0-M10  bin  etc  games  include  lib  lib64  libexec  sbin  share  src
    
    # 创建软链接
    [root@localhost local]# ln -s apache-tomcat-10.0.0-M10/ tomcat
    
    [root@localhost local]# cd tomcat/
    [root@localhost tomcat]# ls
    bin           conf             lib      logs    README.md      RUNNING.txt  webapps
    BUILDING.txt  CONTRIBUTING.md  LICENSE  NOTICE  RELEASE-NOTES  temp         work
    
    • 创建index.jsp文件
    [root@localhost tomcat]# cd webapps/
    [root@localhost webapps]# ls
    docs  examples  host-manager  manager  ROOT
    [root@localhost webapps]# touch test
    [root@localhost webapps]# vim index.jsp
    
    <html>
    <head> 
            <title>test page</title>
    </head> 
    <body>  
             <%      
                    out.println("Hellow World");
             %>     
    </body>
    </html>
    
    • 开启tomcat服务
    [root@localhost webapps]# /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
    Using CATALINA_OPTS:   
    Tomcat started.
    [root@localhost webapps]# 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                      [::]:*
    
    • 访问tomcat主页

    • 访问test目录内容

    • 主页上Server status,Manager App,Host Manager 出现403拒绝访问

    • 解决方案

    [root@localhost webapps]# vim usr/local/tomcat/conf/tomcat-users.xml
    ......
    <role rolename="manager-gui"/>
    <role rolename="admin-gui"/>
    <user username="tomcat" password="123456" roles="admin-gui,manager-gui"/>
    </tomcat-users>
    
        ##文件尾部添加角色名及用户密码
    
    
    ##  在manager/context文件中添加本机ip
    [root@localhost manager]# vim META-INF/context.xml 
    ......
    <Valve className="org.apache.catalina.valves.RemoteAddrValve"
             allow="192.168.197.d+|127.d+.d+.d+|::1|0:0:0:0:0:0:0:1" />     ## 在allow中添加本网段地址
             
             
             
    ##  同理,添加host-manager配置文件中Ip
    [root@localhost local]# vim tomcat/webapps/host-manager/META-INF/context.xml
    ......
      <Valve className="org.apache.catalina.valves.RemoteAddrValve"
              allow="192.168.197.d+|127.d+.d+.d+|::1|0:0:0:0:0:0:0:1" />
    ......
    
    ## 重启服务
    [root@localhost local]# /usr/local/tomcat/bin/catalina.sh stop;/usr/local/tomcat/bin/catalina.sh start
    ......
    Tomcat started.
    
    • 访问成功

    部署Mysql

    [root@localhost src]# tar -xf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C /usr/local
    
    # 下载环境包
    [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
    
    • 初始化mysql
    [root@localhost local]# /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --datadir=/v
    ar/mysql_data/
    2020-11-26T07:21:44.110055Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2020-11-26T07:21:45.483929Z 0 [Warning] InnoDB: New log files created, LSN=45790
    2020-11-26T07:21:45.618106Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    2020-11-26T07:21:45.630521Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 0a2f7fa9-2fb8-11eb-ac9d-000c29c8f0f8.
    2020-11-26T07:21:45.632380Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    2020-11-26T07:21:45.633021Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
    
    • 创建配置文件
    [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                      [::]:*         
    [root@localhost local]# mysql
    ......
    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
    
    mysql>
    

    部署HTTP

    • 下载环境及依赖文件
    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
    ......
    
    • 编译apr-util
    [root@localhost apr-1.7.0]# cd ../apr-util-1.6.1
    
    [root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
    ......
    
    [root@localhost apr-util-1.6.1]# 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@wnz ~]# 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.197.147:8080/
        ProxyPassReverse / http://192.168.197.147:8080/
        <Directory "/usr/local/httpd/htdocs">
            Options none
            AllowOverride none
            Require all granted
        </Directory>
    </VirtualHost>
    
    • 直接访问80端口,web会跳转到8080端口
  • 相关阅读:
    SQL Server 中的事务与事务隔离级别以及如何理解脏读, 未提交读,不可重复读和幻读产生的过程和原因
    微软BI 之SSIS 系列
    微软BI 之SSIS 系列
    微软BI 之SSIS 系列
    微软BI 之SSIS 系列
    微软BI 之SSIS 系列
    微软BI 之SSAS 系列
    微软BI 之SSRS 系列
    微软BI 之SSRS 系列
    配置 SQL Server Email 发送以及 Job 的 Notification通知功能
  • 原文地址:https://www.cnblogs.com/sawyer95/p/14054302.html
Copyright © 2011-2022 走看看