tomcat管理功能, host manager, manager app, tomcat日志, ftp服务

Host Manager

  • 安装完tomcat以后,通过8080端口访问服务器,即可看到以下页面。注意右手边有两个管理功能,Manager App 和 Host Manager。
    tomcat管理界面
  • 直接点击Host Manager出现错误,如下
403 Access Denied

You are not authorized to view this page.

By default the Host Manager is only accessible from a browser running on the same machine as Tomcat. If you wish to modify this restriction, you'll need to edit the Host Manager's context.xml file.		#要使用需要修改文件;

If you have already configured the Host Manager application to allow access and you have used your browsers back button, used a saved book-mark or similar then you may have triggered the cross-site request forgery (CSRF) protection that has been enabled for the HTML interface of the Host Manager application. You will need to reset this protection by returning to the main Host Manager page. Once you return to this page, you will be able to continue using the Host Manager application's HTML interface normally. If you continue to see this access denied message, check that you have the necessary permissions to access this application.		

If you have not changed any configuration files, please examine the file conf/tomcat-users.xml in your installation. That file must contain the credentials to let you use this webapp.
#需要在conf/tomcat-users.xml文件里增加登陆信息;
For example, to add the admin-gui role to a user named tomcat with a password of s3cret, add the following to the config file listed above.
#举例增加一个角色(角色对应登陆后使用的功能);
<role rolename="admin-gui"/>
<user username="tomcat" password="s3cret" roles="admin-gui"/>
Note that for Tomcat 7 onwards, the roles required to use the host manager application were changed from the single admin role to the following two roles. You will need to assign the role(s) required for the functionality you wish to access.
#需要两个角色;
admin-gui - allows access to the HTML GUI
admin-script - allows access to the text interface
The HTML interface is protected against CSRF but the text interface is not. To maintain the CSRF protection:

Users with the admin-gui role should not be granted the admin-script role.			#注意事项;
If the text interface is accessed through a browser (e.g. for testing since this interface is intended for tools not humans) then the browser must be closed afterwards to terminate the session.
  • 信息
    这里的admin-gui和admin-script是两个Tomcat内置的角色,host-manager功能需要这两个角色的支持。其中admin-gui用于控制页面访问权限,admin-script用于控制以简单的文本的形式进行访问host-manager。

  • 操作

[root@draft conf.d]# cd /usr/local/tomcat/conf/
[root@draft conf]# vim !$
vim tomcat-users.xml	#增加以下内容;

<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<user username="tomcat" password="tomcat123" roles="admin-gui,admin-script"/>

[root@draft conf]# vim /usr/local/tomcat/webapps/host-manager/META-INF/context.xml		#增加使用服务的IP,默认可使用127.0.0.1访问,语句修改如下;

allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|192.168.87.*"/>

[root@draft conf]# /usr/local/tomcat/bin/shutdown.sh 
[root@draft conf]# /usr/local/tomcat/bin/startup.sh 
  • 再次登陆Host Manager,显示登陆界面,用户名为tomcat,密码为tomcat123(上边语句定义)
    在这里插入图片描述

    • 成功登陆界面
      在这里插入图片描述
  • 可以在这个web界面显示,创建,删除,启动,停止虚拟主机,将生成的虚拟主机保存下来。要实现全部功能还需要配置Manager App;

  • 这时可以新增域名主机,如图点击添加即可增加www.aaa.com虚拟主机;
    在这里插入图片描述

在这里插入图片描述

  • 做好hosts设置好,可通过www.aaa.com:8080访问,提示404,因为没有内容;
  • 可以在界面停止和启动虚拟主机,马上生效;停止后访问地址,显示tomcat默认界面;
  • 重启(shutdown&&startup)tomcat服务后,www.aaa.com消失;

Manager App

  • 跟Host Manager类似,目前在tomcat主界面点击Manager App,显示错误信息;
403 Access Denied

You are not authorized to view this page.

By default the Manager is only accessible from a browser running on the same machine as Tomcat. If you wish to modify this restriction, you'll need to edit the Manager's context.xml file.

