Triển khai Gitlab trên Centos

Centos Git

Gitlab là gì?

GitLab là một dự án mã nguồn mở với rất nhiều người phát triển trên toàn thế giới. Gitlab cung cấp dịch vụ lưu trữ nền web được dùng cho các mã nguồn lập trình và phát triển những dự án lập trình có sử dụng hệ thống kiểm soát Git revision tương tự như Bitbucket trên trang Gitlab.com Ngoài ra nếu bạn muốn Gitlab cũng cung cấp gói cài đặt để bạn có thể tự tải về và cài đặt lên máy chủ của bạn tại trang Gitlab.org.

Cài đặt và triển khai GitLab

Dưới đây là cách cài đặt và triển khai Gitlab trên Centos. Nếu các bạn muốn tham khảo cách cài đặt trên các nền tảng khác có thể tham khảo tại link sau: https://about.gitlab.com/installation

Các bước triển khai như sau:

Chuẩn bị các công cụ cần thiết

Cập nhật hệ thống:

yum update -y

Cài đặt các công cụ và mở port cần thiết tường lửa:

sudo yum install -y curl policycoreutils-python openssh-server cronie
sudo lokkit -s http -s ssh

Mở port http và mail

iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 25 -j ACCEPT
iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 465 -j ACCEPT
iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport 587 -j ACCEPT
service iptables save
service iptables restart

Cài đặt mail server

sudo yum install postfix
sudo service postfix start
sudo chkconfig postfix on

Cài đặt Gitlab

Thêm repository và cài đặt Gitlab

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

yum -y install gitlab-ce

[quangcao]
Khởi động Gitlab

sudo gitlab-ctl reconfigure

Cấu hình

nano /etc/gitlab/gitlab.rb

Các bạn chỉnh sửa tập tin gitlab.rb phụ hợp với môi trường sử dụng, ví dụ như mình cấu hình như sau:

external_url 'http://192.168.1.169' #IP Gitlab Server
Cấu hình mail
### GitLab email server settings

gitlab_rails['smtp_enable'] = true;
 gitlab_rails['smtp_address'] = 'localhost';
 gitlab_rails['smtp_port'] = 25;
 gitlab_rails['smtp_domain'] = 'localhost';
 gitlab_rails['smtp_tls'] = false;
 gitlab_rails['smtp_openssl_verify_mode'] = 'none'
 gitlab_rails['smtp_enable_starttls_auto'] = false
 gitlab_rails['smtp_ssl'] = false
 gitlab_rails['smtp_force_ssl'] = false
Cấu hình LDAP
### LDAP Settings
 ###! Docs: https://docs.gitlab.com/omnibus/settings/ldap.html
 ###! **Be careful not to break the indentation in the ldap_servers block. It is
 ###! in yaml format and the spaces must be retained. Using tabs will not work.**

gitlab_rails['ldap_enabled'] = true

###! **remember to close this block with 'EOS' below**
 gitlab_rails['ldap_servers'] = YAML.load <<-'EOS'
 main:
 label: 'LDAP'
 host: 'AD IP'
 port: 389
 uid: 'sAMAccountName'
 method: 'plain'
 bind_dn: 'domain LDPA user'
 password: 'password'
 active_directory: true
 allow_username_or_email_login: true
 block_auto_created_users: false
 base: 'OU=,OU=,DC=,DC=com'
 user_filter: ''
 attributes:
 username: ['uid', 'userid', 'sAMAccountName']
 email: ['mail', 'email', 'userPrincipalName']
 name: 'displayName'
 first_name: 'givenName'
 last_name: 'sn'
 EOS
Cấu hình Postfix Mail (relay đến Office 365)
Cấu hình file generic
nano /etc/postfix/generic

Ghi vào cuối file:

/.*/

root@localdomain [email protected]
@localdomain [email protected]

Sau đó thực hiện các lệnh sau:

sudo chown root:root /etc/postfix/generic
sudo chmod 0600 /etc/postfix/generic
sudo postmap /etc/postfix/generic
Cấu hình Postfix
nano /etc/postfix/main.cf
relayhost = [smtp.office365.com]:587
 smtp_use_tls = yes
 smtp_always_send_ehlo = yes
 smtp_sasl_auth_enable = yes
 smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
 smtp_sasl_security_options = noanonymous
 smtp_sasl_tls_security_options = noanonymous
 smtp_tls_security_level = encrypt
 smtp_generic_maps = hash:/etc/postfix/generic
 smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

 

nano /etc/postfix/sasl_passwd

 

Ghi vào cuối file:

[smtp.office365.com]:587 username@yourdomain:office365password

 

Tiếp theo thực hiện các lệnh sau:

sudo chown root:root /etc/postfix/sasl_passwd
sudo chmod 0600 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd

Khởi động lại Postfix

service postfix restart
TSL check
openssl s_client -starttls smtp -connect smtp.office365.com:587
Test mail
echo "This is the test mail" | mail -s "this is the subject line" "[email protected]"

Như vậy việc cài đặt Gitlab và Mail Server đã hoàn tất. Bạn có thể truy cập vào IP của Gitlab để sử dụng. Chúc các bạn thành công.
[quangcao1]

Share: