Continuous integration environment (1)-installation and use of Gitlab code hosting server

1. Introduction to GitlabInsert picture description here

Official website: https://about.gitlab.com/

GitLab is an open source project for a warehouse management system. It uses Git as a code management tool and builds a web service on this basis. GitLab, like GitHub, is a third-party Git-based work. It is free and open source (based on the MIT protocol). Similar to Github, you can register users, submit your code, add SSHKey, and so on. The difference is that GitLab can be deployed on its own server, and all information such as the database is in your hands. It is suitable for collaborative development within the team. Simply put, GitLab can be regarded as a personal version of GitHub.

2. Gitlab installation (yum installation)

2.1 Installation related dependencies

yum -y install policycoreutils openssh-server openssh-clients postfifix

2.2 Set sshd to start at boot

Note: This step can be skipped, obviously ssh services are self-starting

systemctl enable sshd 

2.3 Set postfifix to start automatically after booting, and start, postfifix supports gitlab sending function

systemctl enable postfix.service && systemctl start postfix.service

2.4. Open ssh and http services, reload firewall

Note: If you turn off the firewall, you do not need to do the above configuration

firewall-cmd --add-service=ssh --permanent 
firewall-cmd --add-service=http --permanent
firewall-cmd --reload

2.5 Download the gitlab package and install it

cd /root/pkg
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-13.7.8-ce.0.el7.x86_64.rpm
rpm -ivh gitlab-ce-13.7.8-ce.0.el7.x86_64.rpm

or

cat << EOF > /etc/yum.repos.d/gitlab-ce.repo
[gitlab-ce]
name=gitlab-ce
baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7
gpgcheck=0
enabled=1
EOF
yum makecache     #更新yum源 
yum -y install gitlab-ce          #安装最新版本的gitlab
yum list gitlab-ce --showduplicates | sort -r  #查看仓库中所有gitlab版本
yum -y intsall gitlab-ce-12.3.5-ce.0.el7       #安装指定版本的gitlab

2.6 Modify gitlab configuration

1) Directory structure

/opt/gitlab     主目录
/etc/gitlab     配置文件目录
/var/log/gitlab 日志目录

2) Modify the gitlab configuration file

vim /etc/gitlab/gitlab.rb

#gitlab基本配置:
#外部访问url(并非必须配置;经过编译后,自动将这个配置编译到nginx配置,nginx就无需配置了)
external_url 'http://10.99.200.110:8888'
nginx['listen_port'] = 8088

3) Configure the domain name (if the above configuration file /etc/gitlab/gitlab.rb has been modified, it can be skipped)

vim /var/opt/gitlab/nginx/conf/gitlab-http.conf (if the service has not been reconfigured, there is no such configuration file)
the port for external network access, if the server already has a server occupying 80, then it can be changed here Into other

listen *:8088;
server_name gitlab.test.domain.com;
set $http_host_with_default "gitlab.test.domain.com:8088"

Supplementary note: Because this custom nginx configuration will be regenerated when compiling the gitlab configuration /etc/gitlab/gitlab.rb, so as long as the gitlab configuration is configured well, the above nginx does not need to be customized.

2.7 Reload configuration and start gitlab

gitlab-ctl reconfigure
gitlab-ctl restart
相关命令
gitlab-ctl restart               #重新启动gitLab
gitlab-ctl start                 #启动全部服务
gitlab-ctl restart               #重启全部服务
gitlab-ctl stop                  #停止全部服务
gitlab-ctl restart nginx         #重启单个服务
gitlab-ctl status                #查看全部组件的状态
gitlab-ctl show-config           #验证配置文件
gitlab-ctl uninstall             #删除gitlab(保留数据)
gitlab-ctl cleanse               #删除所有数据,重新开始
gitlab-ctl tail <svc_name>       #查看服务的日志
gitlab-ctl tail                  #查看所有日志
gitlab-ctl tail nginx/gitlab_access.log     #查看nginx访问日志
gitlab-rake gitlab:check SANITIZE=true --trace  #检查gitlab
gitlab-rails console production      #进入控制台 ,可以修改root 的密码

2.8 Add port to firewall

Note: If you turn off the firewall, you do not need to do the above configuration

firewall-cmd --zone=public --add-port=8888/tcp --permanent
firewall-cmd --reload

3. Gitlab installation (docker version installation)

3.1 docker installation

Docker installation reference

3.2 gitlab installation

docker search gitlab-ce      #查找镜像
docker pull gitlab/gitlab-ce       #拉取镜像
mkdir -p /home/GitLab/{
    
    config,data,log}  #创建相关目录
