<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: majun</title>
    <description>The latest articles on Forem by majun (@junoma).</description>
    <link>https://forem.com/junoma</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F885070%2F832bb79f-c306-45cf-88f8-76797c35cab1.jpeg</url>
      <title>Forem: majun</title>
      <link>https://forem.com/junoma</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/junoma"/>
    <language>en</language>
    <item>
      <title>Play with CVM: Gitlab installation and construction</title>
      <dc:creator>majun</dc:creator>
      <pubDate>Tue, 05 Jul 2022 03:30:12 +0000</pubDate>
      <link>https://forem.com/junoma/gitlab-installation-and-construction-3po5</link>
      <guid>https://forem.com/junoma/gitlab-installation-and-construction-3po5</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This tutorial will explain how to build Gitlab service in Docker mode relying on Tencent Cloud Host (CVM).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  0. Introduction to Gitlab
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://gitlab.com/"&gt;Gitlab (https://gitlab.com)&lt;/a&gt; is a complete set of DevOps tools, through which developers can easily manage projects, source code management, continuous integration/deployment, development document maintenance and even security monitoring, and these important tasks Covers the entire development cycle of the software.&lt;/p&gt;

&lt;p&gt;Gitlab's code submission mode is fully compatible with Git, and the cooperation mode is similar to Github. Merge Request in Gitlab can be roughly analogous to Github's Pull Request. This makes it easy for developers to get started with almost no concept learning cost.&lt;/p&gt;

&lt;p&gt;When do we need Gitlab (or a similar tool)? The answer is that the earlier the project, the better. The core functions of Gitlab are source code submission records and continuous integration, which are like "ledgers" and "rulers" for software projects, and their importance is self-evident. For developers, it is convenient to carry out distributed collaboration, such as branch feature development, etc., thereby improving efficiency, confidence, and sense of achievement; for project managers, it is easy to analyze and track problems, measure progress, and plan target features.&lt;/p&gt;

&lt;p&gt;Git provides a complete set of software, which is essentially a Ruby on Rails WebApp (some background components are now implemented in Go). In the early days, its installation was relatively cumbersome, because it had many components, such as servers, databases, message queues, log management, etc. Although it was easy to use, it had a slight threshold. With the popularization of Docker technology, now we can easily install, configure and deploy through its official image. Next, we will build Gitlab service from scratch on Tencent Cloud Server &lt;a href="https://www.tencentcloud.com/products/cvm?from_social=dev_4"&gt;CVM&lt;/a&gt; , let's get started~&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Preparations
&lt;/h2&gt;

&lt;p&gt;Before starting to install Gitlab, we need to prepare some initial environments, mainly including: cloud server + domain name + certificate + Nginx server installation.&lt;/p&gt;

&lt;p&gt;Cloud server: Gitlab's official recommendation is not less than 4GB of memory, here we choose S4.MEDIUM4 of &lt;a href="https://www.tencentcloud.com/products/cvm?from_social=dev_4"&gt;Tencent cloud server (standard S4, 2 cores 4GB).&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Operating system: CentOS-7.5 is selected here, other systems such as Ubuntu are also no problem at all, and the operation is similar.&lt;/p&gt;

&lt;p&gt;Domain name: It can be purchased from any domain name provider (such as &lt;a href="https://dnspod.cloud.tencent.com/"&gt;Tencent Cloud Domain Name&lt;/a&gt; ). The following is an example of master-cvm.yangyang.cloud.&lt;/p&gt;

