When deploying GitLab, it is required to display the real IP address of the server

After the GitLab deployed in the teaching environment is successful, copying the address bar of GitLab will hide the real IP of the server, which is inconvenient in practical work. Therefore, I found a method on the Internet that can directly display the real IP:

1, Modify the sshd default port.

Because Git is accessed through SSH protocol, the GitLab container needs to be started later, which needs to occupy port 22, and the sshd service of the computer also needs to occupy port 22 (Port conflict). Therefore, it is necessary to modify the sshd default port in advance and change the port to 2022.

Note: after modification, you need to log in to the virtual machine again (you need to specify the port to log in again).

[root@git ~]# vim /etc/ssh/sshd_config
Port 2022                                               #Line 17
[root@git ~]# systemctl restart sshd
[root@git ~]# exit
 Real machine# ssh -p 2022  192.168.4.20

2, Prepare the container environment.

Tip: gitlab_zh.tar in the second stage material directory, you need to copy the material to the 192.168.4.20 host first. (for example, copy to the / root directory) or download the image of gitlab on the Internet (dock pull gitlab / gitlab EE: 11.11.0-ee.0)

[root@git ~]# dnf  -y   install   podman
[root@git ~]# podman load < ./gitlab_zh.tar
[root@git ~]# podman images
REPOSITORY               TAG      IMAGE ID          CREATED       SIZE
localhost/gitlab_zh   latest   1f71f185271a       2 years ago   1.73 GB

3, Create a data directory.

The container cannot store data permanently. It is necessary to bind the real machine directory and the container directory to realize permanent data storage.

[root@git ~]# mkdir -p /root/gitlab/{config,logs,data}

4, Start gitlab container (gitlab server operation)

1) Start container

[root@git ~]# touch /etc/resolv.conf                       
#If there is no such file, a file is created to prevent the container from being started by podman run
[root@git ~]# docker run -d -h gitlab \
--hostname gitlab.example.com \         # Specify the container domain name and create an image warehouse (it can be used without)
-p 8443:443 \                           # Container 443 port maps to host 8443 port (https)
-p 8080:80 \                            # Container port 80 maps to host port 8080 (http)
-p 22:22 \                              # Container port 22 maps to host port 22 (ssh)
--name gitlab \                         # Container name
--restart always \                      # Automatic restart after container exit
-v /root/gitlab/config:/etc/gitlab \    # Mount the local directory to the container configuration directory
-v /root/gitlab/logs:/var/log/gitlab \  # Mount the local directory to the container log directory
-v /root/gitlab/data:/var/opt/gitlab \  # Mount the local directory to the container data directory
gitlab/gitlab-ce:latest                 # Used image: Version (can not be)
gitlab_zh

notes:

-d put the container into the background and start it.

-h set the host name of the container to gitlab.

--Name set the container name to gitlab.

-p for port mapping, bind ports 443, 80 and 22 of git host with container ports running on git

In this way, anyone can access port 22 of the git host, that is, port 22 in the access container, and anyone can access port 80 of the git host (192.168.4.20), that is, port 80 in the access container.

-v bind the directory on the git host to the directory in the container. The / root/gitlab/config directory of the git host corresponds to the / etc/gitlab / directory in the container. Other directories are the same.

The last gitlab_zh is the mirror name.

2) Configure systemd to realize the self startup of the container (choose to do the experiment)

Generate a service file, - n is the name of the container, and generate a service file for the gitlab container

[root@git ~]# cd /usr/lib/systemd/system
[root@git ~]# podman generate systemd -n gitlab --files
[root@git ~]# cd ~

Set startup and self startup

[root@git ~]# systemctl enable container-gitlab.service

5, Modify gitlab configuration file (key)

 cd /root/gitlab/config    #Go to the directory where the configuration file is located
cp gitlab.rb gitlab.rb.bak  #Backup profile

1) Modify the configuration file.

# gitlab domain name
external_url 'http://192.168.8.21'  #Fill in the real IP address of gitlab

# time zone
gitlab_rails['time_zone'] = 'Asia/Shanghai'

# Allow custom avatars
gitlab_rails['gravatar_plain_url'] = 'http://www.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon'    #Just delete the notes here

# Since the port mapping is set, the following options are set to make the web page display the normally available ssh address, such as "ssh://git@192.168.8.21:2222/xxx/xxx.git"
gitlab_rails['gitlab_shell_ssh_port'] = 22                

# Close CI/CD  
gitlab_rails['gitlab_default_projects_features_builds'] = false   #You can leave it alone here

# Set GitLab backup path
gitlab_rails['manage_backup_path'] = true                #Just delete the notes
gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"  #Just delete the notes

2) Restart the container or enter the container to restart the gitlab service, and the configuration will take effect.

stay gitlab Execute the following command in the container  #The command to enter the container is: podman exec -it container ID /bin/bash
gitlab-ctl reconfigure
gitlab gitlab-ctl restart

Or restart the container directly
podman restart gitlab

At this point, you can see the real IP address by entering the GitLab page again, which is very convenient in work.

 

Keywords: GitLab

Added by yaba on Wed, 19 Jan 2022 04:32:11 +0200