Docker로 Jenkins를 띄우려고 했는데, 이미 8080 포트를 사용하고 있어 Jenkins 포트 번호를 바꾸고자 했다.

 

만약 Docker가 아닌 로컬에 Jenkins를 설치했다면 "/etc/default/jenkins" 파일을 수정해야 한다는 정보는 많지만

Docker의 Jenkins 기본 포트를 변경하는 정보는 많지 않았다.

 

🐳 Jenkins Docker 공식문서

https://hub.docker.com/_/jenkins

 

jenkins - Official Image | Docker Hub

DEPRECATION NOTICE This image has been deprecated for over 2 years in favor of the jenkins/jenkins:lts image provided and maintained by the Jenkins Community as part of the project's release process. The images found here have not received updates for over

hub.docker.com

 

Docker의 Jenkins 기본 포트를 변경하려면 JENKINS_OPTS를 활용해야 한다.

처음에 그냥 무작정 7070:7070만 입력했더니 젠킨스 접속이 안 되더라..

docker run -itd --env JENKINS_OPTS=--httpPort=7070 -p 7070:7070 -v ~/jenkins:/var/jenkins_home --name jenkins jenkins/jenkins:lts

JENKINS_OPTS 환경변수에 --httpPort값을 지정해주면 된다!

 

 

 

 

참고 사이트

1. 문제 상황

Jenkins POST API를 호출하니까 403 No valid crumb was included in the request 에러가 발생하였다.

 

2. 해결 방법

Jenkins Configure → Script Console

import jenkins.model.Jenkins
def instance = Jenkins.instance
instance.setCrumbIssuer(null)

스크립트를 작성 후 실행한다. 실행 후에는 Jenkins를 재시작해주어야 한다.

 

 

 

참고 사이트

배치를 수동으로 돌려야 하는 상황이 있을 수 있다.

예를 들면, DBMS에 새 버전이 나왔을 때 바로 배치를 돌려서 데이터를 추가해야 될 수도 있기 때문! 

 

웹에 [수동 배치] 같은 버튼을 만들어 놓고 누르면 젠킨스에서 배치가 돌게 하고 싶은 경우

젠킨스에서 제공하는 원격으로 빌드 유발 기능을 사용하면 된다.

 

그러면 젠킨스에 설정해 놓은 재시도 횟수, 두레이 메신저 알림 기능, 로그 확인 기능을 모두 사용할 수 있기 때문이다.

 

아래 방법을 따라서 원격으로 빌드를 유발해보자!

 


1. 토큰 발급

  • Dashboard > 사람

 

  • admin이란 이름으로 사용자를 등록했기 때문에 admin 클릭!

 

  • 설정으로 들어가서 API Token 발급

다시 들어가면 값이 사라져 있으니 잘 복사해두자!

 

2. Job 설정

  • 원격으로 빌드 유발 체크 및 토큰 이름 설정

토큰 이름은 나중에 호출할 때 사용할 것이기 때문에 띄어쓰기 없이 짧게 적어주면 된다.

 

3. 원격으로 빌드

1) Job Build

  • Parameter가 없는 build
curl -i -X POST 'http://<jenkins_username>:<jenkins_api_token>@<jenkins_url>/job/<job_name>/build?token= <token_name>'

 

값을 채워넣고 터미널에서 실행해보면 젠킨스 job이 잘 실행된다!

 

파이썬에서 구현하고자 하면

