Start tomcat services using authbind this will allow user to start ports less than 1024 we do not need to redirect or iptables.

apt-get install authbind -y

To install Authbind software

chmod -R 755 /etc/authbind

group should be user group.

chown -Rh root:group /etc/authbind

After that run the below commands

cd /etc/authbind/byuid

As an example lets imagne user id is 2000 you can use your user id number

echo '0.0.0.0/0:1,1023' > 2000

That file should be own by user and group.

chown : 2000

chmod 700 2000

Add the below line in tomcat startup file $CATALINA_BASE/startup.sh

export JAVA_OPTS="$JAVA_OPTS -Djava.net.preferIPv4Stack=true"

For Starting tomcat using Authbind service startup.sh

Comment the below line

#$CATALINA_HOME/bin/startup.sh

Add This End as the end of the file

AUTHBIND_COMMAND="/usr/bin/authbind --deep /bin/bash -c " 

$AUTHBIND_COMMAND $CATALINA_HOME/bin/startup.sh

now you should be able to start tomcat services as user with less that 1024 ports.

方法二:

http://serverfault.com/questions/615422/tomcat-cannot-change-port-8080-to-80

方法三: 

Running Tomcat on port 80 on Linux

Wednesday, 10 November 2010 18:40 | Author: Doma |   

By default Tomcat's HTTP connector listens on port 8080. Changing to port 80 in Linux environment can be quite a tricky issue, since by default listening on any port under 1024 require a privileged user, and for security considerations it is not recommended to run Tomcat with elevated permissions. This article discusses how to use authbind to achieve this; it also describes the way all this configuration can be automated for the sake of the creation of a script which can be used to initialize a freshly installed Linux instance. This is especially advantageous on Amazon EC2, where we can use this init-script to initialize a fresh instance just launched from an AMI; and indeed, for the sake of this article Amazon's "Amazon Linux Image 1.0" was used for testing. Please note that this is a CentOS 5-based linux distribution, for other distributions there are slight changes, like replacing "sudo yum install tomcat6" with "sudo apt-get install tomcat6" on Debian-based systems like Ubuntu.

In the end of the article, all the commands are summarized to facilitate one-step configuration.

Installing Tomcat

We’ll need the tomcat6 package to run Tomcat’s core components, as well as the tomcat6-admin-webapps package since we’ll use Tomcat’s Manager Application for application deployments, either thru Maven’s Cargo component or thru the web-browser. Since we’ll compile the authbind application from its sources, we’ll also need gcc, the GNU C Compiler package which contains all components to build an application on Linux. To install all this, grab a terminal and execute:

sudo yum -y install tomcat6 tomcat6-admin-webapps gcc

Usually a web server is started automatically on system boot. This can be achieved by

sudo /sbin/chkconfig --levels 235 tomcat6 on

Listening on ports<1024 in Linux with an unprivileged user

There are more options to achieve this:
-    By using authbind which authorizes specific users to specific ports under 1024
-    By using Jsvc, a set of libraries and applications for making Java applications run on UNIX more easily (Jsvc allows Tomcat application to perform some privileged operations as root (e.g. bind to a port < 1024), and then switch identity to a non-privileged user.)
-    By configuring iptables to re-route the packets from port 80 to 8080
This article describes the authbind approach. But first, let's tell Tomcat to listen on port 80 instead of 8080.

Changing Tomcat's default HTTP port

The default HTTP port is defined in /etc/tomcat6/server.xml:

<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />

We need to change this default port to 80 in server.xml. Either replace by hand, or automatically: to replace the occurrences of port=”8080” to port=”80”, execute the following script:

sudo sed -i 's/port\=\"8080\"/port\=\"80\"/' /etc/tomcat6/server.xml

The same for port 8443, which will be replaced with port 443:

sudo sed -i 's/port\=\"8443\"/port\=\"443\"/' /etc/tomcat6/server.xml

We'll start Tomcat with authbind. This can be achieved by changing Tomcat's init-script in /etc/init.d, replacing the line

TOMCAT_SCRIPT="/usr/sbin/tomcat6"

with

TOMCAT_SCRIPT="exec authbind --deep /usr/sbin/tomcat6"

Again, it can be automated like this:

sudo sed -i  's/TOMCAT_SCRIPT=\"\/usr\/sbin\/tomcat6\"/TOMCAT_SCRIPT=\"exec authbind  --deep \/usr\/sbin\/tomcat6\"/' /etc/init.d/tomcat6

We have to tell Tomcat to use the IPv4 stack by default. This can be done by appending the line CATALINA_OPTS="-Djava.net.preferIPv4Stack=true" to /etc/tomcat6/tomcat6.conf:

sudo sed -i '$ a\CATALINA_OPTS=\"-Djava\.net\.preferIPv4Stack=true\"\n' /etc/tomcat6/tomcat6.conf

Installing and configuring authbind

Authbind is installed the usual way, with the help of gcc and make. Please note: For this step to succeed, the gcc package is needed. It is already installed with the command sudo yum install gccearlier, when tomcat was installed.

cd ~fetch http://ftp.debian.org/debian/pool/main/a/authbind/authbind_2.1.1.tar.gztar xvzf authbind_2.1.1.tar.gzcd authbind-2.1.1makesudo make install

Authbind is configured with some special files, for which we can assign our arbitrary permissions for the users we want to give access to. Since Tomcat is running with the Tomcat user, we'll tell authbind to allow connections to the HTTP port 80 and the HTTPS port 443 for this account:

sudo touch /etc/authbind/byport/80sudo chmod 500 /etc/authbind/byport/80sudo chown tomcat /etc/authbind/byport/80sudo touch /etc/authbind/byport/443sudo chmod 500 /etc/authbind/byport/443sudo chown tomcat /etc/authbind/byport/443

For the changes to take effect, Tomcat has to be restarted:

sudo /etc/init.d/tomcat6 restart

To see if there is any error, the tomcat log can be consulted:

less -S /var/log/tomcat6/catalina.out

The whole script

Here is the whole script which automates all this:

sudo yum -y install tomcat6 tomcat6-admin-webapps gcc sudo sed -i 's/port\=\"8080\"/port\=\"80\"/' /etc/tomcat6/server.xmlsudo sed -i 's/port\=\"8443\"/port\=\"443\"/' /etc/tomcat6/server.xmlsudo sed -i 's/TOMCAT_SCRIPT=\"\/usr\/sbin\/tomcat6\"/TOMCAT_SCRIPT=\"exec authbind --deep \/usr\/sbin\/tomcat6\"/' /etc/init.d/tomcat6sudo sed -i '$ a\CATALINA_OPTS=\"-Djava\.net\.preferIPv4Stack=true\"\n' /etc/tomcat6/tomcat6.confcd ~fetch http://ftp.debian.org/debian/pool/main/a/authbind/authbind_2.1.1.tar.gztar xvzf authbind_2.1.1.tar.gzcd authbind-2.1.1makesudo make install	sudo touch /etc/authbind/byport/80sudo chmod 500 /etc/authbind/byport/80sudo chown tomcat /etc/authbind/byport/80sudo touch /etc/authbind/byport/443sudo chmod 500 /etc/authbind/byport/443sudo chown tomcat /etc/authbind/byport/443sudo /sbin/chkconfig --levels 235 tomcat6 onsudo /etc/init.d/tomcat6 restartcd ~
References:
http://en.wikipedia.org/wiki/Sed
http://en.wikipedia.org/wiki/Grep
http://www.unix.com/unix-desktop-dummies-questions-answers/36604-append-line-last-line-file.html
http://pwet.fr/man/linux/commandes/authbind
http://www.centos.org/docs/5/html/Installation_Guide-en-US/s1-boot-init-shutdown-sysv.html
http://netthink.com/?p=362

