社内se × プログラマ × ビッグデータ

プログラミングなどITに興味があります。

さくら vpsに Jenkins をインストールする

似た記事は多くありますが、自分の作業結果メモとして。

1. Java version

$ java -version
openjdk version "1.8.0_272"
OpenJDK Runtime Environment (build 1.8.0_272-b10)
OpenJDK 64-Bit Server VM (build 25.272-b10, mixed mode)
※Java がインストールされていなかった場合、インストールする
sudo yum install java-1.8.0-openjdk

2. jenkins repository を登録

$ sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo
--2021-mm-dd 17:11:32--  http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo
Resolving pkg.jenkins-ci.org (pkg.jenkins-ci.org)... 52.202.51.185
Connecting to pkg.jenkins-ci.org (pkg.jenkins-ci.org)|52.202.51.185|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 85
Saving to: ‘/etc/yum.repos.d/jenkins.repo’

100%[===========================================================================================================>] 85          --.-K/s   in 0s

3. jenkins 公開鍵のインストール

sudo rpm --import https://pkg.jenkins.io/redhat/jenkins.io.key

4. jenkins インストール

$ sudo yum install jenkins
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: ty1.mirror.newmediaexpress.com
 * epel: nrt.edge.kernel.org
 * extras: ty1.mirror.newmediaexpress.com
 * updates: ty1.mirror.newmediaexpress.com
jenkins                                                                                                                       | 2.9 kB  00:00:00     
jenkins/primary_db                                                                                                            |  37 kB  00:00:00     
Resolving Dependencies
--> Running transaction check
---> Package jenkins.noarch 0:2.289.1-1.1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================================================================
 Package                           Arch                             Version                                  Repository                         Size
=====================================================================================================================================================
Installing:
 jenkins                           noarch                           2.289.1-1.1                              jenkins                            71 M

Transaction Summary
=====================================================================================================================================================
Install  1 Package

Total download size: 71 M
Installed size: 71 M
Is this ok [y/d/N]: 
Downloading packages:
jenkins-2.289.1-1.1.noarch.rpm                                                                                                |  71 MB  00:00:08     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : jenkins-2.289.1-1.1.noarch                                                                                                        1/1 
  Verifying  : jenkins-2.289.1-1.1.noarch                                                                                                        1/1 

Installed:
  jenkins.noarch 0:2.289.1-1.1                                                                                                                       

Complete!

5. 状態確認

$ systemctl status jenkins
● jenkins.service - LSB: Jenkins Automation Server
   Loaded: loaded (/etc/rc.d/init.d/jenkins; bad; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:systemd-sysv-generator(8)
⇒インストールしたばかりのため、動いていない

6. jenkins service 起動

$ sudo systemctl start jenkins

7. 自動起動を有効にする
サーバ再起動時に自動的に起動されるようにする。

$ sudo systemctl enable jenkins

# 確認
$ systemctl is-enabled jenkins
jenkins.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig jenkins --level=5
enabled

8.ポートを開放
8080 が開放されている必要がある。
さくらVPSの管理画面から、パケットフィルタ設定を開き、カスタム / TCP / 8080 を追加する。

補足:firewalld が有効で 8080 に接続できない場合
jenkins サービスを許可する登録を行う。

sudo vim /etc/firewalld/services/jenkins.xml

<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>Jenkins</short>
  <description>Jenkins</description>
  <port protocol="tcp" port="8080"/>
</service>

sudo firewall-cmd --add-service=jenkins --zone=public --permanent
sudo firewall-cmd --reload
sudo firewall-cmd --list-services --zone=public --permanent

9.初回セットアップ
yourserver.com:8080 にアクセス
※yourserver.com=自身のサーバ

f:id:blueskyarea:20210627095217p:plain

f:id:blueskyarea:20210627095235p:plain

f:id:blueskyarea:20210627095244p:plain

f:id:blueskyarea:20210627095253p:plain

f:id:blueskyarea:20210627095301p:plain

以上のステップで、jenkins のインストール完了。