@api_view(['POST'])
def trigger_build(request):
    # 젠킨스 빌드 주소 - 파라미터 : 토큰
    jenkins_url = f"http://{jenkins_username}:{jenkins_password}@{jenkins_server}/job/{jenkins_job_name}/build?token={jenkins_token}"

    try:
        response = requests.post(jenkins_url)  # 젠킨스 빌드 주소로 post 요청 보내기

        if response.status_code == 201:  # 요청 성공
            print("[Success] Jenkins trigger builds remotely!")
            return HttpResponse("Jenkins build triggered successfully!", status=201)
        else:  # 요청 실패
            print("[Fail] Failed to trigger builds remotely. Status code:", response.status_code)
            return HttpResponse("Failed to trigger Jenkins build. Status code: " + str(response.status_code), status=500)

    except Exception as e:  # 예외 발생
        print("[Fail] Failed to trigger builds remotely. Exception:", e)
        return HttpResponse("Failed to trigger Jenkins build. Exception: " + str(e), status=500)

 

  • Build with Parameter
curl -X POST 'http://[IP]:[PORT]/job/[JOB_NAME]/build buildWithParameters --data [PARAM1]=[VALUE1] --data [PARAM2]=[VALUE2] --user [USER_NAME]:[USER_API_TOKEN]'

 

@api_view(['GET'])
def trigger_build_with_parameters(request):
    try:
        # 젠킨스 빌드 주소 - 파라미터 : 토큰, 파라미터
        jenkins_url = f"http://{jenkins_username}:{jenkins_password}@{jenkins_server}/job/{jenkins_job_name}/buildWithParameters?token={jenkins_token}&params={params}"
        response = requests.post(jenkins_url)  # 젠킨스 빌드 주소로 post 요청 보내기

        if response.status_code == 201:  # 요청 성공
            print("[Success] Jenkins trigger builds remotely!")
            return HttpResponse("Jenkins build triggered successfully!", status=201)
        else:  # 요청 실패
            print("[Fail] Failed to trigger builds remotely. Status code:", response.status_code)
            return HttpResponse("Failed to trigger Jenkins build. Status code: " + str(response.status_code), status=500)

    except Exception as e:  # 예외 발생
        print("[Fail] Failed to trigger builds remotely. Exception:", e)
        return HttpResponse("Failed to trigger Jenkins build. Exception: " + str(e), status=500)

 

2) Job Build 조회

curl -X GET 'http://[IP]:[PORT]/job/[JOB_NAME]/api/json --user [USER_NAME]:[USER_API_TOKEN]'

 

3) Job Build 결과 조회

 curl -X GET 'http://[IP]:[PORT]/job/[JOB_NAME]/[BUILD_NUM]/api/json --user [USER_NAME]:[USER_API_TOKEN]'

 

빌드 넘버를 확인하기 어려울 경우

BUILD_NUM 대신 lastStableBuild를 입력할 경우 가장 최신의 빌드 결과를 알 수 있다.

각 조회 결과는 json, xml, python 타입을 지정할 수 있다.

 curl -X GET 'http://[IP]:[PORT]/job/[JOB_NAME]/lastStableBuild/api/json --user [USER_NAME]:[USER_API_TOKEN]'

 

 

 

 

 

 

참고 사이트

1. Ubuntu 인스턴스에 CentOS 도커 컨테이너 설치

설치 환경

  • NHN Cloud
  • Ubuntu 20.04 LTS
  • Docker 23.0.1
  • CentOS 7.9

 

Workflow

  1. 설치하려는 패키지가 이미 설치되어 있는지 체크 후 다운로드
  2. Docker 공식 GPG 키 추가
  3. Docker 레포지토리 등록
  4. apt-get 업데이트
  5. Docker 설치
  6. 그룹에 사용자 추가
  7. CentOS 7 컨테이너 실행

 

설치 스크립트

#!/usr/bin/env bash

# curl 이미 설치되어 있는지 체크
if ! command -v curl &> /dev/null
then
    sudo apt-get update
    sudo apt-get install -y curl
fi

# apt-transport-https 이미 설치되어 있는지 체크
if ! dpkg -s apt-transport-https &> /dev/null
then
    sudo apt-get update
    sudo apt-get install -y apt-transport-https
fi

# ca-certificates 이미 설치되어 있는지 체크
if ! dpkg -s ca-certificates &> /dev/null
then
    sudo apt-get update
    sudo apt-get install -y ca-certificates
