Ubuntu Server 18.04 LTS隐藏Tomcat-9.0.16.0的版本号与操作系统类型

推荐方案

另外更推荐的方法是通过 Tomcat 的配置文件完成,而不是修改代码,具体配置方法为:

conf/server.xml 配置文件中的 <Host> 配置项中添加如下配置:

<Valve className="org.apache.catalina.valves.ErrorReportValve" showReport="false" showServerInfo="false" />

配置项说明:

  • showReport:默认值为true,默认显示报错信息
  • showServerInfo:默认值为true,默认显示Tomcat的版本号

其他方案

其他的方案跟  Ubuntu 14.04隐藏Tomcat-7.0.52的版本号与操作系统类型 是一致的,但是具体的细节上存在不小的差异,还是需要记录一下。

$ cd ~

$ mkdir catalina

$ cd catalina

$ cp /usr/share/tomcat9/lib/catalina.jar .

$ unzip catalina.jar

$ cd org/apache/catalina/util

$ vim ServerInfo.properties

可以看到里面的内容如下:

# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

server.info=Apache Tomcat/9.0.16 (Ubuntu)
server.number=9.0.16.0
server.built=Sep 11 2019 19:47:51 UTC

直接注释掉里面的内容,如下:

# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# server.info=Apache Tomcat/9.0.16 (Ubuntu)
# server.number=9.0.16.0
# server.built=Sep 11 2019 19:47:51 UTC

修改完成后,把修改完成的数据存储到catalina.jar中。

$ cd ~

$ cd catalina

$ sudo apt install openjdk-11-jdk-headless

$ jar uvf catalina.jar org/apache/catalina/util/ServerInfo.properties

把修改后的catalina.jar放回到Tomcat的目录下面:

$ cd ~

$ cd catalina

$ sudo unlink /usr/share/tomcat9/lib/catalina.jar 

$ sudo mv /usr/share/java/tomcat9-catalina.jar /usr/share/java/tomcat9-catalina.jar.old

$ sudo cp catalina.jar /usr/share/java/

$ sudo chmod +r /usr/share/java/catalina.jar

$ cd /usr/share/tomcat9/lib

$ sudo ln -s ../../java/catalina.jar catalina.jar

重启Tomcat的服务

$ sudo service tomcat9 restart

参考链接


腾讯云Ubuntu Server 16.04.7 LTS升级系统到Ubuntu Server 18.04.5 LTS之后letsencrypt证书更新出现异常“ImportError: cannot import name _remove_dead_weakref”

腾讯云`Ubuntu Server 16.04.7 LTS`升级系统到`Ubuntu Server 18.04.5 LTS`之后,`letsencrypt`证书更新出现异常,如下:

$ sudo ./letsencrypt-auto
Error: couldn't get currently installed version for /opt/eff.org/certbot/venv/bin/letsencrypt: 
Traceback (most recent call last):
  File "/opt/eff.org/certbot/venv/bin/letsencrypt", line 7, in <module>
    from certbot.main import main
  File "/opt/eff.org/certbot/venv/local/lib/python2.7/site-packages/certbot/main.py", line 2, in <module>
    from certbot._internal import main as internal_main
  File "/opt/eff.org/certbot/venv/local/lib/python2.7/site-packages/certbot/_internal/main.py", line 6, in <module>
    import logging.handlers
  File "/usr/lib/python2.7/logging/__init__.py", line 26, in <module>
    import sys, os, time, cStringIO, traceback, warnings, weakref, collections
  File "/usr/lib/python2.7/weakref.py", line 14, in <module>
    from _weakref import (
ImportError: cannot import name _remove_dead_weakref

原因为系统版本变化过大导致以前安装的`Python`组件不能适应最新的系统,最简单的方法就是删除之前安装的`Python`组件,让`letsencrypt`重新安装即可。

$ sudo apt-get install python-pip

$ sudo rm -rf /opt/eff.org/

$ sudo ./letsencrypt-auto

参考链接


Cannot renew certificate “ImportError: cannot import name _remove_dead_weakref”