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

2018-01-22 10:43:49来源:oschina作者:hellopasswd人点击

分享

hellopasswd





配置tomcat的虚拟主机
vi /usr/local/tomcat/conf/server.xml
其中之间的配置为虚拟主机配置部分,name定义域名,appBase定义应用的目录,Java的应用通常是一个jar的压缩包,需要将jar的压缩包放到appBase目录下,不过是在它子目录root里
增加虚拟主机,编辑server.xml,增加内容
unpackWARs="ture" autoDeploy="ture"
xmlValidation="flase" xmlNamespaceAware="flase">
reloadable="ture" crossContest="ture"/>

[root@localhost ~]# vi /usr/local/tomcat/conf/server.xml
/添加
165166unpackWARs="ture" autoDeploy="ture"
167xmlValidation="false" xmlNamespaceAware="false">
168
169


[root@localhost ~]# vi /usr/local/tomcat/conf/server.xml
148149unpackWARs="true" autoDeploy="true">
150
151
153
156
157
160161prefix="localhost_access_log" suffix=".txt"
162pattern="%h %l %u %t "%r" %s %b" />
163
164

165166unpackWARs="ture" autoDeploy="ture"
167xmlValidation="false" xmlNamespaceAware="false">
168
169
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.gzjdk-8u161-linux-x64.gzzrlog-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/
docsexampleshost-managermanagerROOTzrlog-1.7.1-baaecb9-release.war
[root@localhost src]# ls /usr/local/tomcat/webapps/
docsexampleshost-managermanagerROOTzrlog-1.7.1-baaecb9-releasezrlog-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
docsexampleshost-managermanagerROOTzrlog

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


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


[root@localhost mysql]# ps aux | grep mysql
root29130.00.0 1132681608 pts/0S07:52 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/localhost.localdomain.pid
mysql30480.2 24.3 1039348 455908 pts/0Sl 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
root30960.00.0 112660 976 pts/0S+ 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
tcp600 127.0.0.1:8005 :::*LISTEN3300/java
tcp600 :::8009 :::*LISTEN3300/java
tcp600 :::80 :::*LISTEN3300/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

最新文章

123

最新摄影

闪念基因

微信扫一扫

第七城市微信公众平台