fi

# gnupg-agent 이미 설치되어 있는지 체크
if ! dpkg -s gnupg-agent &> /dev/null
then
    sudo apt-get update
    sudo apt-get install -y gnupg-agent
fi

# software-properties-common 이미 설치되어 있는지 체크
if ! dpkg -s software-properties-common &> /dev/null
then
    sudo apt-get update
    sudo apt-get install -y software-properties-common
fi

# Docker 공식 GPG key 이미 추가되어 있는지 체크
if ! curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key list | grep Docker &> /dev/null
then
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
fi

# Docker repository 등록
if ! apt-cache policy | grep https://download.docker.com/linux/ubuntu | grep stable &> /dev/null
then
  echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
fi

# 기본적인 패키지들이 최신 버전인지 확인
sudo apt-get update

# docker-ce 이미 설치되어 있는지 체크
if ! dpkg -s docker-ce &> /dev/null
then
    # Docker 설치
    sudo apt-get install -y docker-ce docker-ce-cli containerd.io
fi

# docker 그룹에 사용자 추가
sudo usermod -aG docker $USER

# Centos7 컨테이너 실행
sudo docker run --privileged -d -p 5432:5432 --name centos centos:7 /sbin/init
  • systemctl 명령을 사용하기 위해서 privileged로 컨테이너 실행
  • 컨테이너에 postgresql을 설치할 예정이어서 포트 5432로 실행

1. 로컬 PC에서 Vagrant로 CentOS 가상환경 띄우기

설치 환경

  • Macbook Pro Intel (2019)
  • CentOS 7.9

 

설치 스크립트

#!/usr/bin/env bash

directory="$HOME/workspace/VM/centos7"
ssh_key_file="$HOME/.ssh/id_rsa"

# Check if Homebrew is installed
if ! [ -x "$(command -v brew)" ]; then
  echo '>> Homebrew is not installed.' >&2
  /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi

# Check if VirtualBox is installed
if ! [ -x "$(command -v vboxmanage)" ]; then
  echo '>> VirtualBox is not installed.' >&2
  brew install --cask virtualbox
fi

# Check if VirtualBox Extension Pack is installed
if ! vboxmanage list extpacks | grep "Oracle VM VirtualBox Extension Pack"; then
  echo '>> VirtualBox Extension Pack is not installed.'
  rm Oracle_VM_VirtualBox_Extension_Pack-$(VBoxManage -v | cut -d r -f 1).vbox-extpack
fi

# Check if Vagrant is installed
if ! [ -x "$(command -v vagrant)" ]; then
  echo '>> Vagrant is not installed.' >&2
  brew install vagrant
fi

# Check if Ansible is installed
if ! [ -x "$(command -v ansible)" ]; then
  echo '>> Ansible is not installed.' >&2
  brew install ansible
fi

# Create directory for CentOS VM
if [ ! -d "$directory" ]
then
    mkdir -p "$directory"
fi

cd "$directory"

# Check if the required Vagrant plugins are installed
if ! vagrant plugin list | grep -q vagrant-vbguest
then
    echo ">> vagrant-vbguest plugin is not installed."
    vagrant plugin install vagrant-vbguest
fi

if ! vagrant plugin list | grep -q vagrant-disksize
then
    echo ">> vagrant-disksize plugin is not installed."
    vagrant plugin install vagrant-disksize
fi

# Initialize Vagrantfile
vagrant init

