Table of Contents
1 Jenkinsのインストール
Jenkinsのリポジトリを追加してインストールします.
> sudo zypper ar -f http://pkg.jenkins-ci.org/opensuse-stable/ jenkins> sudo zypper -n –gpg-auto-import-keys up> sudo zypper -n in jenkins> sudo systemctl start jenkins
Jenkinsが使うTCPポートは/etc/sysconfig/jenkinsのJENKINS_PORTを変更します。デフォルトだとポートは8080です。以下の手順でJENKINS_PORTのポートを開放します。
> firewall_open_tcp(){ for t in FW_SERVICES_EXT_TCP FW_SERVICES_DMZ_TCP FW_SERVICES_INT_TCP; do sudo sed -e “s/^${t}=”(.*)”/${t}=”1 $1″/g” -i /etc/sysconfig/SuSEfirewall2 done sudo systemctl restart SuSEfirewall2}> firewall_open_tcp 8080
以下のURL経由でJenkinsへアクセスできるようになります。
http://<server>:8080
2 mod_proxyを利用する
Apache2をインストールします。
> sudo zypper -n in apache2
jenkins用の設定ファイルを追加します。8080はJENKINS_PORTの値です。
> sudo su -c ‘cat <<EOF > /etc/apache2/conf.d/jenkins.conf<IfModule mod_proxy.c> ProxyPass /jenkins http://localhost:8080/jenkins ProxyPassReverse /jenkins http://localhost:8080/jenkins ProxyRequests Off AllowEncodedSlashes NoDecode <Proxy http://localhost:8080/jenkins> Order deny,allow Allow from all </Proxy></IfModule>EOF’
mod_proxyとmod_proxy_httpを有効にして、Apache2を再起動します。
> sudo a2enmod proxy> sudo a2enmod proxy_http> sudo systemctl restart apache2
Apache2用のポートを開放します。
> firewall_open_service(){ for t in FW_CONFIGURATIONS_EXT FW_CONFIGURATIONS_DMZ FW_CONFIGURATIONS_INT; do sudo sed -e “s/^${t}=”(.*)”/${t}=”1 $1″/g” -i /etc/sysconfig/SuSEfirewall2 done sudo systemctl restart SuSEfirewall2}> firewall_open_service apache2
Jenkinsで/jenkinsというURIを使用するように変更します。
> sudo sed -i -e ‘s;JENKINS_ARGS=”(.*)”;JENKINS_ARGS=”–prefix=/jenkins 1″;g’ /etc/sysconfig/jenkins> sudo systemctl restart jenkins
以下のURL経由でJenkinsへアクセスできるようになります。
http://<server>/jenkins
JENKINS_PORTが開放されている場合、以下のURLでもアクセスできるようになっています。不必要ならJENKINS_PORTを開放しないようにしてください。
http://<server>:8080/jenkins
3 Jenkinsインストールとmod_proxy設定用のスクリプト
以下のスクリプトを実行すれば、Jenkinsのインストールからmod_proxyの設定までを実施できます。
#!/bin/shfirewall_open_tcp(){ for t in FW_SERVICES_EXT_TCP FW_SERVICES_DMZ_TCP FW_SERVICES_INT_TCP; do sudo sed -e “s/^${t}=”(.*)”/${t}=”1 $1″/g” -i /etc/sysconfig/SuSEfirewall2 done sudo systemctl restart SuSEfirewall2}firewall_open_service(){ for t in FW_CONFIGURATIONS_EXT FW_CONFIGURATIONS_DMZ FW_CONFIGURATIONS_INT; do sudo sed -e “s/^${t}=”(.*)”/${t}=”1 $1″/g” -i /etc/sysconfig/SuSEfirewall2 done sudo systemctl restart SuSEfirewall2}sudo zypper ar -f http://pkg.jenkins-ci.org/opensuse-stable/ jenkinssudo zypper -n –gpg-auto-import-keys upsudo zypper -n in jenkins# Comment out if you need.# firewall_open_tcp 8080sudo zypper -n in apache2sudo su -c ‘cat <<EOF > /etc/apache2/conf.d/jenkins.conf<IfModule mod_proxy.c> ProxyPass /jenkins http://localhost:8080/jenkins ProxyPassReverse /jenkins http://localhost:8080/jenkins ProxyRequests Off AllowEncodedSlashes NoDecode <Proxy http://localhost:8080/jenkins> Order deny,allow Allow from all </Proxy></IfModule>EOF’sudo a2enmod proxysudo a2enmod proxy_httpsudo systemctl restart apache2firewall_open_service apache2sudo sed -i -e ‘s;JENKINS_ARGS=”(.*)”;JENKINS_ARGS=”–prefix=/jenkins 1″;g’ /etc/sysconfig/jenkinssudo systemctl start jenkins