If you have already configured the Manager application to allow access and you have used your browsers back button, used a saved book-mark or similar then you may have triggered the cross-site request forgery (CSRF) protection that has been enabled for the HTML interface of the Manager application. You will need to reset this protection by returning to the main Manager page. Once you return to this page, you will be able to continue using the Manager application's HTML interface normally. If you continue to see this access denied message, check that you have the necessary permissions to access this application.

If you have not changed any configuration files, please examine the file conf/tomcat-users.xml in your installation. That file must contain the credentials to let you use this webapp.
#需要帐号密码;
For example, to add the manager-gui role to a user named tomcat with a password of s3cret, add the following to the config file listed above.

<role rolename="manager-gui"/>
<user username="tomcat" password="s3cret" roles="manager-gui"/>
Note that for Tomcat 7 onwards, the roles required to use the manager application were changed from the single manager role to the following four roles. You will need to assign the role(s) required for the functionality you wish to access.
#需要增加4个角色;
manager-gui - allows access to the HTML GUI and the status pages
manager-script - allows access to the text interface and the status pages
manager-jmx - allows access to the JMX proxy and the status pages
manager-status - allows access to the status pages only
The HTML interface is protected against CSRF but the text and JMX interfaces are not. To maintain the CSRF protection:

Users with the manager-gui role should not be granted either the manager-script or manager-jmx roles.
If the text or jmx interfaces are accessed through a browser (e.g. for testing since these interfaces are intended for tools not humans) then the browser must be closed afterwards to terminate the session.
For more information - please see the Manager App How-To.
  • 信息
    manager-gui用于控制manager页面的访问,manager-script 用于控制以简单的文本的形式进行访问manager,manager-jmx用于控制jmx访问,manager-status用于控制服务器状态的查看。
  • 操作
[root@draft conf.d]# cd /usr/local/tomcat/conf/
[root@draft conf]# vim tomcat-users.xml	#结合Host Manager配置语句如下;

<role rolename="admin-gui"/>
  <role rolename="admin-script"/>
<role rolename="manager-gui"/>
  <role rolename="manager-script"/>
<role rolename="manager-jmx"/>
  <role rolename="manager-status"/>
  <user username="tomcat" password="tomcat123" roles="admin-gui,admin-script,manager-gui,manager-script,manager-jmx,manager-status"/>

[root@draft conf]# vim ../webapps/manager/META-INF/context.xml #注意这个manager目录,不是host-manager目录,增加使用服务的IP,语句修改如下;

allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|192.168.87.*"/>

[root@draft conf]# /usr/local/tomcat/bin/shutdown.sh 
[root@draft conf]# /usr/local/tomcat/bin/startup.sh 
  • 再次登陆Manager App,显示登陆界面,用户名为tomcat,密码为tomcat123,登陆后界面如下
    tomcat manager app

  • 可以管理web程序(包括Host Manager),而且不需要重启tomcat服务。包括以下功能:显示你上一个web程序管理命令的成功或失败信息;显示程序列表,帮助文件;显示程序的路径,名字,运行状态,程序的会话个数,显示可实施的命令;用这个web界面安装程序到tomcat服务器上;识别潜在问题;显示服务器信息;

  • 添加配置使Host Manager新增虚拟主机,并保存在配置文件里;

vim /usr/local/tomcat/conf/server.xml	#添加以下语句;

<Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>

新增虚拟主机并保存在配置文件里

  • 进入Host Manager
  • 配置顺序如下:
    tomcat host manager
    • 添加内容如下
      在这里插入图片描述
  • 检验
    可是否可以登陆www.173.com:8080 - 404为正常;
[root@draft conf]# ls -ld /data/wwwroot/173.com/		#新增了目录;
drwxr-x---. 2 root root 6 10月 24 15:38 /data/wwwroot/173.com/
[root@draft tomcat]# vi /usr/local/tomcat/conf/server.xml	#增加了以下配置文件;

<Host appBase="/data/wwwroot/173.com" copyXML="true" name="www.173.com">
        <Alias>173.com</Alias>
      </Host>
  • 重启tomcat虚拟主机还是存在的;

tomcat的日志

  • 路径
    /usr/local/tomcat/logs
  • 有如下几类文件
    catalina.out、catalina.xxxx-xx-xx.log、host-manager.xxxx-xx-xx.log、manager.xxxx-xx-xx.log、localhost.xxxx-xx-xx.log、xxx_access_log.xxxx-xx-xx.txt

