Ubuntu为Tomcat启用80端口

Ubuntu为Tomcat启用80端口

一、tomcat部署调试

 

Update the package repository

sudo apt-get update
sudo apt-get upgrade --show-upgrades 

 
Install the authbind package

 

 

sudo apt-get install authbind

 
This package allows non-root users to bind to ports below 1024. Install the tomcat7 package

sudo apt-get install tomcat7

 

The tomcat7-docs, tomcat7-examples,and tomcat7-admin packages aren't required to deploy and maintain a web application. These packages can be skipped unless they are truly needed.

A new user "tomcat7" with primary group "tomcat7" will be created.



Enable authbind
Open a text editor like vim and load the default tomcat configuration file

nano /etc/default/tomcat7

 

Remove the comment hash "#" in front of the authbind property and set the value to "yes"

AUTHBIND=yes

 

Create authbind bind permission files for ports 80 and 443. Authbind will loop through the directory structure and try to find a byPort file referencing the port number attempting to be bound. Authorization will be granted if the user attempting to bind has execute permission.

touch /etc/authbind/byport/80
touch /etc/authbind/byport/443
chmod 0755 /etc/authbind/byport/80
chmod 0755 /etc/authbind/byport/443
chown tomcat7:tomcat7 /etc/authbind/byport/80
chown tomcat7:tomcat7 /etc/authbind/byport/443

 

Change the Tomcat Port from 8080/8443 to 80/443
Open a text editor like vim and load the server configuration file

nano /etc/tomcat7/server.xml

 

Find the connector for port 8080 to port 80 and the redirect port from 8443 to 443:

<Connector port="80" protocol="HTTP/1.1" 
connectiontimeout="20000" uriencoding="UTF-8" 
redirectport="443">
</Connector>

 
Restart the Tomcat service

sudo service tomcat7 restart

 
View the catalina.out log after restart and look for any errors. If you see permission denied errors, then you may have missed a step like: 
Forgetting to uncomment the AuthBind setting and putting it to "yes"
Forgetting to restart the tomcat7 service as sudo

 

最后运行netstat -ant,查看80端口是否起来 。

 

二、应用部署

 

tomcat配置成功后需要将开发的应用部署到tomcat服务器中。步骤如下:

1、将应用打包为ROOT.war

2、在/usr/share/tomcat7中创建logs目录

 

cd /usr/share/tomcat7
sudo mkdir logs
sudo chmod 755 logs

3、创建ROOT.xml文件内容如下:

 

<!-- The contents of this file will be loaded for each web application -->


<Context path="" docBase="/usr/share/tomcat7/ROOT.war" displayName="Tomcat_1" reload="false" 
        debug="0" privileged="true">

    <!-- Default set of monitored resources -->

    <WatchedResource>WEB-INF/web.xml</WatchedResource>

</Context>

   其中 docBase="/usr/share/tomcat7/ROOT.war"指向应用部署所在文件地址。

 

4、 重启tomcat

 

sudo service tomcat7 restart

 提示信息如下:

 

 * Stopping Tomcat servlet engine tomcat7
   ...done.
 * Starting Tomcat servlet engine tomcat7
   ...done.

 启动完毕后登陆应用地址查看。如还不成功请参考上述步骤修改。

### 在 Ubuntu 上配置 Tomcat 服务器的详细方法 在 Ubuntu 系统上配置 Tomcat 服务器需要完成一系列步骤,包括下载、解压、移动到指定目录、启动服务、验证服务状态以及允许外部访问等。以下是具体的配置方法: #### 一、下载并上传 Tomcat 压缩包 首先,从 Apache 官方网站下载最新版本的 Tomcat 压缩包,并将其上传到 Ubuntu 服务器上。可以通过 `wget` 命令直接下载压缩包到服务器中[^1]。 ```bash wget https://downloads.apache.org/tomcat/tomcat-9/v9.0.85/bin/apache-tomcat-9.0.85.tar.gz ``` #### 二、解压并移动到指定目录 下载完成后,使用以下命令解压压缩包并将解压后的文件夹移动到 `/usr/local/tomcat` 目录下[^3]。 ```bash tar -zxvf apache-tomcat-9.0.85.tar.gz sudo mv apache-tomcat-9.0.85 /usr/local/tomcat ``` #### 三、启动 Tomcat 服务 进入 Tomcat 的 `bin` 目录后,执行以下命令以启动 Tomcat 服务。如果已将 Tomcat 配置为系统服务,则可以使用 `systemctl` 命令来管理服务[^4]。 ```bash sudo systemctl start tomcat ``` #### 四、检查 Tomcat 服务状态 为了确保 Tomcat 服务正常运行,可以使用以下命令检查其状态[^2]。 ```bash systemctl status tomcat ``` #### 五、验证 Tomcat 启动 打开浏览器并访问 `http://<服务器IP>:8080`,如果看到 Tomcat 默认欢迎页面,则表示服务已成功启动。 #### 六、配置防火墙以允许外部访问 如果服务启用了防火墙,则需要添加规则以允许外部通过端口 8080 访问 Tomcat 服务。 ```bash sudo ufw allow 8080/tcp ``` #### 七、修改 Tomcat 配置实现远程访问 默认情况下,Tomcat 可能仅允许本地访问。为了允许远程访问,需要编辑 `server.xml` 文件,取消对 `address="localhost"` 的注释或删除该属性[^5]。 ```xml <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> ``` 保存文件后重启 Tomcat 服务以应用更改。 ```bash sudo systemctl restart tomcat ``` #### 八、停止 Tomcat 服务 如果需要停止 Tomcat 服务,可以使用以下命令[^4]。 ```bash sudo systemctl stop tomcat ``` --- ### 注意事项 - 确保已安装 Java 环境,因为 Tomcat 是基于 Java 的应用服务器。 - 如果遇到权限问题,可以尝试使用 `chmod` 或 `chown` 命令调整文件和目录权限。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值