ÔõÑùÔÚUbuntuϵͳÉÏ×°ÖúÍʹÓÃGitLab
gitlabÊÇÒ»¿î¿ªÔ´´úÂëÍйÜƽ̨£¬Ëü³ýÁË¿ÉÒÔÓÃ×÷git¿ÍÕ»ÖÎÀíÖ®Í⣬»¹ÌṩÁËÐí¶àÆäËûµÄ¹¦Ð§£¬ºÃ±ÈÒ»Á¬¼¯³É¡¢¹¹½¨¡¢ci/cdµÈµÈ¡£ÔÚÕâƪÎÄÕÂÖУ¬ÎÒ»á½ÌÄãÔõÑùÔÚubuntuϵͳÉÏ×°ÖúÍʹÓÃgitlab¡£
Ò»¡¢×°ÖÃ
¸üÐÂϵͳºÍ×°ÖÃÐëÒªµÄÈí¼þ°ü
Ê×ÏÈ£¬ÎÒÃÇÐèÒª¸üÐÂϵͳ£¬²¢×°ÖÃһЩÐëÒªµÄÈí¼þ°ü£º
sudo apt update sudo apt install -y curl openssh-server ca-certificates
µÇ¼ºó¸´ÖÆ
×°ÖÃGit
GitLabÊÇʹÓÃGit¾ÙÐа汾¿ØÖƵģ¬ÒÔÊÇÎÒÃÇÐèÒªÔÚϵͳÉÏ×°ÖÃGit£º
sudo apt install -y git
µÇ¼ºó¸´ÖÆ
×°ÖÃPostgreSQL
GitLabʹÓÃPostgreSQL×÷ΪÊý¾Ý¿â¡£Ê¹ÓÃÒÔÏÂÏÂÁî×°Öãº
sudo apt install -y postgresql postgresql-client
µÇ¼ºó¸´ÖÆ
ÉèÖÃPostgreSQL
½ÓÏÂÀ´£¬ÎÒÃÇÐèÒªµÇ¼µ½PostgreSQL²¢½¨ÉèÒ»¸öеÄÊý¾Ý¿âÓû§ºÍÊý¾Ý¿â£º
sudo su - postgres psql CREATE USER git CREATEDB; CREATE DATABASE gitlabhq_production OWNER git; \q exit
µÇ¼ºó¸´ÖÆ
×°ÖÃRedis
GitLabʹÓÃRedis×÷Ϊ»º´æЧÀÍÆ÷¡£Ê¹ÓÃÒÔÏÂÏÂÁî×°Öãº
sudo apt install -y redis-server
µÇ¼ºó¸´ÖÆ
×°ÖÃGitLab
ÏÖÔÚ£¬ÎÒÃÇ¿ÉÒÔ×îÏÈ×°ÖÃGitLabÁË¡£Ê¹ÓÃÒÔÏÂÏÂÁîÌí¼ÓGitLabÈí¼þ¿ÍÕ»£º
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
µÇ¼ºó¸´ÖÆ
×°ÖÃGitLab CE
ʹÓÃÒÔÏÂÏÂÁװÖÃGitLab CE£º
sudo apt install -y gitlab-ce
µÇ¼ºó¸´ÖÆ
¶þ¡¢ÉèÖÃGitLab
ÉèÖÃÓòÃûºÍIP
ÔÚÎÒÃÇ×îÏÈʹÓÃGitLab֮ǰ£¬ÎÒÃÇÐèÒª½«ÓòÃûºÍIPµØµãÌí¼Óµ½GitLabµÄÉèÖÃÎļþÖС£±à¼ÒÔÏÂÎļþ£º
sudo nano /etc/gitlab/gitlab.rb
µÇ¼ºó¸´ÖÆ
ÕÒµ½ÒÔÏÂÐв¢½«Æä×÷·Ï×¢ÊÍ£º
external_url 'http://example.com'
µÇ¼ºó¸´ÖÆ
½«”example.com”Ì滻ΪÄãÏÖʵµÄÓòÃû»òIPµØµã¡£
ÉèÖÃSMTP
GitLabʹÓÃSMTPЧÀÍÆ÷·¢ËÍÓʼþ֪ͨ¡£ÔÚGitLabÉèÖÃÎļþÖУ¬ÕÒµ½ÒÔÏÂÐв¢ÉèÖÃ׼ȷµÄSMTPЧÀÍÆ÷µØµã¡¢¶Ë¿Ú¡¢Óû§ÃûºÍÃÜÂ룺
gitlab_rails['smtp_enable'] = true gitlab_rails['smtp_address'] = "smtp.example.com" gitlab_rails['smtp_port'] = 465 gitlab_rails['smtp_user_name'] = "user@example.com" gitlab_rails['smtp_password'] = "password" gitlab_rails['smtp_authentication'] = "login" gitlab_rails['smtp_enable_starttls_auto'] = true gitlab_rails['smtp_tls'] = true
µÇ¼ºó¸´ÖÆ
½«”smtp.example.com”¡¢”user@example.com”ºÍ”password”Ì滻ΪÄãµÄÏÖʵֵ¡£
ÉúÑIJ¢Í˳ö
ÉúÑIJ¢Í˳öGitLabÉèÖÃÎļþ£º
sudo gitlab-ctl reconfigure
µÇ¼ºó¸´ÖÆ
ÉèÖÃÎļþµÄ¸ü¸Ä½«ÔÚÖØÐÂÉèÖÃGitLabʱÉúЧ¡£
Èý¡¢Ê¹ÓÃGitLab
怬
ÔÚä¯ÀÀÆ÷ÖÐÊäÈëÄãµÄGitLabÓòÃû»òIPµØµã£¬µÇ¼GitLab¡£Ä¬ÈÏÓû§ÃûΪ”root”£¬Ä¬ÈÏÃÜÂëΪ”5iveL!fe”¡£
½¨ÉèÏîÄ¿
ÔÚGitLabÖн¨ÉèÒ»¸öеÄÏîÄ¿¡£ÊäÈëÏîÄ¿Ãû³Æ¡¢ÐÎòµÈÐÅÏ¢¡£
GitLab CI/CD
GitLabÓÐÄÚÖõÄCI/CD¹¦Ð§£¬Äܹ»ÔÚ´úÂëÐÞ¸Äʱ¾ÙÐбàÒë¡¢²âÊԺͰ²ÅÅ¡£ÉèÖÃCI/CDÐèÒªÌí¼ÓÒ»¸ö.gitlab-ci.ymlÎļþµ½ÏîÄ¿¸ùĿ¼ÖС£
Õâ¸öÎļþ½ç˵ÁËGitLabÓ¦¸ÃÔÚÖ´ÐÐÄÄЩʹÃü£¬ÒÔ¼°ÔõÑùÖ´ÐÐÕâЩʹÃü¡£ÀýÈ磺
stages: - build - test - deploy build: stage: build script: - make test: stage: test script: - make test deploy: stage: deploy script: - make deploy
µÇ¼ºó¸´ÖÆ
Õâ¸öÎļþ¸æËßGitLabÓ¦¸ÃÔÚ”build”½×¶ÎÖ´ÐДmake”ÏÂÁÔÚ”test”½×¶ÎÖ´ÐДmake test”ÏÂÁÔÚ”deploy”½×¶ÎÖ´ÐДmake deploy”ÏÂÁî¡£
¼ÓÈ뿪ԴÏîÄ¿
ÄãÒ²¿ÉÒÔÔÚGitLabÉÏ·¢Ã÷һЩ¿ªÔ´ÏîÄ¿£¬¼ÓÈëÆäÖв¢¾ÙÐÐТ˳¡£À´úÂë¡¢Ìá½»¸ü¸Ä¡¢ÍÆ´úÂë¡¢ÌᳫºÏ²¢ÇëÇóµÈµÈ£¬ÕâЩ¶¼¿ÉÒÔÔÚGitLabÖÐÍê³É¡£
½áÂÛ
×°ÖúÍʹÓÃGitLab²¢²»ÄÑ£¬²¢ÇÒËüµÄ¹¦Ð§ºÜÊÇÇ¿Ê¢¡£Í¨¹ýGitLab£¬Äã¿ÉÒÔÔ½·¢Àû±ãµØÖÎÀíÄãµÄGit¿ÍÕ»£¬²¢ÊµÏÖCI/CDµÈһϵÁй¦Ð§¡£Òò´Ë£¬ÈôÊÇÄã¶Ô´úÂëÍйܡ¢×Ô¶¯»¯¹¹½¨ºÍÒ»Á¬¼¯³ÉÁìÓò¸ÐÐËȤ£¬²»ÒªÓÌÔ¥£¬ÊµÑéÒ»ÏÂGitLab°É£¡
ÒÔÉϾÍÊÇÔõÑùÔÚUbuntuϵͳÉÏ×°ÖúÍʹÓÃGitLabµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