记住一点即可,遇到问题查catalina.out,这个日志是核心日志,无论正确的信息还是错误的信息,不管是tomcat服务本身的还是tomcat跑的应用(如,zrlog)都会记录到这个日志里。

  • 两个manager日志是管理台相关的日志,不用关注。

  • 而access_log是访问日志,记录客户端访问网站的情况,这个日志其实可以不让它记,而是在前端Nginx代理上记录,所以也不用关注。

  • 这个带日期的catalina.xxxx-xx-xx.log是catalina引擎相关的日志,可以认为是tomcat服务本身的日志,其实这个也不用关注,因为它和catalina.out是重复的,也就是说这个里面记录的信息在catalina.out里就有。

  • 还有个localhost.xxxx-xx-xx.log,它主要是应用初始化(listener, filter, servlet)未处理的异常最后被tomcat捕获而输出的日志,其实也不用怎么关注。

  • 日志配置文件
    /usr/local/tomcat/conf/logging.properties

  • 里面主要定义了非访问日志的一些属性,比如日志路径、哪些日志记录到哪个文件(名字)、日志级别、存储周期等信息,这个配置文件我们一般都不会更改,保持默认即可

  • 访问日志的格式、路径是在server.xml中定义的,如下为访问日志的配置片段

<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />
  • catalina.out文件并没有日期后缀,这样就意味着该文件并不会自动切割,它会越写越大
  • 计划任务定期清空文件
0 0 */5 * * echo "" > /usr/local/tomcat/logs/catalina.out
  • 使用logrotate切割
# vim /etc/logrotate.d/tomcat  //写入如下内容
/usr/local/tomcat/logs/catalina.out  {
    copytruncate    # 创建新的catalina.out副本后,截断源catalina.out文件
    daily    # 每天进行catalina.out文件的轮转
    rotate 7     # 至多保留7个副本
    missingok    # 如果要轮转的文件丢失了,继续轮转而不报错
    compress     # 使用压缩的方式(节省硬盘空间)
    size 16M     # 当catalina.out文件大于16MB时,就轮转
}

脚本和自动启动

ftp服务

文件传输协议,可以上传和下载文件。
比如,我们可以把Windows上的文件上传到Linux上。也可以把Linux上的文件下载到windows上。当然,反过来也可以,因为FTP也可以安装在Windows上。
ftp在大公司用得比较少,汲及用户,有风险。

  • 安装pure-ftpd
yum install -y epel-release
yum install -y pure-ftpd
  • 配置pure-ftpd
vi /etc/pure-ftpd/pure-ftpd.conf

	PureDB                        /etc/pure-ftpd/pureftpd.pdb	#使用文件存放用户和密码;
	MinUID                      1000			#设置最小的使用ftp服务的用户UID;

useradd ftpuser			#新增使用ftp的用户;
mkdir /data/ftp			#ftp的访问目录;
chown ftpuser:ftpuser /data/ftp		#修改目录属主;

pure-pw useradd user1 -u ftpuser -d /data/ftp 	#制作虚拟用户user1, 映射到用户ftpuser,要输入密码;
pure-pw mkdb		#生成密码文件,文件不能cat查看;
pure-pw list 			#查看用户;

systemctl start pure-ftpd		#启动服务;

firewall-cmd --add-port=21/tcp --permanent		#开放端口;
firewall-cmd --reload		#重载防火墙;
  • 命令行本地测试
    安装lftp客户端
yum install -y lftp
lftp user1@127.0.0.1  #进入ftp的目录;
put 上传
mput 多个文件上传
get 
mget
mirror   镜像服务器 
mirror -R  反向镜像
-c  断点续传
-n 线程
  • 远程测试
    安装filezilla
    下载链接:https://filezilla-project.org/download.php?type=client

配置信息
在这里插入图片描述
在这里插入图片描述
默认连接方式访问不成功,可以更换成主动或被动模式;

  • SFTP配置方式
    使用的ssh的端口 22
    使用的是可以登陆系统的帐号和密码;也可以使用密钥登陆;
    在这里插入图片描述
    可查看的目录和内容更多,最好使用随机的密码串登陆;
    在这里插入图片描述
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值