&lt;p&gt;Then we have the web server and SSL certificate installed, which can be easily verified through the Nginx test page similar to the following.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GRsI0E1b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.computeinit.com/wp-content/uploads/2021/04/d2b5ca33bd970f64a6301fa75ae2eb22-1024x665.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GRsI0E1b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.computeinit.com/wp-content/uploads/2021/04/d2b5ca33bd970f64a6301fa75ae2eb22-1024x665.png" alt="2-1" width="880" height="571"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For SSL certificate application and advanced Nginx installation, please refer to the previous article: Play with &lt;a href="https://www.tencentcloud.com/products/cvm?from_social=dev_4"&gt;CVM: Web Service Construction&lt;/a&gt; .&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Docker installation
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.docker.com/"&gt;As a platform for container management, Docker&lt;/a&gt; has been widely used in service deployment and other fields. Container is a lightweight virtualization solution, relying on OS-level virtualization technologies such as overlayfs, namespace under Linux, and cgroups, and its performance is more prominent than VM-based virtualization. But more importantly, it is more convenient to install and configure software through Docker, so we need to simply install Docker first.&lt;/p&gt;

&lt;p&gt;Here we take the example of installing the latest docker-ce version. If the ee version is installed, it is similar. Refer to the official documentation here: &lt;a href="https://docs.docker.com/install/linux/docker-ce/centos/"&gt;https://docs.docker.com/install/linux/docker-ce/centos/&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Install dependencies and set up repository sources
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Install docker-ce
&lt;/h3&gt;

&lt;p&gt;In our environment, it takes about 1 minute, and Tencent Cloud's network generally feels pretty good.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# The latest stable version
yum install docker-ce docker-ce-cli containerd.io
# Or the specified version, such as:
# yum install docker-ce-18.09.6 docker-ce-cli-18.09.6 containerd.io
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The version installed in this article is: docker-ce-18.09.6 (the latest).&lt;/p&gt;

&lt;h3&gt;
  
  
  start the docker service
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;systemctl start docker&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Docker service verification
&lt;/h3&gt;

&lt;p&gt;Start the hello-world container for simple verification.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker run hello-world docker run hello-world docker run hello-world&lt;/code&gt; &lt;code&gt;docker run hello-world&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Indeed, the installation of Docker is becoming more and more convenient.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Loo_rlMB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.computeinit.com/wp-content/uploads/2021/04/d2b5ca33bd970f64a6301fa75ae2eb22-1024x512.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Loo_rlMB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.computeinit.com/wp-content/uploads/2021/04/d2b5ca33bd970f64a6301fa75ae2eb22-1024x512.png" alt="2-2" width="880" height="440"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Install Gitlab
&lt;/h2&gt;

&lt;p&gt;Official documentation: &lt;a href="https://docs.gitlab.com/omnibus/docker/"&gt;https://docs.gitlab.com/omnibus/docker/&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Download the docker image of gitlab to the local
&lt;/h3&gt;

&lt;p&gt;It takes about 2.5 minutes on Tencent Cloud.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# The latest stable version
docker pull gitlab/gitlab-ce
# or the specified version, such as:
docker pull gitlab/gitlab-ce:11.11.2-ce.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The version installed in this article is: gitlab-ce:11.11.2-ce.0 (the latest).&lt;/p&gt;

&lt;h3&gt;
  
  
  Start the gitlab container
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run --detach \
  --hostname master-cvm.yangyang.cloud \
  --env GITLAB_OMNIBUS_CONFIG="external_url 'https://master-cvm.yangyang.cloud/gitlab'; gitlab_rails['gitlab_shell_ssh_port'] = 55522;" \
  --publish 127.0.0.1:55523:443 --publish 55522:22 \
  --name gitlab    \
  --restart always \
  --volume /data/gitlab/config:/etc/gitlab   \
  --volume /data/gitlab/logs:/var/log/gitlab \
  --volume /data/gitlab/data:/var/opt/gitlab \
  gitlab/gitlab-ce:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The meaning of each parameter:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;detach: let the container run in the background;&lt;/li&gt;
