Skip to content

Latest commit

 

History

History
213 lines (153 loc) · 7.84 KB

Gitlab.md

File metadata and controls

213 lines (153 loc) · 7.84 KB

วิธีการติดตั้ง Gitlab CE

Update & Upgrade Packages

sudo apt update && sudo apt upgrade -y

Pastedimage20240801201244.png

ตั้งค่า Time Zone

sudo timedatectl set-timezone Asia/Bangkok

ติดตั้ง Packages ที่จำเป็นต้องใช้

sudo apt install build-essential curl openssh-server tzdata debian-archive-keyring lsb-release ca-certificates apt-transport-https software-properties-common

Pastedimage20240801201354.png

ติดตั้ง Gitlab Version CE

curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash

Pastedimage20240801201542.png

sudo apt install gitlab-ce

Pastedimage20240801201613.png

แก้ไขการตั้งค่า Base URL

sudo nano /etc/gitlab/gitlab.rb

Pastedimage20240801201808.png

เมื่อแก้ไข configure จำเป็นต้องทำการ reconfigure ใหม่ทุกครั้ง

sudo gitlab-ctl reconfigure

Pastedimage20240801201912.png

เมื่อมีการติดตั้ง gitlab server ใหม่ ระบบจะมีการสร้าง root password ให้โดยจะอยู่ในไฟล์ /etc/gitlab/initial_root_password

sudo cat /etc/gitlab/initial_root_password

Password: xxxxx

# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.

เข้าสู่หน้า Gitlab ด้วย http://server-ip โดย username ใช้เป็น root ส่วน password ใช้เป็น initial root password จากไฟล์

Pastedimage20240801202510.png

ปิดการใช้งานเมนู Sign-up ซึ่งจะเป็นการทำให้ ไม่สามารถสร้าง User ด้วยตัวเองได้ โดยจำเป็นต้องให้ Admin สร้างให้เท่านั้น (เพื่อป้องกันผู้อื่นเข้ามาใช้งาน) โดยเมนูนี้จะสามารถแก้ไขด้วย User Root เท่านั้น

Admin Area -> Settings -> General -> Sign-up restrictions -> Sign-up enabled (ติ๊กอันนี้ออก)

Pastedimage20240801202725.png

หากถูกต้องปุ่ม # ในหน้าหลักจะหายไป

Pastedimage20240801202954.png

จากนั้นทำการเปลี่ยนแปลงรหัสผ่านของ Admin โดยรหัสผ่านควรมีความยาว 12 ตัวอักษรขึ้นไปและคาดเดาได้ยาก

Pastedimage20240801203130.png

การตั้งค่า Firewall: ปกติแล้ว gitlab server จะใช้งานเพียง 2 Port คือ 22 (ssh) และ 80 (http)

sudo apt install ufw

sudo ufw allow openssh
sudo ufw allow http

# หรือ
sudo ufw allow from 192.168.88.0/24 to any port 22
sudo ufw allow from 192.168.88.0/24 to any port 80

sudo ufw enable
# answer: y

sudo ufw status
# Status: active
#
# To                         Action      From
# --                         ------      ----
# OpenSSH                    ALLOW       Anywhere
# 80/tcp                     ALLOW       Anywhere
# OpenSSH (v6)               ALLOW       Anywhere (v6)
# 80/tcp (v6)                ALLOW       Anywhere (v6)

# Command อื่น ๆ
sudo ufw status numbered
Status: active

     To                         Action      From
     --                         ------      ----
[ 1] OpenSSH                    ALLOW IN    Anywhere
[ 2] 80/tcp                     ALLOW IN    Anywhere
[ 3] 23                         ALLOW IN    192.168.88.0/24
[ 4] OpenSSH (v6)               ALLOW IN    Anywhere (v6)
[ 5] 80/tcp (v6)                ALLOW IN    Anywhere (v6)

sudo ufw delete 3

ทดสอบด้วย nmap

nmap -p- 192.22.3.150

# Nmap scan report for 192.22.3.150
# Host is up (0.018s latency).
# Not shown: 998 filtered tcp ports (no-response)
# PORT   STATE SERVICE
# 22/tcp open  ssh
# 80/tcp open  http

ผู้ที่เป็น Admin สามารถสร้าง User ให้ได้

Admin Area -> Overview -> Users -> New User

  • Name, Username, Email: ตั้งอะไรก็ได้
  • Access level: ถ้าเป็น ผนง. ทั่วไปตั้งเป็น Regular, ถ้าต้องการให้เป็น Admin เลือกเป็น Administrator Pasted image 20240801114504.png

SSH keypair authentication

ไปยัง Drive C -> Users -> เลือก Users ที่มีการใช้งานอยู่ จากนั้นทำการแก้ไขการตั้งค่า View -> Show -> ติ๊ก Hidden Items และ File name extensions

Pastedimage20240801131422.png

สร้าง Folder .ssh และเข้าไปยัง Folder ดังกล่าว จากนั้นสร้างไฟล์ชื่อ config (แบบไม่มีนามสกุล)

Pastedimage20240801131509.png

เปิด cmd ssh-keygen -t rsa จากนั้นสร้างไฟล์ให้เรียบร้อย

Pastedimage20240801131647.png

เพิ่ม ภายในไฟล์ ~/.ssh/config โดย Host คือหมายเลข IP ของ Gitlab Server และ IdentityFile คือไฟล์ที่สร้างขึ้นมาจากขั้นตอนก่อนหน้า

Host 192.22.3.150
IdentityFile ~/.ssh/id_rsa

จากนั้นเปิดไฟล์ id_rsa.pub ด้วย notepad และ copy content ข้างในไว้

กลับไปที่ Gitlab, กดปุ่ม Profile -> Edit Profile -> SSH Keys และเพิ่ม SSH Key นำ content ในไฟล์ id_rsa.pub ไปไว้ใน SSH KEYS

ปล. เอา expired date ออกด้วย Pasted image 20240801131946.png

ทดสอบ connect ssh -T git@gitlab-ip Pasted image 20240801132357.png