Cómo configurar Jenkins para que se ejecute en el puerto 80


Estoy ejecutando Ubuntu 11.10 y he ejecutado sudo apt-get install jenkins para instalar Jenkins en este sistema.

He visto algunos tutoriales sobre cómo configurar un proxy inverso (Apache, Nginx, etc.), sin embargo, esta es una máquina virtual dedicada solo para jenkins y me gustaría mantenerla lo más ajustada posible mientras jenkins se ejecuta en el puerto 80.

He encontrado la configuración de inicio en /etc/init/jenkins.conf y modificado el puerto a 80 env HTTP_PORT=80

Cuando empiezo jenkins vía service jenkins start, ps revela que se ejecuta durante unos segundos y luego termina.

¿Es porque jenkins se está ejecutando como el usuario jenkins en un puerto privilegiado? Si es así, ¿cómo lo arreglo? Cualquier otra idea es bienvenida.

Aquí está la configuración inicial:

description "jenkins: Jenkins Continuous Integration Server"
author "James Page <[email protected]>"

start on (local-filesystems and net-device-up IFACE!=lo)
stop on runlevel [!2345]

env USER="jenkins"
env GROUP="jenkins"
env JENKINS_LOG="/var/log/jenkins"
env JENKINS_ROOT="/usr/share/jenkins"
env JENKINS_HOME="/var/lib/jenkins"
env JENKINS_RUN="/var/run/jenkins"
env HTTP_PORT=80
env AJP_PORT=-1
env JAVA_OPTS=""
env JAVA_HOME="/usr/lib/jvm/default-java"

limit nofile 8192 8192

pre-start script
    test -f $JENKINS_ROOT/jenkins.war || { stop ; exit 0; }
    $JENKINS_ROOT/bin/maintain-plugins.sh   
    mkdir $JENKINS_RUN > /dev/null 2>&1  || true
    chown -R $USER:$GROUP $JENKINS_RUN || true
end script

script
    JENKINS_ARGS="--webroot=$JENKINS_RUN/war --httpPort=$HTTP_PORT --ajp13Port=$AJP_PORT"
    exec daemon --name=jenkins --inherit --output=$JENKINS_LOG/jenkins.log --user=$USER \
        -- $JAVA_HOME/bin/java $JAVA_OPTS -jar $JENKINS_ROOT/jenkins.war $JENKINS_ARGS \
        --preferredClassLoader=java.net.URLClassLoader
end script
Author: hafichuk, 2012-02-17

9 answers

Dale una oportunidad a ' authbind':

sudo apt-get install authbind
sudo touch /etc/authbind/byport/80
sudo chmod 500 /etc/authbind/byport/80 
sudo chown jenkins /etc/authbind/byport/80

Luego modifique el script anterior para tener (agregar authbind antes de la parte $JAVA_HOME/bin/java):

exec daemon --name=jenkins --inherit --output=$JENKINS_LOG/jenkins.log \
--user=$USER -- authbind $JAVA_HOME/bin/java $JAVA_OPTS \
-jar $JENKINS_ROOT/jenkins.war $JENKINS_ARGS \
--preferredClassLoader=java.net.URLClassLoader

Para instalaciones Jenkins más recientes (1.598) en instalaciones Ubuntu más recientes (14.04) edite /etc/init.d/jenkins y agregue authbind antes de $JAVA

$SU -l $JENKINS_USER --shell=/bin/bash -c "$DAEMON $DAEMON_ARGS -- authbind $JAVA $JAVA_ARGS -jar $JENKINS_WAR $JENKINS_ARGS" || return 2

Como menciona Alan (ver comentario más abajo) si necesita IPv6 y su sistema es inferior a Quantal, puede en lugar de usar apt-get para instalar authbind descargar una versión superior. Asegúrate de tener libc6 y libc6-udeb instalados. Aquí está authbind la versión 2.1.1 de Ubuntu:

Luego ejecutar:

sudo dpkg -i authbind_2.1.1_amd64.deb
# or sudo dpkg -i authbind_2.1.1_i386.deb

sudo touch /etc/authbind/byport/80
sudo chmod 500 /etc/authbind/byport/80 
sudo chown jenkins /etc/authbind/byport/80
 29
Author: JScoobyCed,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 10:30:55

Otra solución es simplemente usar iptables para redirigir el tráfico entrante de 80 a 8080. Las reglas se verían como:

-A INPUT -i eth0 -p tcp --dport 80 -j ACCEPT
-A INPUT -i eth0 -p tcp --dport 8080 -j ACCEPT
-A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080

Reformateado como un iptables.archivo de reglas:

*filter
:INPUT ACCEPT [100:100000]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [95:9000]
-A INPUT -i eth0 -p tcp --dport 80 -j ACCEPT
-A INPUT -i eth0 -p tcp --dport 8080 -j ACCEPT
COMMIT

*nat
-A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
COMMIT

La ventaja de un iptable.el archivo de reglas es que las reglas pueden persistir después de los reinicios. Solo asegúrese de integrar cualquier otra regla iptable actual en el mismo archivo!

En Redhat/CentOS este archivo puede ir en /etc/sysconfig/iptables.

En los sistemas Debian / Ubuntu se pueden guardar en /etc/iptables/rules.v4 usando el iptables-persistent paquete. O el iptable.las reglas se pueden llamar modificando /etc/network/interfaces o conectándose a if-up/if-down guiones. La wiki de la Comunidad de Ubuntu tiene una gran página explicando estos métodos.

Como suele ser el caso con las redes, hay muchas maneras diferentes de lograr el mismo resultado. ¡Usa lo que funciona mejor para ti!

 41
Author: Chris Laskey,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-01-15 22:19:57
  1. Vaya a la carpeta/etc / default Open > Abra el archivo "jenkins"
  2. Modifique la línea HTTP_PORT=8080 como HTTP_PORT = 80
  3. Inicie jenkins como root usando el comando: sudo /etc/init.d / jenkins start
  4. Abre un navegador y navega como localhost: 80

Eso es todo

 34
Author: Ripon Al Wasim,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-06-19 07:53:23

Sugiero usar apache y mod_proxy. Esto es lo que hago, y mi configuración de vhost se parece un poco a esto (también redirijo para SSL, pero puede omitir eso):

<VirtualHost *:443>
ServerAdmin [email protected]
ServerName ci.example.com

ProxyRequests Off
<Proxy *>
    Order deny,allow
    Allow from all
</Proxy>
ProxyPreservehost on
ProxyPass / http://localhost:8080/

Header edit Location ^http://ci.example.com/ https://ci.example.com/

SSLEngine on
SSLCertificateFile /etc/apache2/keys/apache.pem
</VirtualHost>
 7
Author: regulatethis,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-04-24 17:07:20

Desde que usé docker. Puede usarlo para ejecutar jenkins en el puerto 80, de aquí en adelante un fragmento de mi script:

JENKINS_PORT=80
JENKINS_HOME=/home/jenkins
/usr/bin/docker run -d -p $JENKINS_PORT:8080 -v $JENKINS_HOME jenkins
 1
Author: Ali SAID OMAR,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-05-13 13:06:54

El camino de firewalld para adelantar el puerto 8080 al 80:

yum install firewalld
systemctl start firewalld
chkconfig firewalld on
firewall-cmd --permanent --zone=external --change-interface=eth0
firewall-cmd --permanent --zone=external --add-forward-port=port=80:proto=tcp:toport=8080
 0
Author: Greg,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-11-24 23:25:02

Ninguna de las respuestas dice cómo redirigir simplemente 80 a 8080 con iptables.
Afortunadamente, dskrvk ' s comentario lo hace !

También hay un[7]} wiki de Jenkins documentando esto


Solo tuve que copiar / pegar esas líneas en mi terminal para que la redirección funcionara :

sudo iptables -I INPUT 1 -p tcp --dport 8443 -j ACCEPT
sudo iptables -I INPUT 1 -p tcp --dport 8080 -j ACCEPT
sudo iptables -I INPUT 1 -p tcp --dport 443 -j ACCEPT
sudo iptables -I INPUT 1 -p tcp --dport 80 -j ACCEPT
sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 443 -j REDIRECT --to-port 8443

Por cierto, no olvide incluirlo en los scripts de inicio de su servidor una vez probados, o perderá la redirección después de un reinicio. Probado en Debian 8.2 (Jessie)

 0
Author: Balmipour,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-01-05 17:33:47

En Ubuntu 16.04, este wiki explica cómo hacerlo.

sudo nano /etc/rc.local

Luego agregue lo siguiente justo antes de la salida 0

#Requests from outside
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8080
#Requests from localhost
iptables -t nat -I OUTPUT -p tcp -d 127.0.0.1 --dport 80 -j REDIRECT --to-ports 8080

Ahora reinicie o ejecute sudo /etc/rc.local para habilitar el reenvío de puertos

 0
Author: Katu,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-03-20 09:08:31

Cambiar /etc/default/jenkins no funciona en mi configuración ubunutu 16.-4 Jenkins 2.89.4 y la solución para usar rutas iptables 80 a 8080 whis el contrario del resultado requerido de ejecutar jenkins en 80

 0
Author: Barak,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-05-13 17:19:42