&lt;li&gt;always: always restart after failure;&lt;/li&gt;
&lt;li&gt;env: pass environment variables, pay special attention here, the external_url value passed should be consistent with the domain name and routing under Nginx;&lt;/li&gt;
&lt;li&gt;publish: port forwarding –pubish 55522:22 will forward port 22 of the container to port 55522 of the cloud server;&lt;/li&gt;
&lt;li&gt;volume: The volume mount directory of the custom container, Gitlab needs three: configuration config, log logs and data data;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After the container is started, we can &lt;code&gt;docker ps&lt;/code&gt; view the container status through the command, as shown in the figure:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hIM_mxcj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.computeinit.com/wp-content/uploads/2021/04/d2b5ca33bd970f64a6301fa75ae2eb22-1024x40.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hIM_mxcj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.computeinit.com/wp-content/uploads/2021/04/d2b5ca33bd970f64a6301fa75ae2eb22-1024x40.png" alt="2-3" width="880" height="34"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It can be seen that our gitlab container is running normally.&lt;/p&gt;

&lt;p&gt;In addition, you can also use docker logs to view the startup log of the container to troubleshoot potential errors.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker logs -f --tail 50 gitlab&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Nginx settings
&lt;/h3&gt;

&lt;p&gt;Note that the configuration of the path (location) and port number (proxy_pass) should match the docker run command above.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server {
    listen 80;
    server_name master-cvm.yangyang.cloud;

    return 301 https://$host$request_uri;
}

