{"id":18826,"date":"2024-11-19T12:51:16","date_gmt":"2024-11-19T04:51:16","guid":{"rendered":"https:\/\/fwq.ai\/blog\/18826\/"},"modified":"2024-11-19T12:51:16","modified_gmt":"2024-11-19T04:51:16","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8ubuntu%e7%b3%bb%e7%bb%9f%e4%b8%8a%e5%ae%89%e8%a3%85%e5%92%8c%e4%bd%bf%e7%94%a8gitlab","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/18826\/","title":{"rendered":"\u5982\u4f55\u5728Ubuntu\u7cfb\u7edf\u4e0a\u5b89\u88c5\u548c\u4f7f\u7528GitLab"},"content":{"rendered":"<p>gitlab\u662f\u4e00\u6b3e\u5f00\u6e90\u4ee3\u7801\u6258\u7ba1\u5e73\u53f0\uff0c\u5b83\u9664\u4e86\u53ef\u4ee5\u7528\u4f5cgit\u4ed3\u5e93\u7ba1\u7406\u4e4b\u5916\uff0c\u8fd8\u63d0\u4f9b\u4e86\u5f88\u591a\u5176\u4ed6\u7684\u529f\u80fd\uff0c\u6bd4\u5982\u6301\u7eed\u96c6\u6210\u3001\u6784\u5efa\u3001ci\/cd\u7b49\u7b49\u3002\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4f1a\u6559\u4f60\u5982\u4f55\u5728ubuntu\u7cfb\u7edf\u4e0a\u5b89\u88c5\u548c\u4f7f\u7528gitlab\u3002<\/p>\n<p>\u4e00\u3001\u5b89\u88c5<\/p>\n<ol>\n<li>\u66f4\u65b0\u7cfb\u7edf\u548c\u5b89\u88c5\u5fc5\u8981\u7684\u8f6f\u4ef6\u5305<\/li>\n<\/ol>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u66f4\u65b0\u7cfb\u7edf\uff0c\u5e76\u5b89\u88c5\u4e00\u4e9b\u5fc5\u8981\u7684\u8f6f\u4ef6\u5305\uff1a<\/p>\n<pre>sudo apt update\nsudo apt install -y curl openssh-server ca-certificates<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ol>\n<li>\u5b89\u88c5Git<\/li>\n<\/ol>\n<p>GitLab\u662f\u4f7f\u7528Git\u8fdb\u884c\u7248\u672c\u63a7\u5236\u7684\uff0c\u6240\u4ee5\u6211\u4eec\u9700\u8981\u5728\u7cfb\u7edf\u4e0a\u5b89\u88c5Git\uff1a<\/p>\n<pre>sudo apt install -y git<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ol>\n<li>\u5b89\u88c5PostgreSQL<\/li>\n<\/ol>\n<p>GitLab\u4f7f\u7528PostgreSQL\u4f5c\u4e3a\u6570\u636e\u5e93\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1a<\/p>\n<pre>sudo apt install -y postgresql postgresql-client<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ol>\n<li>\u914d\u7f6ePostgreSQL<\/li>\n<\/ol>\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u767b\u5f55\u5230PostgreSQL\u5e76\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6570\u636e\u5e93\u7528\u6237\u548c\u6570\u636e\u5e93\uff1a<\/p>\n<pre>sudo su - postgres\npsql\nCREATE USER git CREATEDB;\nCREATE DATABASE gitlabhq_production OWNER git;\nq\nexit<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ol>\n<li>\u5b89\u88c5Redis<\/li>\n<\/ol>\n<p>GitLab\u4f7f\u7528Redis\u4f5c\u4e3a\u7f13\u5b58\u670d\u52a1\u5668\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1a<\/p>\n<pre>sudo apt install -y redis-server<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ol>\n<li>\u5b89\u88c5GitLab<\/li>\n<\/ol>\n<p>\u73b0\u5728\uff0c\u6211\u4eec\u53ef\u4ee5\u5f00\u59cb\u5b89\u88c5GitLab\u4e86\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6dfb\u52a0GitLab\u8f6f\u4ef6\u4ed3\u5e93\uff1a<\/p>\n<pre>curl https:\/\/packages.gitlab.com\/install\/repositories\/gitlab\/gitlab-ce\/script.deb.sh | sudo bash<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ol>\n<li>\u5b89\u88c5GitLab CE<\/li>\n<\/ol>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff0c\u5b89\u88c5GitLab CE\uff1a<\/p>\n<pre>sudo apt install -y gitlab-ce<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4e8c\u3001\u914d\u7f6eGitLab<\/p>\n<ol>\n<li>\u914d\u7f6e\u57df\u540d\u548cIP<\/li>\n<\/ol>\n<p>\u5728\u6211\u4eec\u5f00\u59cb\u4f7f\u7528GitLab\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u5c06\u57df\u540d\u548cIP\u5730\u5740\u6dfb\u52a0\u5230GitLab\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u3002\u7f16\u8f91\u4ee5\u4e0b\u6587\u4ef6\uff1a<\/p>\n<pre>sudo nano \/etc\/gitlab\/gitlab.rb<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u627e\u5230\u4ee5\u4e0b\u884c\u5e76\u5c06\u5176\u53d6\u6d88\u6ce8\u91ca\uff1a<\/p>\n<pre>external_url 'http:\/\/example.com'<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5c06&#8221;example.com&#8221;\u66ff\u6362\u4e3a\u4f60\u5b9e\u9645\u7684\u57df\u540d\u6216IP\u5730\u5740\u3002<\/p>\n<ol>\n<li>\u914d\u7f6eSMTP<\/li>\n<\/ol>\n<p>GitLab\u4f7f\u7528SMTP\u670d\u52a1\u5668\u53d1\u9001\u90ae\u4ef6\u901a\u77e5\u3002\u5728GitLab\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u627e\u5230\u4ee5\u4e0b\u884c\u5e76\u8bbe\u7f6e\u6b63\u786e\u7684SMTP\u670d\u52a1\u5668\u5730\u5740\u3001\u7aef\u53e3\u3001\u7528\u6237\u540d\u548c\u5bc6\u7801\uff1a<\/p>\n<pre>gitlab_rails['smtp_enable'] = true\ngitlab_rails['smtp_address'] = \"smtp.example.com\"\ngitlab_rails['smtp_port'] = 465\ngitlab_rails['smtp_user_name'] = \"user@example.com\"\ngitlab_rails['smtp_password'] = \"password\"\ngitlab_rails['smtp_authentication'] = \"login\"\ngitlab_rails['smtp_enable_starttls_auto'] = true\ngitlab_rails['smtp_tls'] = true<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5c06&#8221;smtp.example.com&#8221;\u3001&#8221;user@example.com&#8221;\u548c&#8221;password&#8221;\u66ff\u6362\u4e3a\u4f60\u7684\u5b9e\u9645\u503c\u3002<\/p>\n<ol>\n<li>\u4fdd\u5b58\u5e76\u9000\u51fa<\/li>\n<\/ol>\n<p>\u4fdd\u5b58\u5e76\u9000\u51faGitLab\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<pre>sudo gitlab-ctl reconfigure<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u914d\u7f6e\u6587\u4ef6\u7684\u66f4\u6539\u5c06\u5728\u91cd\u65b0\u914d\u7f6eGitLab\u65f6\u751f\u6548\u3002<\/p>\n<p>\u4e09\u3001\u4f7f\u7528GitLab<\/p>\n<ol>\n<li>\u767b\u5f55<\/li>\n<\/ol>\n<p>\u5728\u6d4f\u89c8\u5668\u4e2d\u8f93\u5165\u4f60\u7684GitLab\u57df\u540d\u6216IP\u5730\u5740\uff0c\u767b\u5f55GitLab\u3002\u9ed8\u8ba4\u7528\u6237\u540d\u4e3a&#8221;root&#8221;\uff0c\u9ed8\u8ba4\u5bc6\u7801\u4e3a&#8221;5iveL!fe&#8221;\u3002<\/p>\n<ol>\n<li>\u521b\u5efa\u9879\u76ee<\/li>\n<\/ol>\n<p>\u5728GitLab\u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u9879\u76ee\u3002\u8f93\u5165\u9879\u76ee\u540d\u79f0\u3001\u63cf\u8ff0\u7b49\u4fe1\u606f\u3002<\/p>\n<ol>\n<li>GitLab CI\/CD<\/li>\n<\/ol>\n<p>GitLab\u6709\u5185\u7f6e\u7684CI\/CD\u529f\u80fd\uff0c\u80fd\u591f\u5728\u4ee3\u7801\u4fee\u6539\u65f6\u8fdb\u884c\u7f16\u8bd1\u3001\u6d4b\u8bd5\u548c\u90e8\u7f72\u3002\u914d\u7f6eCI\/CD\u9700\u8981\u6dfb\u52a0\u4e00\u4e2a.gitlab-ci.yml\u6587\u4ef6\u5230\u9879\u76ee\u6839\u76ee\u5f55\u4e2d\u3002<\/p>\n<p>\u8fd9\u4e2a\u6587\u4ef6\u5b9a\u4e49\u4e86GitLab\u5e94\u8be5\u5728\u6267\u884c\u54ea\u4e9b\u4efb\u52a1\uff0c\u4ee5\u53ca\u5982\u4f55\u6267\u884c\u8fd9\u4e9b\u4efb\u52a1\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>stages:\n  - build\n  - test\n  - deploy\n\nbuild:\n  stage: build\n  script:\n    - make\n\ntest:\n  stage: test\n  script:\n    - make test\n\ndeploy:\n  stage: deploy\n  script:\n    - make deploy<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u8fd9\u4e2a\u6587\u4ef6\u544a\u8bc9GitLab\u5e94\u8be5\u5728&#8221;build&#8221;\u9636\u6bb5\u6267\u884c&#8221;make&#8221;\u547d\u4ee4\uff0c\u5728&#8221;test&#8221;\u9636\u6bb5\u6267\u884c&#8221;make test&#8221;\u547d\u4ee4\uff0c\u5728&#8221;deploy&#8221;\u9636\u6bb5\u6267\u884c&#8221;make deploy&#8221;\u547d\u4ee4\u3002<\/p>\n<ol>\n<li>\u53c2\u4e0e\u5f00\u6e90\u9879\u76ee<\/li>\n<\/ol>\n<p>\u4f60\u4e5f\u53ef\u4ee5\u5728GitLab\u4e0a\u53d1\u73b0\u4e00\u4e9b\u5f00\u6e90\u9879\u76ee\uff0c\u53c2\u4e0e\u5176\u4e2d\u5e76\u8fdb\u884c\u8d21\u732e\u3002\u62c9\u4ee3\u7801\u3001\u63d0\u4ea4\u66f4\u6539\u3001\u63a8\u4ee3\u7801\u3001\u53d1\u8d77\u5408\u5e76\u8bf7\u6c42\u7b49\u7b49\uff0c\u8fd9\u4e9b\u90fd\u53ef\u4ee5\u5728GitLab\u4e2d\u5b8c\u6210\u3002<\/p>\n<p>\u7ed3\u8bba<\/p>\n<p>\u5b89\u88c5\u548c\u4f7f\u7528GitLab\u5e76\u4e0d\u96be\uff0c\u800c\u4e14\u5b83\u7684\u529f\u80fd\u975e\u5e38\u5f3a\u5927\u3002\u901a\u8fc7GitLab\uff0c\u4f60\u53ef\u4ee5\u66f4\u52a0\u65b9\u4fbf\u5730\u7ba1\u7406\u4f60\u7684Git\u4ed3\u5e93\uff0c\u5e76\u5b9e\u73b0CI\/CD\u7b49\u4e00\u7cfb\u5217\u529f\u80fd\u3002\u56e0\u6b64\uff0c\u5982\u679c\u4f60\u5bf9\u4ee3\u7801\u6258\u7ba1\u3001\u81ea\u52a8\u5316\u6784\u5efa\u548c\u6301\u7eed\u96c6\u6210\u9886\u57df\u611f\u5174\u8da3\uff0c\u4e0d\u8981\u72b9\u8c6b\uff0c\u5c1d\u8bd5\u4e00\u4e0bGitLab\u5427\uff01<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5728Ubuntu\u7cfb\u7edf\u4e0a\u5b89\u88c5\u548c\u4f7f\u7528GitLab\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>gitlab\u662f\u4e00\u6b3e\u5f00\u6e90\u4ee3\u7801\u6258\u7ba1\u5e73\u53f0\uff0c\u5b83\u9664\u4e86\u53ef\u4ee5\u7528\u4f5cgit\u4ed3\u5e93\u7ba1\u7406\u4e4b\u5916\uff0c\u8fd8\u63d0\u4f9b\u4e86\u5f88\u591a\u5176\u4ed6\u7684\u529f\u80fd\uff0c\u6bd4\u5982\u6301\u7eed\u96c6\u6210\u3001\u6784\u5efa\u3001ci\/cd\u7b49\u7b49\u3002\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4f1a\u6559\u4f60\u5982\u4f55\u5728ubuntu\u7cfb\u7edf\u4e0a\u5b89\u88c5\u548c\u4f7f\u7528gitlab\u3002 \u4e00\u3001\u5b89\u88c5 \u66f4\u65b0\u7cfb\u7edf\u548c\u5b89\u88c5\u5fc5\u8981\u7684\u8f6f\u4ef6\u5305 \u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u66f4\u65b0\u7cfb\u7edf\uff0c\u5e76\u5b89\u88c5\u4e00\u4e9b\u5fc5\u8981\u7684\u8f6f\u4ef6\u5305\uff1a sudo apt update sudo apt install -y curl openssh-server ca-certificates \u767b\u5f55\u540e\u590d\u5236 \u5b89\u88c5Git GitLab\u662f\u4f7f\u7528Git\u8fdb\u884c\u7248\u672c\u63a7\u5236\u7684\uff0c\u6240\u4ee5\u6211\u4eec\u9700\u8981\u5728\u7cfb\u7edf\u4e0a\u5b89\u88c5Git\uff1a sudo apt install -y git \u767b\u5f55\u540e\u590d\u5236 \u5b89\u88c5PostgreSQL GitLab\u4f7f\u7528PostgreSQL\u4f5c\u4e3a\u6570\u636e\u5e93\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1a sudo apt install -y postgresql postgresql-client \u767b\u5f55\u540e\u590d\u5236 \u914d\u7f6ePostgreSQL \u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u767b\u5f55\u5230PostgreSQL\u5e76\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6570\u636e\u5e93\u7528\u6237\u548c\u6570\u636e\u5e93\uff1a sudo su &#8211; postgres psql CREATE USER git CREATEDB; CREATE DATABASE gitlabhq_production OWNER git; q exit \u767b\u5f55\u540e\u590d\u5236 \u5b89\u88c5Redis GitLab\u4f7f\u7528Redis\u4f5c\u4e3a\u7f13\u5b58\u670d\u52a1\u5668\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1a sudo apt [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-18826","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18826","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=18826"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18826\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=18826"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=18826"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=18826"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}