# Edit Vagrantfile
cat << EOF > Vagrantfile
ENV["LC_ALL"] = "en_US.UTF-8"
Vagrant.configure("2") do |centos|

  # All servers will run cent 7
  centos.vm.box = "centos/7"
  centos.vm.box_check_update = false
  centos.disksize.size = "60GB"

  # Create the cent1 Server
  N = 1
  (1..N).each do |i|
    hostname = "cent7-#{i}"
    centos.vm.define hostname do |host1|
      host1.vm.hostname = hostname
      host1.vm.network "private_network", ip: "192.168.56.#{10 + i}"
      host1.vbguest.auto_update = false
      host1.vm.provider "virtualbox" do |v|
        v.name = hostname
        v.memory = "2048"
        v.cpus = "2"
        v.linked_clone = "true"
        v.gui = "false"
        v.customize ['modifyvm', :id, '--graphicscontroller', 'vmsvga']
        v.customize ['modifyvm', :id, '--vram', '20']
      end
    end
  end

  # Provision with Ansible playbook
  centos.vm.provision "ansible" do |ansible|
    ansible.playbook = "init.yml"
  end
end
EOF

# Edit Ansible playbook
cat << EOF > init.yml
- name: init.yml
  hosts: all
  gather_facts: no
  become: yes
  tasks:
    - name: Create users
      user:
        name: "{{ item }}"
        shell: /bin/bash
        home: "/home/{{ item }}"
        generate_ssh_key: true
        password_lock: yes
      with_items:
        - irteam
        - irteamsu
        - centos
    - name: Add sudoers.d file
      copy:
        content: |
          %{{item}} ALL=(ALL) NOPASSWD: ALL
        dest: "/etc/sudoers.d/{{item}}"
        owner: root
        group: root
        mode: 0440
        validate: "/usr/sbin/visudo -c -f '%s'"
      with_items:
        - irteam
        - irteamsu
        - centos
    - name: Add SSH key
      authorized_key:
        user: "{{ item }}"
        state: present
        key: "{{ lookup('file', '~/.ssh/id_rsa.pub') }}"
      with_items:
        - irteam
        - irteamsu
        - centos
        - vagrant
        - root
    - name: Restart SSH service
      ansible.builtin.systemd:
        state: restarted
        name: sshd.service
EOF

# Start Vagrant VM
vagrant up

# Generate SSH key
if [[ ! -f "$ssh_key_file" ]]; then
    echo ">> Generating new SSH key..."
    ssh-keygen
fi

cat ~/.ssh/id_rsa.pub

cd "$directory"

# SSH into Vagrant VM
vagrant SSH

vagrant ssh -c "cat ~/.ssh/authorized_keys"

vagrant ssh -c 'exit'

# Print public SSH key
cat "$ssh_key_file"

# Provision Vagrant VM
vagrant provision

# Connect
ssh-keyscan -H 192.168.56.11 >> ~/.ssh/known_hosts
ssh -o StrictHostKeyChecking=no centos@192.168.56.11

 

결과

성공!

 

 

2. Ubuntu 인스턴스에서 Vagrant로 CentOS 가상환경 띄우기

설치 환경

  • NHN Cloud
  • Ubuntu 20.04 LTS
  • CentOS 7.9

 

설치 스크립트

#!/usr/bin/env bash

directory="$HOME/workspace/VM/centos7"
ssh_key_file="$HOME/.ssh/id_rsa"

# Check if wget is installed
if ! command -v wget &> /dev/null
then
    echo ">> wget is not installed."
    sudo apt-get update
    sudo apt-get install -y wget
fi

# Download and add VirtualBox public key

# Add VB repo to package manager

# Update package list
sudo apt-get update

# Install VirtualBox
sudo apt-get install -y virtualbox-6.1

# Clean up
#sudo apt-get autoremove
#sudo apt-get autoclean


# Check if VirtualBox Extension Pack is installed
if ! vboxmanage list extpacks | grep -q "Oracle VM VirtualBox Extension Pack"; then
  echo '>> VirtualBox Extension Pack is not installed.'
  wget https://download.virtualbox.org/virtualbox/6.1.42/Oracle_VM_VirtualBox_Extension_Pack-6.1.42.vbox-extpack
  rm "Oracle_VM_VirtualBox_Extension_Pack-6.1.42.vbox-extpack"