chmod -R 755 /home/GitLab/{
    
    config,data,log}  #权限
docker run -itd  -h 192.168.16.119 -p 443:443 -p 80:80 -p 222:22 --name GitLab --restart always -v /home/GitLab/config:/etc/gitlab -v /home/GitLab/log:/var/log/gitlab -v /home/GitLab/data:/var/opt/gitlab gitlab/gitlab-ce   #启动容器

Parameter Description:

-d:后台运行
-p:将容器内部端口向外映射
–name:命名容器名称
-v:将容器内数据文件夹或者日志、配置等文件夹挂载到宿主机指定目录

Insert picture description here
The configuration in the configuration through yum installation is the same, so I won't repeat it here, and the configuration files have been persisted locally.

3.3 Backup script

Write backup script

#!/bin/bash
case $1 in
  start)
    docker exec  GitLab gitlab-rake gitlab:backup:create;;
esac

Insert picture description here
Write timed tasks

echo '00 03 * * 6 /home/GitLab/gitlab_data_backup.sh start' >>  /var/spool/cton/root

4. Log in to the homepage

The first time you visit GitLab, you need to wait patiently. The 502 may appear due to the incomplete service; the system will redirect the page to the reset password page, you need to enter the password of the initial administrator account, and the administrator user name is root , The initial password is 5iveL!fe (the initial password can be obtained in the log). After resetting the password, the new password is the one you just entered.

Reset password
image
Login page The page
image
after logging in
image

5. Precautions and troubleshooting

  1. The default installation login requires resetting the root password. You can set a complex password and log in by yourself.
  2. Gitlab itself uses port 80. If the server has 80 enabled before installation, an error will be reported after installation. Need to change the default port of gitlab. Modify the external_url'http://localhost:8088' configuration item in the /etc/gitlab/gitlab.rb configuration file.
  3. If you just want to use port 80, that's fine. If you change the port, you can adjust the nginx configuration file to set the nginx reverse proxy.
  4. Here you can bind your own gitlab domain name or public network, internal network IP to replace localhost for public network access, depending on your actual situation. For safety, gitlab is generally deployed on the intranet. The specific deployment location, please decide according to your actual situation. (For security reasons, it is not recommended to set the public IP for exposure. You can set up IP binding for return or other rules for IP avoidance access through nginx.) The test gitlab address domain name of this site is: gitlab.test.domain.com.
  5. Unicorn itself uses port 8080, if you don't use 8080 there, you don't need to modify it later. If 8080 is enabled on the server before installation, an error will be reported after installation. Need to change the default port of unicorn: modify the unicorn['listen'] = '127.0.0.1' unicorn['port'] = 3000 configuration item in the /etc/gitlab/gitlab.rb configuration file.
  6. Every time you reconfigure, you need to execute sudo gitlab-ctl reconfigure to make it effective.
  7. Log location: /var/log/gitlab You can go in to view the access log and error log, etc., for access review and exception troubleshooting.
  8. If gitlab-ctl reconfigure reports an error.

image
Try this command, and then execute gitlab-ctl reconfigure again

cat /etc/sysctl.conf /etc/sysctl.d/*.conf | sysctl -e -p -
  1. When the browser visits, it will report 502 errors from time to time, and the virtual memory of the server needs to be increased.
dd if=/dev/zero of=/var/swap bs=1024 count=2048000 #增加2G左右SWAP
mkswap /var/swap #设置交换文件
swapon /var/swap #激活启用交换分区
echo "/var/swap swap swap defaults 0 0" >> /etc/fstab #加入开机自启

6. Use of Gitlab code hosting server (add group, create user, create project)

6.1 Create project group and project

Create project group
Insert picture description here
Create project
Insert picture description here
Insert picture description here
Insert picture description here

6.2 Account creation and authorization

Create an account After the
Insert picture description here
Insert picture description here
account is created, change the password
Insert picture description here
Insert picture description here
Add the user to the project to authorize
Insert picture description here

6.3 Create a new warehouse

git clone http://10.99.200.110:8888/test/deam-test.git
cd deam-test
touch README.mdgit add README.md
git commit -m "add README"
git push -u origin master

Insert picture description here

6.4 Associate local projects to gitlab

cd existing_folder  #existing_folder是已有的目录
git init
git remote add origin http://10.99.200.110:8888/test/web_deam.git
git add .
git commit -m "Initial commit"
git push -u origin master

Insert picture description hereInsert picture description here
It's all here. For more information, please refer to the personal WeChat public account ALL In Linux, let's scan it!
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_44729138/article/details/115020279