server {
    listen 443 http2 ssl;
    listen [::]:443 http2 ssl;

    server_name master-cvm.yangyang.cloud;

    ssl on;
    ssl_certificate /etc/letsencrypt/live/master-cvm.yangyang.cloud/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/master-cvm.yangyang.cloud/privkey.pem;
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
    ssl_prefer_server_ciphers on;

    location /gitlab/ {
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_http_version 1.1;
        proxy_pass https://127.0.0.1:55523;
    }

    location / {
        root    /usr/share/nginx/html;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;reboot&lt;/p&gt;

&lt;p&gt;&lt;code&gt;systemctl restart nginx.service&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;Try accessing it from a browser~ For example: &lt;a href="https://master-cvm.yangyang.cloud/gitlab/"&gt;https://master-cvm.yangyang.cloud/gitlab/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At this time, the interface to reset the root password will appear, and the installation is successful.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0S8d9N6v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.computeinit.com/wp-content/uploads/2021/04/d2b5ca33bd970f64a6301fa75ae2eb22-1024x656.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0S8d9N6v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.computeinit.com/wp-content/uploads/2021/04/d2b5ca33bd970f64a6301fa75ae2eb22-1024x656.png" alt="2-4" width="880" height="564"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Initialization and installation verification
&lt;/h2&gt;

&lt;p&gt;After Gitlab is installed, we can use it on the web side. The first is to set the root password. Note that only the root user can access the administrator panel and view many global configurations such as users and projects.&lt;/p&gt;

&lt;h3&gt;
  
  
  create user
&lt;/h3&gt;

&lt;p&gt;After setting the root password, you will be redirected to the login page. Although you can use root + the password you just set to log in directly, it is more recommended to register the first user and use this user for daily operations.&lt;/p&gt;

&lt;p&gt;Upload the key of the user's local development machine&lt;/p&gt;

&lt;h3&gt;
  
  
  set sshkey
&lt;/h3&gt;

&lt;p&gt;Consistent with Github, users need to upload the user's ssh key to push code through the ssh protocol. Execute the following command on development and copy it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh-keygen
cat ~/.ssh/id_rsa.pub
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;User avatar in the upper right corner -&amp;gt; "Settings" -&amp;gt; "SSH Keys" in the left column to manage and add keys.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BAr03sNV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.computeinit.com/wp-content/uploads/2021/04/d2b5ca33bd970f64a6301fa75ae2eb22-1024x601.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BAr03sNV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.computeinit.com/wp-content/uploads/2021/04/d2b5ca33bd970f64a6301fa75ae2eb22-1024x601.png" alt="2-5" width="880" height="516"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Common operations
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Create projects, create users and group management
&lt;/h3&gt;

&lt;p&gt;Create a project group (optional)&lt;/p&gt;

&lt;p&gt;In Gitlab, the namespace that manages each project (Project) is a group (Group) and its nested subgroup (Subgroup), which can be simply understood as different "directories" where the project is located.&lt;/p&gt;

&lt;p&gt;Gitlab creates a default project group with the same name for each user, so projects can be created directly.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create project
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--N0jWWTfT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.computeinit.com/wp-content/uploads/2021/04/d2b5ca33bd970f64a6301fa75ae2eb22-1024x587.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--N0jWWTfT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.computeinit.com/wp-content/uploads/2021/04/d2b5ca33bd970f64a6301fa75ae2eb22-1024x587.png" alt="2-6" width="880" height="504"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the familiar Github-like interface:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eblQgbKJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.computeinit.com/wp-content/uploads/2021/04/d2b5ca33bd970f64a6301fa75ae2eb22-1024x637.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eblQgbKJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.computeinit.com/wp-content/uploads/2021/04/d2b5ca33bd970f64a6301fa75ae2eb22-1024x637.png" alt="2-7" width="880" height="547"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Because the key has been uploaded before, we can clone the project locally through SSH&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git clone ssh://git@master-cvm.yangyang.cloud:55522/example-group/my-webapp.git&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;Note that the url here will contain the ssh port set by my door&lt;/p&gt;

&lt;p&gt;It is also supported to select the https protocol when cloning the code, but it is not as convenient to use ssh to enter the user name and password.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. CI and CI-Runner installation
&lt;/h2&gt;

&lt;p&gt;Gitlab's support for CI (Continuous Integration/Deployment) is very mature. Personally think it is easier to understand and use than jenkins. The so-called continuous integration is to do pre-set tasks (such as code compilation and packaging, automated testing, release, etc.) on a specific machine at a specific point in time (such as code Merge). The program that executes the task is called Gitlab Runner, which executes the component of the task, and it does not necessarily run on the host where gitlab is located, as long as it can communicate with the network.&lt;/p&gt;

&lt;p&gt;For the installation process, refer to the official documentation here: &lt;a href="https://docs.gitlab.com/runner/install/linux-repository.html"&gt;https://docs.gitlab.com/runner/install/linux-repository.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The installation of Gitlab's CI-Runner is very simple and straightforward, and subsequent use (such as configuration tasks) can be started in just three steps.&lt;/p&gt;

&lt;h3&gt;
  
  
  Update repository source
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | bash&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Install
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;yum install gitlab-runner&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  register
&lt;/h3&gt;

&lt;p&gt;Why register? In fact, it is to let gitlab know which machines are running runner. The url and token of gitlab are required.&lt;/p&gt;

&lt;p&gt;You can find it in the project's "Settings" -&amp;gt; "CI/CD" -&amp;gt; "Runners" and copy it, as shown in the figure&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ORcXmIoP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.computeinit.com/wp-content/uploads/2021/04/d2b5ca33bd970f64a6301fa75ae2eb22-1024x608.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ORcXmIoP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.computeinit.com/wp-content/uploads/2021/04/d2b5ca33bd970f64a6301fa75ae2eb22-1024x608.png" alt="2-8" width="880" height="523"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can register directly with the gitlab-runner register command.&lt;/p&gt;

&lt;p&gt;The type of executor is selected according to the needs, and the shell is more commonly used.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--imFt96r0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.computeinit.com/wp-content/uploads/2021/04/d2b5ca33bd970f64a6301fa75ae2eb22-1024x304.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--imFt96r0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.computeinit.com/wp-content/uploads/2021/04/d2b5ca33bd970f64a6301fa75ae2eb22-1024x304.png" alt="2-9" width="880" height="261"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Later, you can set specific CI tasks in .gitlab-ci.yml under the project, and view the execution results of the tasks on the Pipeline page of Gitlab-CI.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. bonus: git/gitlab based development process
&lt;/h2&gt;

&lt;p&gt;The pictures on Gitlab's official website are quoted here to illustrate the development workflow.&lt;/p&gt;

&lt;p&gt;It can be seen that Gitlab classifies a series of work on the branch code before merging into the release trunk as a CI process, including automatic build testing, etc.; and the automated work after merging into the trunk is called a CD process, including deployment to the production environment, etc. .&lt;/p&gt;

&lt;p&gt;The problems to be dealt with in actual automated deployment are usually much more complicated than this picture, and we can further experience this evolving process in the process of project development.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--URICceHu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.computeinit.com/wp-content/uploads/2021/04/d2b5ca33bd970f64a6301fa75ae2eb22-1024x576.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--URICceHu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.computeinit.com/wp-content/uploads/2021/04/d2b5ca33bd970f64a6301fa75ae2eb22-1024x576.png" alt="2-10" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At this point, this tutorial has come to an end. I believe that following here, you can already build your own Gitlab service on CVM by yourself, and you are well prepared for the next journey.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let's enjoy the fun of playing &lt;a href="https://www.tencentcloud.com/products/cvm?from_social=dev_4"&gt;CVM&lt;/a&gt; together~&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Enjoy Yourself~&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This article is from Tencent Cloud Computing Community, please indicate the source for reprinting: &lt;a href="https://computeinit.com/archives/2415"&gt;https://computeinit.com/archives/2415&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>gitlab</category>
      <category>cvm</category>
      <category>tencent</category>
      <category>ci</category>
    </item>
    <item>
      <title>How to Build Web Services Relying on Tencent Cloud CVM</title>
      <dc:creator>majun</dc:creator>
      <pubDate>Tue, 05 Jul 2022 03:16:46 +0000</pubDate>
      <link>https://forem.com/junoma/how-to-build-web-services-relying-on-cvm-1pn</link>
      <guid>https://forem.com/junoma/how-to-build-web-services-relying-on-cvm-1pn</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This tutorial will explain how to build cutting-edge secure and high-performance web services relying on Tencent Cloud Hosting.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  0. Environment preparation
&lt;/h2&gt;

&lt;p&gt;Before we start, we have prepared the following two types of resources.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;One Tencent Cloud instance:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://www.tencentcloud.com/products/cvm?from_social=dev_3"&gt;Created on demand in the Tencent Cloud CVM product homepage&lt;/a&gt; . This article uses a cloud server with the model S4.SMALL2. Note that you need to check the "free allocation of public network IP" when purchasing. The operating system we choose is CentOS 7. Of course, for other systems such as Fedora/Ubuntu, most of the steps in this article are common. All commands below are executed inside this instance.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;One Tencent Cloud domain name:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://dnspod.cloud.tencent.com/"&gt;On the Tencent Cloud domain name registration page&lt;/a&gt; , select Register. Pick a domain name you like ~ &lt;a href="http://my-awesome-domain.com/"&gt;http://my-awesome-domain.com&lt;/a&gt; is used below .&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Set domain name resolution
&lt;/h2&gt;

&lt;p&gt;Adding a domain name resolution record means associating a domain name record with a cloud server on a public cloud.&lt;/p&gt;

&lt;p&gt;Tencent Cloud's &lt;a href="https://www.tencentcloud.com/products/cvm?from_social=dev_3"&gt;cloud resolution&lt;/a&gt; products can easily manage our domain name resolution work.&lt;br&gt;
The addition of all parsing records can be set in the &lt;a href="https://console.cloud.tencent.com/cns"&gt;cloud parsing console&lt;/a&gt; .&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PbVNZHWV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.computeinit.com/wp-content/uploads/2021/03/c27cbe9537c9f651954815d76896b68d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PbVNZHWV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.computeinit.com/wp-content/uploads/2021/03/c27cbe9537c9f651954815d76896b68d.png" alt="1" width="880" height="140"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Record type: select "A", this type of resolution record can be associated with IP and domain name;&lt;/li&gt;
&lt;li&gt;Record value: the public network IP of the &lt;a href="https://www.tencentcloud.com/products/cvm?from_social=dev_3"&gt;CVM&lt;/a&gt; cloud host;&lt;/li&gt;
&lt;li&gt;Host record: the domain name above the third level we need, such as filling in web, that is, the domain name "web" .my-awesome-domain.com" to the specified IP.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Tencent Cloud's resolution takes effect very quickly, so we can log in to CVM through domain name records, such as:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ssh root@web.my-awesome-domain.com&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  2 Apply for SSL certificate
&lt;/h2&gt;

&lt;p&gt;Let's apply for a Let's Encrypt certificate. It can be easily done through the official &lt;a href="https://certbot.eff.org/"&gt;Certbot tool.&lt;/a&gt;Certbot is essentially a client of the &lt;a href="http://https://tools.ietf.org/html/rfc8555"&gt;ACME protocol , which is specially used for developers to automatically manage the certificate application process.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Install Certbot&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yum install certbot
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At the same time, relevant dependent libraries, such as openssl, will be installed. Just use apt install under Debian/Ubuntu.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Certificate Application&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;certbot certonly --standalone -n -m my-email-address@example.com --agree-tos -d web.my-awesome-domain.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The application execution process takes about ten seconds, as shown below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Rf2b1Ugs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.computeinit.com/wp-content/uploads/2021/03/a40e2bd88cfc87bc978bf903cac9480e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Rf2b1Ugs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.computeinit.com/wp-content/uploads/2021/03/a40e2bd88cfc87bc978bf903cac9480e.png" alt="1-1" width="726" height="362"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Certificate Application Result&lt;/p&gt;

&lt;p&gt;After success, certificate-related files will be generated in the /etc/letsencrypt/live/ &lt;a href="http://web.my-awesome-domain.com/"&gt;http://web.my-awesome-domain.com/&lt;/a&gt; directory: certificate file &lt;strong&gt;fullchain.pem&lt;/strong&gt; and certificate private key file &lt;strong&gt;privkey.pem&lt;/strong&gt; , later in Nginx They will be used in the configuration.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The certificate that is set to automatically renew&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The certificate application will expire after 90 days, but Certbot comes with a tool for re-applying (renew) certificate regularly: certbot-renew. We don't have to worry about certificate expiration by starting this scheduled task through the systemctl command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;systemctl start certbot-renew.timer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3 Install Nginx
&lt;/h2&gt;

&lt;p&gt;There are two common ways to install Nginx: through distribution package management tools, or through source code compilation and installation. If the former is used, only:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yum install nginx # Debian/Ubuntu下：apt install nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then skip this section and start the configuration process in the next section.&lt;/p&gt;

&lt;p&gt;However, in the current mainstream distributions (such as Centos7/Ubuntu18, etc.), due to the relatively low version of nginx/openssl and other software packages, they will not be able to support features such as TLSv1.3, so please choose between features according to your needs.&lt;/p&gt;

&lt;p&gt;Then, let's explain in detail how to &lt;strong&gt;install the latest version of Nginx through source code&lt;/strong&gt; . The latest stable version is 1.16.0. Be careful to install the latest stable version as much as possible, too old versions do not support many features, such as HTTP/2 (supported after 1.10) and TLSv1.3 (supported after 1.15).&lt;/p&gt;

&lt;p&gt;The latest version of the software is usually not in the software repository of the distribution's package management tools (such as Yum, APT), but requires us to compile and install the source code. But for us CVM players, this is not a problem at all. Let's experience greater freedom and flexibility with me.&lt;/p&gt;

&lt;p&gt;We choose to complete the Nginx installation in the /opt directory, which is usually a suitable choice. Of course, whatever you are used to working with directory is fine.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd /opt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Installation related dependencies&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here are mainly compilers, PCRE packages and zlib packages&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yum install gcc pcre-devel zlib-devel
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(It needs to be done with apt install under Debian/Ubuntu system, and the corresponding package names are libpcre3-dev and zlib1g-dev)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Download the openssl source code&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To download the latest version of the openssl library, version 1.1.1b. This is because the TLS protocol and encryption and decryption in Nginx are done by external libraries (such as libssl/libcrypto, etc.), and they are all implemented in the openssl project. The default openssl of the system is relatively old and cannot support the latest HTTP/2 and TLS features.&lt;/p&gt;

&lt;p&gt;It only takes two steps: download and unzip. No need to compile and install.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wget https://www.openssl.org/source/openssl-1.1.1b.tar.gz
tar -zxvf openssl-1.1.1b.tar.gz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Source code to compile Nginx&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Download, compile and install Nginx, version 1.16.0.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wget http://nginx.org/download/nginx-1.16.0.tar.gz
tar -zxvf nginx-1.16.0.tar.gz
cd nginx-1.16.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Configure the compilation options, note that here we need to specify the code directory of openssl, and Nginx will compile the parts required for compiling openssl by the way. Its options here focus on enabling the http/2 and ssl modules. For other options, if you want to make changes later, you only need to reconfigure and compile. The source installation is so convenient and willful.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./configure \
  --pid-path=/run/nginx.pid   \
  --with-http_v2_module      \
  --with-http_ssl_module     \
  --with-openssl=/opt/openssl-1.1.1b
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Compile and install&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;make &amp;amp;amp;&amp;amp;amp; make install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nginx will be installed by default in the /usr/local/nginx directory (also specified by the prefix compile option).&lt;/p&gt;

&lt;p&gt;At this point, we have completed the installation of Nginx. actually implement&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/usr/local/nginx/sbin/nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Nginx service can be started. But wait, let's get the job done a little more gracefully.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Configure the Nginx service as a systemd system service&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Edit the file: /lib/systemd/system/nginx.service , add the following content&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/bin/rm -f /run/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true

[Install]
WantedBy=multi-user.target
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;then execute&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;systemctl daemon-reload
systemctl enable nginx.service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can then manage Nginx services through systemctl commands, such as restart, reload, etc.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;systemctl restart nginx.service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Configure Nginx
&lt;/h2&gt;

&lt;p&gt;Edit the server section in nginx.conf (or similar configuration file), set ssl-related parameters such as certificate/key, and redirect the HTTP service of port 80 to port 443 of HTTPS. details as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server {
    listen       443 ssl http2;
    server_name  web.my-awesome-domain.com;

    ssl_certificate "/etc/letsencrypt/live/web.my-awesome-domain.com/fullchain.pem";
    ssl_certificate_key "/etc/letsencrypt/live/web.my-awesome-domain.com/privkey.pem";
    ssl_session_cache shared:SSL:1m;
    ssl_session_timeout  10m;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers ECDHE-RSA-AES256-GCM-SHA384:!aNULL:!MD5:!RC4:!DHE;
    ssl_prefer_server_ciphers on;

    add_header Strict-Transport-Security "max-age=31536000";

    location / {
        root   html;
        index  index.html;
    }
}

server {
    listen       80;
    server_name  web.my-awesome-domain.com;
    if ($host = web.my-awesome-domain.com) {
        return 301 https://$host$request_uri;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: We support http2, and for the SSL protocol, we support both the current stable TLSv1.2 and the latest TLSv1.3.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;systemctl restart nginx.service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then restart the service and you're done!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This article is from Tencent Cloud Computing Community, please indicate the source for reprinting: &lt;a href="https://computeinit.com/archives/2405"&gt;https://computeinit.com/archives/2405&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>javascript</category>
      <category>nginx</category>
      <category>tencent</category>
      <category>web</category>
    </item>
  </channel>
</rss>
