Installing Gitlab
1.1. Obtain gitlab image package
docker pull gitlab/gitlab-ce # Community Edition (CE) here represents community specimens,
1.2. Prepare gitlab working directory on the machine
mkdir -p /data/gitlab/config # Create config directory mkdir -p /data/gitlab/logs # Create logs directory mkdir -p /data/gitlab/data # Create data directory
1.3 mirror and start
Since port 80 of the server may be occupied, we have changed it to another port to start
docker run --detach --hostname :IP --publish 7001:443 --publish 7002:80 --publish 7003: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 --volume /etc/localtime:/etc/localtime gitlab/gitlab-ce docker run -d -p 2443:443 -p 5678:80 -p 2222:22 --name gitlab --restart always -v /srv/gitlab/config:/etc/gitlab -v /srv/gitlab/logs:/var/log/gitlab -v /src/gitlab/data:/var/opt/gitlab docker.io/gitlab/gitlab-ce
Parameter name | Parameter description |
---|---|
detach | Specifies whether the container runs in the foreground or background |
hostname | Specify the host address. If there is a domain name, you can point to the domain name |
publish | Specify the port exposed by the container. The port on the left represents the port of the host machine, and the port on the right represents the port of the container |
name | Give the container a name |
restart always | Always restart |
volume | Data volume is the most important knowledge point in docker |
Parameter description of the script, Please refer to the official documents for details
1.4. Modify configuration file
Modify gitlab YML file
vim /src/gitlab/data/gitlab-rails/etc/gitlab.yml
Find the following configuration, modify the IP or domain name that the host serves you (http: / /) and save and exit after modification
Modify gitlab RB file
external_url 'http://192.168.16.200:7002' gitlab_rails['gitlab_ssh_host'] = '192.168.16.200' gitlab_rails['gitlab_shell_ssh_port'] = 7003
1.5 restart gitlab
Stop and remove previously started gitlab
stop it
docker stop gitlab
remove
docker rm gitlab
Restart gitlab
1.6 and 4.8 check the local port status again
netstat -tnl # command
1.7. Open firewall port
[root@h200 ~]# firewall-cmd --zone=public --permanent --add-port=7002/tcp success [root@h200 ~]# firewall-cmd --zone=public --permanent --add-port=1001/tcp success [root@h200 ~]# firewall-cmd --zone=public --permanent --add-port=1003/tcp success [root@h200 ~]# [root@h200 ~]# firewall-cmd --reload success [root@h200 ~]#
Container internal commands
gitlab-ctl reconfigure // Reapply gitlab configuration gitlab-ctl restart // Restart gitlab service gitlab-ctl status // View gitlab running status gitlab-ctl stop // Stop gitlab service gitlab-ctl tail // View gitlab run log
Installing gitlab runner
You can configure settings -- > cicd -- > Runner in a project, or you can install shared Runner on the GitLab main settings page. The installation methods are the same
1. Pull the Runner image and start it
docker run -d --name gitlab-runner --restart always -v /srv/gitlab-runner/config:/etc/gitlab-runner -v /var/run/docker.sock:/var/run/docker.sock gitlab/gitlab-runner:latest
2. Enter the Runner container
docker exec -it gitlab-runner bash
3. Run the following command
gitlab-runner register
Enter the address of the Gitlab instance
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com ) http://xxx
Enter a token
Please enter the gitlab-ci token for this runner xxx
Enter a description of the Runner
Please enter the gitlab-ci description for this runner [hostname] my-runner
Enter the label associated with the Runner
Please enter the gitlab-ci tags for this runner (comma separated): my-tag,another-tag
Enter the performer of Ruuner
Please enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, virtualbox, docker-ssh, shell: docker
If the above executor is docker, you need to gitlab-ci. Specify docker version in YML
Please enter the Docker image (eg. ruby:2.1): alpine:latest
After passing the above command, you can view the newly created runner in gitlab
4. Modify Runner profile
vim /srv/gitlab-runner/config/config.toml
Find the volumes configuration and modify it as follows: mount the docker of the host and configure the cache of Maven to improve efficiency
volumes = ["/cache","/var/run/docker.sock:/var/run/docker.sock","/data/.m2/:/.m2/"]
Add a line of configuration below the volumes configuration to prevent the Runner from repeatedly pulling images
pull_policy = "if-not-present"
Just restart the Runner
docker restart gitlab-runner