authbind start tomcat services as user with less that 1024 ports. linux常规用户使用tomcat的80端口的更多相关文章

  1. Jsvc安装,配置 常规用户使用tomcat的80端口

     Jsvc安装 一.下载安装包,地址如下: http://commons.apache.org/proper/commonsdaemon/download_daemon.cgi 二.安装步骤,参考链接 ...

  2. How to run Tomcat without root privileges? 常规用户使用tomcat的80端口

    How to run Tomcat without root privileges? 1. The best way is to use jsvc, available as part of the  ...

  3. IIS和tomcat共用80端口

    IIS和tomcat共用80端口 很多机器都需要同时使用tomcat和iis两个服务器以部署不同的网站,而解决共用80端口的问题也经常遇到,今天实际操作了一回,以下是具体步骤: 实现tomcat和ii ...

  4. linux系统非ROOT用户80端口不能启动tomcat问题的变通办法——通过Iptables端口转发

    2010-07-17 13:21:42 org.apache.tomcat.util.digester.SetPropertiesRule begin 警告: [SetPropertiesRule]{ ...

  5. IIS7和Tomcat7整合,即IIS7和Tomcat共用80端口

    IIS7和Tomcat7整合,即IIS7和Tomcat共用80端口 背景: 最近公司有一个项目要上线,需要用到iis和tomcat整合,共用80端口.由于公司的数据都非常重要,只通过端口映射到外网的8 ...

  6. Ubuntu下Tomcat绑定80端口(zz)

    Ubuntu下Tomcat绑定80端口 来源:本站转载 作者:佚名 时间:2011-02-22 TAG: 工作环境迁移到了Ubuntu,很多东西发生了变化,比如原先配置tomcat端口.只需要配置se ...

  7. Linux 笔记 #04# Installing Tomcat 8 on Debian

    失败一 ※ 失败二  ※ 失败三 ※ 完 1- 确认机型: root@iZwz:~# lsb_release -a LSB Version: core-2.0-amd64:core-2.0-noarc ...

  8. ubuntu下Tomcat绑定80端口

    转载自:https://www.2cto.com/os/201102/84081.html   工作环境迁移到了Ubuntu,很多东西发生了变化,比如原先配置tomcat端口.只需要配置server. ...

  9. Tomcat配置域名、ip访问及解决80端口冲突

    1.先在tomcat下的conf下找到server.xml文件,用记事本打开后,首先对端口号进行修改,以前一直以为8080是默认的端口号,其实默认的端口号是80 <Connector port= ...

随机推荐

  1. Android:ImageView应用之图片浏览器

    ImageView控件实现的简单图片浏览器 一.纯显示图片: 引言: 读者在做这个东西的时候,需要自己把图片在源程序中导入. 读者要注意:所有导入的图片之前,图片的命名只可以是小写英文和数字. 效果图 ...

  2. CF-Approximating a Constant Range

    Description When Xellos was doing a practice course in university, he once had to measure the intens ...

  3. C#的checked和unchecked

    C#的 checked关键字用于对整型算术运算和转换显式启用溢出检查. 简单点说,我们在进行数值计算时,运算结果可能会超出该类型能表达的数值范围,因而结果溢出.而这个溢出如果是含有变量的表达式的话,编 ...

  4. MarkWord - 可发布博客的 Markdown编辑器 代码开源

    因为前一段时间看到 NetAnalyzer 在Windows10系统下UI表现惨不忍睹,所以利用一段时间为了学习一下WPF相关的内容,于是停停写写,用了WPF相关的技术,两个星期做了一个Markdow ...

  5. Javascript:splice()方法实现对数组元素的插入、删除、替换及去重

    定义和用法 splice() 方法向/从数组中添加/删除项目,然后返回被删除的项目. 注释:该方法会改变原始数组. 语法: Array.prototype.splice(index,count[,el ...

  6. Javascript:charCodeAt()方法及示例

    js charCodeAt()函数说明 返回一个整数,代表指定位置上字符的 Unicode 编码.该Unicode编码为十六进制 strObj.charCodeAt(index) 参数: strObj ...

  7. 【ArcGIS 10.2新特性】地理数据(Geodatabase 和database)10.2 新特性

    1. 大数据支持 ArcGIS与Hadoop集成,将提供一个开源的工具包用于大数据的空间分析,开发者将通过该工具包构建定制化的工作流并在ArcGIS当中执行.         支持更多的大数据平台数据 ...

  8. swift 实现漂亮的粒子效果CAEmitterLayer

    一些粒子效果 我们经常会在一些游戏或者应用中看到一些炫酷的粒子效果,我们在iOS中也能很轻松的搞一些粒子效果 我们本次做得是一个下雪的效果,看下效果图 源码地址: https://github.com ...

  9. div与span

    div与span的区别: div标签属于块级元素,span标签属于行内元素,使用对比效果如下: <!DOCTYPE html> <html> <head lang=&qu ...

  10. .IIS7如何设置301重定向详解

    <?xml version="1.0" encoding="UTF-8"?> <configuration> <system.we ...