【CentOS 7Tomcat配置4】,配置tomcat的虚拟主机#180121

hellopasswd


配置tomcat的虚拟主机

  • vi /usr/local/tomcat/conf/server.xml
  • 其中<Host>和</Host>之间的配置为虚拟主机配置部分,name定义域名,appBase定义应用的目录,Java的应用通常是一个jar的压缩包,需要将jar的压缩包放到appBase目录下,不过是在它子目录root里
  • 增加虚拟主机,编辑server.xml,</Host>增加内容 <Host name="www.123.cn" appBase="" unpackWARs="ture" autoDeploy="ture" xmlValidation="flase" xmlNamespaceAware="flase"> <Contest path="" docBase="/data/wwwroot/123.cn/" debugg="0" reloadable="ture" crossContest="ture"/> </Host>
[root@localhost ~]# vi /usr/local/tomcat/conf/server.xml
/<Host
添加
    165       <Host name="www.123.cn" appBase=""
    166             unpackWARs="ture" autoDeploy="ture"
    167             xmlValidation="false" xmlNamespaceAware="false">
    168         <Context path="" docBase="/data/wwwroot/123.cn/" debug="0" reloadable="ture" crossContest="ture"/>
    169       </Host>

[root@localhost ~]# vi /usr/local/tomcat/conf/server.xml
    148       <Host name="localhost"  appBase="webapps"
    149             unpackWARs="true" autoDeploy="true">
    150 
    151         <!-- SingleSignOn valve, share authentication between web applications
    152              Documentation at: /docs/config/valve.html -->
    153         <!--
    154         <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
    155         -->
    156 
    157         <!-- Access log processes all example.
    158              Documentation at: /docs/config/valve.html
    159              Note: The pattern used is equivalent to using pattern="common" -->
    160         <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
    161                prefix="localhost_access_log" suffix=".txt"
    162                pattern="%h %l %u %t &quot;%r&quot; %s %b" />
    163 
    164       </Host>
    165       <Host name="www.123.cn" appBase=""
    166             unpackWARs="ture" autoDeploy="ture"
    167             xmlValidation="false" xmlNamespaceAware="false">
    168         <Context path="" docBase="/data/wwwroot/123.cn/" debug="0" reloadable="ture" crossContest="ture"/>
    169       </Host>

  • docBase这个参数用来定义网站的文件存放路径,如果不定义,默认是在appBase/ROOT下面,定义了docBase就以该目录为主了,其中appBase和docBase可以一样。在这一步操作过程中若遇到访问404问题,很有可能是docBase没有定义对。
  • appBase为应用存放目录,通常是需要把war包直接放到该目录下面,他会自动解压成一个程序目录。
  • 通过部署一个java应用来体会appBase和docBase目录的作用
  • cd /usr/local/src/
  • 下载zrlog wget http://dl.zrlog.com/release/zrlog-1.7.1-baaecb9-release.war
  • mv zrlog-1.7.1-baaecb9-release.war /usr/local/tomcat/webapps/
  • mv /usr/local/tomcat/webapps/zrlog-1.7.1-baaecb9-release /usr/local/tomcat/webapps/zrlog
  • 浏览器访问ip:8080/zrlog/install/
  • mv /usr/local/tomcat/webapps/zrlog/* /data/wwwroot/123.cn/
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# wget http://dl.zrlog.com/release/zrlog-1.7.1-baaecb9-release.war
--2018-01-21 06:41:59--  http://dl.zrlog.com/release/zrlog-1.7.1-baaecb9-release.war
Resolving dl.zrlog.com (dl.zrlog.com)... 117.169.71.181, 117.169.71.219, 117.169.71.191, ...
Connecting to dl.zrlog.com (dl.zrlog.com)|117.169.71.181|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7122027 (6.8M) [application/zip]
Saving to: ‘zrlog-1.7.1-baaecb9-release.war’

100%[================================================================================>] 7,122,027   2.41MB/s   in 2.8s   

2018-01-21 06:42:11 (2.41 MB/s) - ‘zrlog-1.7.1-baaecb9-release.war’ saved [7122027/7122027]

[root@localhost src]# ls
apache-tomcat-8.5.24.tar.gz  jdk-8u161-linux-x64.gz  zrlog-1.7.1-baaecb9-release.war
[root@localhost src]# cp zrlog-1.7.1-baaecb9-release.war /usr/local/tomcat/webapps/
[root@localhost src]# ls /usr/local/tomcat/webapps/
docs  examples  host-manager  manager  ROOT  zrlog-1.7.1-baaecb9-release.war
[root@localhost src]# ls /usr/local/tomcat/webapps/
docs  examples  host-manager  manager  ROOT  zrlog-1.7.1-baaecb9-release  zrlog-1.7.1-baaecb9-release.war
[root@localhost src]# cd /usr/local/tomcat/webapps/
[root@localhost webapps]# mv zrlog-1.7.1-baaecb9-release zrlog
[root@localhost webapps]# rm zrlog-1.7.1-baaecb9-release.war 
rm: remove regular file ‘zrlog-1.7.1-baaecb9-release.war’? y
[root@localhost webapps]# ls
docs  examples  host-manager  manager  ROOT  zrlog

Windows浏览器访问http://192.168.9.128/zrlog/则o 出现zrlog的安装向导

安装mysql https://my.oschina.net/hellopasswd/blog/1610178

[root@localhost mysql]# ps aux | grep mysql
root       2913  0.0  0.0 113268  1608 pts/0    S    07:52   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/localhost.localdomain.pid
mysql      3048  0.2 24.3 1039348 455908 pts/0  Sl   07:52   0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/localhost.localdomain.err --pid-file=/data/mysql/localhost.localdomain.pid --socket=/tmp/mysql.sock
root       3096  0.0  0.0 112660   976 pts/0    S+   07:58   0:00 grep --color=auto mysql

添加mysql环境变量

[root@localhost mysql]# vi /etc/profile
添加
     83 export PATH=$PATH:/usr/local/mysql/bin/
[root@localhost mysql]# source /etc/profile

设置MySQL的root密码

[root@localhost ~]# /usr/local/mysql/bin/mysqladmin -uroot password 123
Warning: Using a password on the command line interface can be insecure.

登录MySQL

[root@localhost mysql]# mysql -uroot -p123
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.35 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

创建zrlog数据库

mysql> create database zrlog;
Query OK, 1 row affected (0.00 sec)

创建用户

mysql> grant all on zrlog.* to 'zrlog'@127.0.0.1 identified by '123a';
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye

检查用户是否创建成功

[root@localhost mysql]# mysql -uzrlog -h127.0.0.1 -p123a
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.6.35 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| test               |
| zrlog              |
+--------------------+
3 rows in set (0.00 sec)

mysql> quit
Bye

Windows浏览器访问http://192.168.9.128/zrlog/ 数据库: 数据库服务器:127.0.0.1 数据库名:zrlog 数据库用户名:zrlog 数据库密码:123a 数据库端口:3306 系统信箱 Email:hellopasswd@gmail.com(自定义) 网站信息: 管理员账号:admin 管理员密码:123 管理员邮箱:hellopasswd@gmail.com 网站标题:hellopasswd 网站子标题:hello world 设置完成后,点击查看 可以使用http://192.168.9.128/zrlog/admin/login管理后台

[root@localhost ~]# mkdir /data/wwwroot/123.cn
[root@localhost ~]# mkdir /data/wwwroot/123.cn
[root@localhost ~]# mv /usr/local/tomcat/webapps/zrlog/* /data/wwwroot/123.cn/
[root@localhost ~]# /usr/local/tomcat/bin/shutdown.sh 
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/local/jdk1.8
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
[root@localhost ~]# /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/local/jdk1.8
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@localhost ~]# netstat -lntp | grep 80
tcp6       0      0 127.0.0.1:8005          :::*                    LISTEN      3300/java           
tcp6       0      0 :::8009                 :::*                    LISTEN      3300/java           
tcp6       0      0 :::80                   :::*                    LISTEN      3300/java      

Windows打开C:\Windows\System32\drivers\etc\hosts文件末行添加192.168.9.128 www.123.cn

测试是否修改成功,就看ip地址

C:\Users\Administrator>ping www.123.cn

正在 Ping www.123.cn [192.168.9.128] 具有 32 字节的数据:
来自 192.168.9.128 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.9.128 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.9.128 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.9.128 的回复: 字节=32 时间<1ms TTL=64

192.168.9.128 的 Ping 统计信息:
    数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
    最短 = 0ms,最长 = 0ms,平均 = 0ms

Windows浏览器访问http://www.123.cn/显示zrlog则成功


修改于 180121

转载于:https://my.oschina.net/hellopasswd/blog/1610194

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值