fi

# Check if Vagrant is installed
if ! [ -x "$(command -v vagrant)" ]; then
  echo '>> Vagrant is not installed.' >&2
  wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg
  sudo apt update && sudo apt install -y vagrant
fi

# Check if Ansible is installed
if ! [ -x "$(command -v ansible)" ]; then
  echo '>> Ansible is not installed.' >&2
  sudo apt install -y ansible
fi

# Create directory for CentOS VM
if [ ! -d "$directory" ]
then
    mkdir -p "$directory"
fi

cd "$directory"

# Check if the required Vagrant plugins are installed
if ! vagrant plugin list | grep -q vagrant-vbguest
then
    echo ">> vagrant-vbguest plugin is not installed."
    vagrant plugin install vagrant-vbguest
fi

if ! vagrant plugin list | grep -q vagrant-disksize
then
    echo ">> vagrant-disksize plugin is not installed."
    vagrant plugin install vagrant-disksize
fi

# Initialize Vagrantfile
vagrant init

# Edit Vagrantfile
cat << EOF > Vagrantfile
ENV["LC_ALL"] = "en_US.UTF-8"
Vagrant.configure("2") do |centos|

  # All servers will run cent 7
  centos.vm.box = "centos/7"
  centos.vm.box_check_update = false
  centos.disksize.size = "60GB"

  # Create the cent1 Server
  N = 1
  (1..N).each do |i|
    hostname = "cent7-#{i}"
    centos.vm.define hostname do |host1|
      host1.vm.hostname = hostname
      host1.vm.network "private_network", ip: "192.168.56.#{10 + i}"
      host1.vbguest.auto_update = false
      host1.vm.provider "virtualbox" do |v|
        v.name = hostname
        v.memory = "2048"
        v.cpus = "2"
        v.linked_clone = "true"
        v.gui = "false"
        v.customize ['modifyvm', :id, '--graphicscontroller', 'vmsvga']
        v.customize ['modifyvm', :id, '--vram', '20']
      end
    end
  end

  # Provision with Ansible playbook
  centos.vm.provision "ansible" do |ansible|
    ansible.playbook = "init.yml"
  end
end
EOF

# Edit Ansible playbook
cat << EOF > init.yml
- name: init.yml
  hosts: all
  gather_facts: no
  become: yes
  tasks:
    - name: Create users
      user:
        name: "{{ item }}"
        shell: /bin/bash
        home: "/home/{{ item }}"
        generate_ssh_key: true
        password_lock: yes
      with_items:
        - irteam
        - irteamsu
        - centos
    - name: Add sudoers.d file
      copy:
        content: |
          %{{item}} ALL=(ALL) NOPASSWD: ALL
        dest: "/etc/sudoers.d/{{item}}"
        owner: root
        group: root
        mode: 0440
        validate: "/usr/sbin/visudo -c -f '%s'"
      with_items:
        - irteam
        - irteamsu
        - centos
    - name: Add SSH key
      authorized_key:
        user: "{{ item }}"
        state: present
        key: "{{ lookup('file', '~/.ssh/id_rsa.pub') }}"
      with_items:
        - irteam
        - irteamsu
        - centos
        - vagrant
        - root
    - name: Restart SSH service
      ansible.builtin.systemd:
        state: restarted
        name: sshd.service
EOF

# Start Vagrant VM
vagrant up

# Generate SSH key
if [[ ! -f "$ssh_key_file" ]]; then
    echo ">> Generating new SSH key..."
    ssh-keygen
fi

cat ~/.ssh/id_rsa.pub

cd "$directory"

# SSH into Vagrant VM
vagrant SSH

vagrant ssh -c "cat ~/.ssh/authorized_keys"

vagrant ssh -c 'exit'

# Print public SSH key
cat "$ssh_key_file"

# Provision Vagrant VM
vagrant provision

