Installing GitLab

GitLab - Installation(Traditional Way)

1
yum -y install policycoreutils openssh-server openssh-clients postfix

2. Start the ssh service & set it to start on boot

1
systemctl enable sshd && sudo systemctl start sshd

3. Set postfix to start automatically after booting, and start it, postfix supports gitlab sending function

1
systemctl enable postfix && systemctl start postfix

4. Open ssh and http services, then reload the firewall list

1
2
3
firewall-cmd --add-service=ssh --permanent 
firewall-cmd --add-service=http --permanent
firewall-cmd --reload

5. Download the gitlab package and install the online download installation package

Download

1
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el6/gitlab-ce-12.4.2-ce.0.el6.x86_64.rpm

Install

1
rpm -i gitlab-ce-12.4.2-ce.0.el6.x86_64.rpm

6. Modify gitlab configuration

1
vi /etc/gitlab/gitlab.rb
external_url 'http://192.168.66.100:82'
nginx['listen_port'] = 82

7. Reload configuration and startup gitlab

1
2
gitlab-ctl reconfigure
gitlab-ctl restart

8. Add port to firewall

1
2
firewall-cmd --zone=public --add-port=82/tcp --permanent 
firewall-cmd --reload

GitLab - Installation(with Docker)

1. Installing Docker

  • If you haven’t installed Docker yet, you first need to install it on your system. You can download the installation package for your operating system from the official Docker website.
  • Installing Docker Related Url

2. Pulling a GitLab Mirror

  • Use Docker commands to pull GitLab images from Docker Hub. You can use the following commands:
    1
    docker pull gitlab/gitlab-ce:latest

3. Configure the Docker container and start GitLab

  • You need to configure some parameters of the GitLab container, such as port mapping, data volumes, and so on. Here’s a simple sample command to start the GitLab container:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    docker run --detach \
    --hostname gitlab.example.com or your_ip \
    --publish 443:443 --publish 80:80 --publish 22:22 \
    --name gitlab \
    --restart always \
    --volume /srv/gitlab/config:/etc/gitlab \
    --volume /srv/gitlab/logs:/var/log/gitlab \
    --volume /srv/gitlab/data:/var/opt/gitlab \
    gitlab/gitlab-ce:latest
  • This command starts a GitLab container and binds it to ports 80 (HTTP), 443 (HTTPS), and 22 (SSH) on the host. It also sets up some persistent storage volumes so that GitLab data is not lost when the container is restarted.

4. Accessing and Configuring GitLab

  • Once the container is started, you can access GitLab through your browser. the first time you access it, you may need to set an administrator password.
  • Visit http://<your host IP or domain name> to access GitLab.

5. Follow-up maintenance

  • To update GitLab, you can pull the latest GitLab image and restart your container.

Be sure to adjust the configurations in the above commands, such as domain name, port mapping, and paths to data volumes, to your actual needs. If your environment has special network or security requirements, you will also need to adjust accordingly.

6. Other

0. Cat Password(Docker)

1
docker exec -it c2e grep 'Password:' /etc/gitlab/initial_root_password

1. Rest root password

If you need to reset the administrator password within a GitLab container, you can follow these steps:

  1. Enter the Bash Session of the GitLab Container:

    • First, identify the name or ID of your GitLab container. You can use docker ps to see a list of running containers.
    • Enter the GitLab container’s bash session by running:
      1
      docker exec -it [your-gitlab-container-name] bash
  2. Run the GitLab Rake Command to Reset Password:

    • Inside the bash session of the GitLab container, run the following command to access the GitLab Rails console:
      1
      gitlab-rails console -e production
    • This will open a Ruby on Rails console. In this console, execute the following commands to change the root user’s password:
      1
      2
      3
      4
      user = User.find_by(username: 'root')
      user.password = 'yournewpassword'
      user.password_confirmation = 'yournewpassword'
      user.save!
    • Replace 'yournewpassword' with the new password you wish to set.
  3. Exit the Console and Container:

    • After completing the above steps, type exit to leave the Ruby on Rails console and type exit again to leave the container’s bash session.
  4. Login Using the New Password:

    • After resetting the password, try logging into GitLab using the root username and the new password you just set.

Make sure to use a strong password for security reasons. If you encounter any issues during these steps, refer to the official GitLab documentation, as commands may slightly vary with different versions of GitLab.

2. WSL2 network Problem

If you are running the GitLab Docker container in a Windows Subsystem for Linux 2 (WSL2) environment, you can access it in a few steps:

  1. Determine the IP address of the WSL2

    • Opening a terminal in a WSL2 environment.
    • Execute the command ip addr to find the IP address of your WSL2 instance. Normally this address is displayed under the eth0 interface, similar to inet 172.25.x.x/20.
  2. Configuring and Starting GitLab Containers

    • In WSL2, start the GitLab container using the Docker commands mentioned earlier. Use the IP address of WSL2 in the --hostname parameter.
  3. Accessing GitLab from Windows

    • On your Windows host, open a browser.
    • Enter the IP address of the WSL2 instance, e.g. http://172.25.x.x (replace it with the actual WSL2 IP address).
  4. **Configure port forwarding (if required)**:

    • If you do not have direct access to the WSL2 IP, you may need to configure port forwarding on Windows.
    • To do this, use a similar command in PowerShell:
      1
      netsh interface portproxy add v4tov4 listenport=80 listenaddress=0.0.0.0 connectport=80 connectaddress=172.25.x.x
    • This command forwards port 80 on the Windows host to the appropriate port on the WSL2.
  5. Note

    • The WSL2’s network configuration may have changed since the reboot. If you find that you cannot access GitLab, you may need to recheck the WSL2’s IP address and update the port forwarding settings.
    • Make sure that Windows Firewall or any security software does not block access to these ports.
    • If you want to remove the above web proxy rules:
      1
      netsh interface portproxy delete v4tov4 listenport=80 listenaddress=0.0.0.0
      As a result, you should be able to access your GitLab instance running on WSL2 from your Windows environment. If you encounter any network connectivity issues, check your network settings and firewall rules.

Installing GitLab
https://www.hardyhu.cn/2022/01/26/Installing-GitLab/
Author
John Doe
Posted on
January 26, 2022
Licensed under