preamble
More than just chatting, there are some pits, recommended reading
Personal use system: Centos7.4, all operations are operated under root privileges by default
之前一直用github存放自己的开源代码,可是不开源的代码放文件夹过段时间就忘了,甚至于可能顺手就删了,没有了再去重新写吧,太麻烦。
-
Think about how many servers you have on your hands. If you pick one, you will say that gitlab is good, comparable to github.
-
I installed my student computer (1h2g1m), and the result was wrong after the installation was completed. The host was stuck and exploded. Later, I looked at the official website recommended configuration: 2h4G, so the first big hole came out: the minimum memory must be 4G .
-
At the same time set the swap swap space , the first knowledge point at this time: set swap swap memory
########################## 此时默认你的权限是root ########################## ########################## 不是的话加命令前加:sudo ########################## # 查看 swap 分区 # 如果只有标题栏,没有数据的话,那就是没有swap分区。 cat /proc/swaps # 创建swap分区 # 这里创建swap的大小=bs*count,这里是4G,具体可以自己算,一般推荐的话是你主机内存的1.5~2倍 # 这里如果没有找到/mnt/swap 那就是/data/swap dd if=/dev/zero of=/mnt/swap bs=512 count=8388616 # 通过mkswap命令将上面新建出的文件做成swap分区 mkswap /mnt/swap # 查看内核参数vm.swappiness中的数值是否为0,如果为0则根据实际需要调整成60 # 查看参数(个人建议改成永久,不然你主机万一重启就糟了) cat /proc/sys/vm/swappiness # 若是0设置参数(临时设置) sysctl -w vm.swappiness=60 # 永久设置(vm.swappiness=0 改为 vm.swappiness=60) vim /etc/sysctl.conf # 启用分区 swapon /mnt/swap echo “/mnt/swap swap swap defaults 0 0” >> /etc/fstab # 再次查看swap分区是否启动,有数据则说明设置成功了 cat /proc/swaps # 再次确认swap分区生效,生效依据为swap后面数字不为0 free -m
4. Now you can rest assured to continue to see the installation steps below
1. Installation
- There are two ways to install: (two specific depending on your own needs)
- Custom installation , that is, manual installation (cumbersome)
- Install through the pagoda , only need to install the pagoda and the following configuration (Personal recommendation )
1.1 Pagoda installation
- Install the pagoda and log in (enter once
y
to install)yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh
- Enter the panel address given above, enter the account password and log in to install LNMP . It is recommended to choose to compile and install , or all kinds of strange problems will be skipped, and then one-click installation (about 30 minutes).
- After the installation is complete, open to the software store . The third page has the latest Gitlab community version and Gitlab Chinese community version . Some details are also written. The latest version can be installed with 4G or 4G memory . It also supports wiki, CI/CD and other functions. , Click to confirm the installation (about 10 minutes)If you need domain name access settings, enter the settings and record the access address: http://IP:Port。
-
Because Gitlab comes with nginx, it does not support 80/8080 . If you want to use domain name access , you can use nginx reverse proxy . The operation is as follows:
- Click the menu bar on the left to enter the website , then add a site and fill in your own domain name .
- After creating the website, enter Settings— > Reverse Proxy— > Add Reverse Proxy ; I
will be in the latest version of Gitlab community just now**Http://IP:Port in the settingsFill it in and save it.
- At this point, you should be able to access the Gitlab homepage through the domain name you just created . After entering, set the password , and then jump to the login page , username: root
- Click the menu bar on the left to enter the website , then add a site and fill in your own domain name .
-
At this point, the key configuration step is entered.
-
1.2 Custom installation
# 安装依赖软件
yum -y install policycoreutils openssh-server openssh-clients postfix
# 设置postfix、ssh开机自启,并启动
systemctl enable postfix && systemctl start postfix
systemctl enable ssh && systemctl start ssh
# 添加GitLab仓库,并安装
curl -sS http://packages.gitlab.cc/install/gitlab-ce/script.rpm.sh | sudo bash
sudo yum install gitlab-ce
# 此时那你输入你的 IP看是否可以进入,正常你如果占用8080端口的话会报502,然后执行
vi /etc/gitlab/gitlab.rb
# 找到 external_url "http://IP:Port" IP可以设置为你的主机 IP,Port:8888之类自定义即可
# 例:external_url 'http://192.168.0.97:8999' 安全组要打开相应端口
# 重置并启动 GitLab
gitlab-ctl reconfigure
gitlab-ctl restart
### 此时安装完成,你可以去访问刚才 external_url设置的IP+Port进入Gitlab了
### 然后直接跳转去配置步骤即可
Two, placement
Gitlab is set to Chinese (User is to click on the drop-down list in your upper right corner)
User —> Setting —> Preferences —> Language —> 中文简体
Set the ssh secret key :
-
Open the CMD or Terminal of your computer
ssh-keygen -C "[email protected]"
-
At this time, there will be private key:
id_rsa
and public key:id_rsa.pub
two files in the directory of your computer-
Windows:
C:\Users\13737\.ssh
-
Linux:($user is your current username)
/$user/.ssh
-
Copy
id_rsa.pub
the contents to the next page of Gitlab ssh inUser —> Setting —> SSH Keys
, save
-
Set up Smtp mailbox service (Here is an example of personal QQ mailbox)
Note:
first go to open the smtp service of qq mailbox , the specific process is omitted here, there are many Baidus, and finally there is a password string , remember to use it below
-
Open
gitlab.rb
:vim /etc/gitlab/gitlab.rb
-
Copy the following things to
gitlab.rb
the end of the fileRemember stmp_password is not your QQ mailbox password, but the password string you applied for above
那两个邮箱可以写成一样的,不影响
gitlab_rails['smtp_enable'] = true gitlab_rails['smtp_address'] = "smtp.qq.com" gitlab_rails['smtp_port'] = 465 gitlab_rails['smtp_user_name'] = "[email protected]" gitlab_rails['smtp_password'] = "xxxxxxxxxxxxx" gitlab_rails['smtp_authentication'] = "login" gitlab_rails['smtp_enable_starttls_auto'] = true gitlab_rails['smtp_tls'] = true gitlab_rails['gitlab_email_from'] = '[email protected]'
-
Reconfiguration takes effect
gitlab-ctl reconfigure
-
Test whether the mailbox is configured correctly (this will take a few minutes, don’t be afraid if there is no response, it will be fine after a while, if something
similar appears,xxx:001:0>
it means you can continue)gitlab-rails console
-
Enter the following command to test. If the configuration is ok, you will receive an email named test in a few seconds.
# [email protected]换成你要实际发送测试邮件的目标邮箱地址 Notify.test_email('[email protected]', 'test', 'test_text').deliver_now
error
After configuring the smtp mailbox server, I found that I entered Gitlab and reported a 502 error
-
gitlab-ctl tail
Display after input :
-
Report an error:
chpst: fatal: unable to run: /opt/gitlab/embedded/sbin/nginx: file does not exist
-
the reason:
宝塔的问题, 为了防止nginx冲突, 把gitlab的nginx启动文件名改成了gitlab-web, 但有个配置文件没修改成功导致错误。
-
solve:
# 修改nginx启动文件: vi /opt/gitlab/sv/nginx/run ## 将exec chpst -P /opt/gitlab/embedded/sbin/nginx -p /var/opt/gitlab/nginx ## 改为 ## exec chpst -P /opt/gitlab/embedded/sbin/gitlab-web -p /var/opt/gitlab/nginx # 重启nginx服务 service nginx restart
to sum up
这次从自定义安装到发现宝塔安装,从1h2g1m跑不起来到狠下心买了一台2h4g5m的服务器,总算是搭建完毕了,中间肯定还会有其他问题,比如你想把仓库的位置改变,但这些网上有很多,这次把常见的安装gitlab的大坑和可以通过宝塔来安装的简单技巧发出来,避免别人安装费时费力的操作,一起学习,一起进步。