# Connect
#ssh centos@192.168.56.11
ssh-keyscan -H 192.168.56.11 >> ~/.ssh/known_hosts
ssh -o StrictHostKeyChecking=no centos@192.168.56.11

 

결과

실패..

 

에러 상황

  • NHN 클라우드 ubuntu 인스턴스에서 vagrant로 centos 가상환경을 띄우려고 함
  • vagrant up 단계에서 에러가 발생해 다음 단계로 넘어가지 못 함

There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["startvm", "d7c9b9b1-a0d1-4ff2-b119-3a33f10a1540", "--type", "gui"]

Stderr: VBoxManage: error: The virtual machine 'cent7-1' has terminated unexpectedly during startup because of signal 6
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component MachineWrap, interface IMachine

 

시도해본 방법

  • 호스트 재부팅 - 실패
  • virtualbox와 virtualbox extension pack 버전 맞추기 - 실패
  • VM headless 모드로 시작 - 시도 전

 

결론

설치를 진행하고 있는 ubuntu 자체가 인스턴스 환경이어서 그 위에 또 가상환경(VM)을 띄우는게 불가능한 것으로 판단..

vagrant 대신 호스트 OS 위에 하이퍼바이저를 띄우지 않는 구조인 docker로 진행하기로 결정!

1. CentOS에 PostgreSQL 설치

설치 환경

  • NHN Cloud 인스턴스 또는 Docker 컨테이너
  • CentOS 7.9

 

Workflow

  1. 스크립트 실행시 설치하고자 하는 버전이 입력되었는지 확인
  2. 설치하고자 하는 PC의 OS, 아키텍처가 적합한지 확인
  3. CentOS 7인지 확인
  4. PostgreSQL이 이미 설치된 경우 제거
  5. 필요한 패키지 설치 및 yum 레포지토리 업데이트
  6. PostgreSQL 설치
  7. 초기화 및 유저 비밀번호 설정
  8. 외부 접속을 위한 pg_hba.conf와 postgresql.conf 수정 및 재시작
  9. PostgreSQL 실행

 

설치 스크립트

#!/usr/bin/env bash

# 설치하고자 하는 버전
version=$1
major_version=${version%%.*}  # 15.2 -> 15

# 설치하려는 버전 번호를 받았는지 확인
if [ $# -eq 0 ]; then
    echo -e "\033[31;1m>> Error: Version number is missing. Usage: ./install_postgres_yum.sh <version>\033[0m"
    exit 1
fi

# OS가 Linux x86_64인지 확인
if [ "$(uname -s)" != "Linux" ]; then
    echo -e "\033[31;1m>> Error: Your OS is not supported.\033[0m"
    exit 1
fi
if [ "$(uname -m)" != "x86_64" ]; then
    echo -e "\033[31;1m>> Error: Your architecture is not supported.\033[0m"
    exit 1
fi

# CentOS가 Enterprise Linux 7 (EL7)인지 확인
if [ "$(rpm -q --queryformat '%{VERSION}' centos-release)" != "7" ]; then
    echo -e "\033[31;1m>> Error: This script is only compatible with Enterprise Linux 7 (EL7)\033[0m"
    exit 1
fi

# PostgreSQL이 이미 설치되어 있다면 제거
if yum list installed | grep postgresql; then
    echo -e "\033[31;1m>> Remove PostgreSQL already installed...\033[0m"
    sudo yum -y remove postgresql*
fi

# 필요한 패키지 설치
echo -e "\033[31;1m>> Install required packages...\033[0m"
yum install -y sudo
sudo yum -y update
sudo yum install -y epel-release
sudo yum install -y zstd

# PostgreSQL 설치
echo -e "\033[31;1m>> Install PostgreSQL...\033[0m"
sudo yum install -y https://download.postgresql.org/pub/repos/yum/${major_version}/redhat/rhel-7-x86_64/postgresql${major_version}-libs-${version}-1PGDG.rhel7.x86_64.rpm
sudo yum install -y https://download.postgresql.org/pub/repos/yum/${major_version}/redhat/rhel-7-x86_64/postgresql${major_version}-${version}-1PGDG.rhel7.x86_64.rpm
sudo yum install -y https://download.postgresql.org/pub/repos/yum/${major_version}/redhat/rhel-7-x86_64/postgresql${major_version}-server-${version}-1PGDG.rhel7.x86_64.rpm

# 초기화
echo -e "\033[31;1m>> Initialize PostgreSQL...\033[0m"
sudo /usr/pgsql-${major_version}/bin/postgresql-${major_version}-setup initdb

# 시작
echo -e "\033[31;1m>> Start PostgreSQL...\033[0m"
sudo systemctl start postgresql-${major_version}
sudo systemctl enable postgresql-${major_version}

# 유저 생성
username="postgres"
password="nhnpostgres123"

sudo adduser $username
echo "$username:$password" | sudo chpasswd

# postgres user로 변경 후 설정파일 수정
echo -e "\033[31;1m>> Edit pg_hba.conf and postgresql.conf\033[0m"
sudo su - postgres <<EOF
    echo "host    all             all             133.186.251.35/22       md5" >> /var/lib/pgsql/${major_version}/data/pg_hba.conf

    sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/g" /var/lib/pgsql/${major_version}/data/postgresql.conf

    exit
EOF

# 재시작
echo -e "\033[31;1m>> Restart PostgreSQL...\033[0m"
sudo systemctl restart postgresql-${major_version}

# 실행
echo -e "\033[31;1m>> Run PostgreSQL...\033[0m"
sudo su - postgres -c "psql"

 

설치 환경

  • NHN Cloud
  • Ubuntu 20.04 LTS
  • Jenkins 2.397

 

⚠️ 주의 !

2023년 3월 28일부터 Linux 설치 패키지에 대한 새로운 레포지토리 서명 키를 사용합니다.

Jenkins 2.397 설치하기 전에 새 서명 키로 설치해야 합니다!

 

구글링 했을 때 나오는 정보들은 예전 거여서 무조건 에러가 발생하니까 당황하지 말고 공식 문서를 참고합시다..!

 

Jenkins 2.397 and 2.387.2: New Linux Repository Signing Keys

Update Red Hat compatible operating systems (Red Hat Enterprise Linux, Alma Linux, CentOS, Fedora, Oracle Linux, Rocky Linux, Scientific Linux, etc.) with the command: Red Hat/CentOS $ sudo rpm --import https://pkg.jenkins.io/redhat/jenkins.io-2023.key

www.jenkins.io

 

설치 과정 

1. 시스템에 젠킨스 레포지토리 추가

curl -fsSL https://pkg.jenkins.io/debian/jenkins.io-2023.key | sudo tee \
  /usr/share/keyrings/jenkins-keyring.asc > /dev/null
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
  https://pkg.jenkins.io/debian binary/ | sudo tee \
  /etc/apt/sources.list.d/jenkins.list > /dev/null

 

2. apt 업데이트

sudo apt update

 

3. 젠킨스 설치

sudo apt install jenkins

 

4. 접속

http://{인스턴스 IP}:8080

 

⚠️ 접속이 안 된다면 ?

  • 보안그룹에 8080 포트 열어주었는지 확인
  • jenkins status 확인
# jenkins status 확인
sudo systemctl status jenkins

# jenkins 시작
sudo systemctl start jenkins
  • 8080 포트 열려있는지 확인
sudo ufw status

# Status: inactive 라면
sudo ufw allow 8080

sudo ufw allow OpenSSH

sudo ufw enable

sudo ufw status

 

5. 설정

  • 초기 비밀번호 위치 : /var/lib/jenkins/secrets/initialAdminPassword

 

6. 완료

설정 단계를 차례대로 진행하다 보면..

젠킨스 웹 인터페이스 접속 완료!

+ Recent posts