首页 Jenkins教程Gitlab安装部署

常见的持续集成工具

Gitlab常见操作和使用

运维派隶属马哥教育旗下专业运维社区,是国内成立最早的IT运维技术社区,欢迎关注公众号:yunweipai
领取学习更多免费Linux云计算、Python、Docker、K8s教程关注公众号:马哥linux运维

Gitlab部署与使用

Gitlab环境要求:

https://docs.gitlab.com/ce/install/requirements.html

https://docs.gitlab.com/ee/install/requirements.html

Gitlab 服务的安装文档: https://about.gitlab.com/install/

硬件配置要求较高:

测试环境:内存4G以上

生产环境:建议CPU2C,内存8G,磁盘10G以上配置,和用户数有关

下载并部署gitlab

Ubuntu 系统环境安装前准备
配置ubuntu 远程连接
[wang@ubuntu1804 ~]$ sudo su - root
[sudo] password for wang:
root@ubuntu:~# passwd 
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
[root@ubuntu1804 ~]# vim /etc/ssh/sshd_config
PermitRootLogin yes
配置ubuntu网卡和主机名
[root@ubuntu1804 ~]#cat /etc/netplan/01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      addresses:
      - 10.0.0.100/24
      gateway4: 10.0.0.2
      nameservers:
        search: [magedu.com, magedu.org]
        addresses: [180.76.76.76, 223.6.6.6]
配置ubuntu 仓库

配置阿里云仓库实现加速

[root@ubuntu1804 ~]#vim /etc/apt/sources.list
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
安装常见软件
[root@ubuntu1804 ~]# apt update
[root@ubuntu1804 ~]# apt install iproute2 ntpdate tcpdump telnet traceroute nfs-kernel-server nfs-common lrzsz tree openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev ntpdate tcpdump telnet traceroute gcc openssh-server lrzsz tree openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev ntpdate tcpdump telnet traceroute iotop unzip zip ipmitool
Centos 系统环境安装前准备

基于最小化服务器安装,准备配置如下:

# yum install vim gcc gcc-c++ wget net-tools lrzsz iotop lsof iotop bash-completion -y
# yum install curl policycoreutils openssh-server openssh-clients postfix -y
# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
# systemctl disable firewalld
# sed -i '/SELINUX/s/enforcing/disabled/' /etc/sysconfig/selinux
# hostnamectl set-hostname gitlab.example.com
# reboot
gitlab安装及使用

安装包官方下载地址:

https://packages.gitlab.com/gitlab/gitlab-ce

yum源清华大学下载地址:

https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/

https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el6/

ubuntu1804的deb源

https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu/pool/bionic/main/

[root@ubuntu1804 ~]#wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu/pool/bionic/main/g/gitlab-ce/gitlab-ce_11.11.8-ce.0_amd64.deb
[root@ubuntu1804 ~]#dpkg -i gitlab-ce_11.11.8-ce.0_amd64.deb

Gitlab安装部署插图

gitlab相关的目录:

/etc/gitlab #配置文件目录
/run/gitlab #运行pid目录
/opt/gitlab #安装目录
/var/opt/gitlab #数据目录
/var/log/gitlab #日志目录 
gitlab配置使用
[root@ubuntu1804 ~]#vim /etc/gitlab/gitlab.rb
[root@ubuntu1804 ~]#grep "^[a-Z]" /etc/gitlab/gitlab.rb
external_url 'http://10.0.0.100'  #修改此行
#增加下面行,可选邮件通知设置
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "29308620@qq.com"
gitlab_rails['smtp_password'] = "授权码"
gitlab_rails['smtp_domain'] = "qq.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_from'] = "29308620@qq.com"
初始化服务

执行配置并启动服务:

#修改完配置文件要执行此操作
[root@ubuntu1804 ~]# gitlab-ctl  reconfigure 

Gitlab安装部署插图1

验证gitlab启动完成
[root@ubuntu1804 ~]#gitlab-ctl status
run: alertmanager: (pid 29801) 117s; run: log: (pid 29411) 135s
run: gitaly: (pid 29575) 120s; run: log: (pid 28084) 222s
run: gitlab-monitor: (pid 29659) 119s; run: log: (pid 29196) 151s
run: gitlab-workhorse: (pid 29616) 120s; run: log: (pid 28848) 173s
run: logrotate: (pid 28923) 166s; run: log: (pid 29008) 163s
run: nginx: (pid 28851) 172s; run: log: (pid 28902) 169s
run: node-exporter: (pid 29638) 119s; run: log: (pid 29107) 157s
run: postgres-exporter: (pid 29817) 116s; run: log: (pid 29479) 131s
run: postgresql: (pid 28231) 217s; run: log: (pid 28266) 214s
run: prometheus: (pid 29767) 118s; run: log: (pid 29335) 139s
run: redis: (pid 27937) 229s; run: log: (pid 27974) 227s
run: redis-exporter: (pid 29668) 118s; run: log: (pid 29258) 145s
run: sidekiq: (pid 28742) 180s; run: log: (pid 28797) 177s
run: unicorn: (pid 28653) 186s; run: log: (pid 28698) 183s
常用命令
gitlab-rails #用于启动控制台进行特殊操作,如修改管理员密码、打开数据库控制台( gitlab-rails dbconsole)等
gitlab-psql #数据库命令行
gitlab-rake #数据备份恢复等数据操作

gitlab-ctl  #客户端命令行操作行
gitlab-ctl stop #停止gitlab
gitlab-ctl start #启动gitlab
gitlab-ctl restar #重启gitlab
gitlab-ctl  status #查看组件运行状态
gitlab-ctl  tail nginx #查看某个组件的日志

范例:

[root@ubuntu1804 ~]#gitlab-psql
psql (9.6.11)
Type "help" for help.

gitlabhq_production=# help
You are using psql, the command-line interface to PostgreSQL.
Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help with psql commands
       \g or terminate with semicolon to execute query
       \q to quit
gitlabhq_production=# \db
         List of tablespaces
    Name    |    Owner    | Location
------------+-------------+----------
 pg_default | gitlab-psql |
 pg_global  | gitlab-psql |
(2 rows)

gitlabhq_production-# \q
[root@ubuntu1804 ~]#
验证端口及状态

80端口是在初始化gitlib的时候启动的,因此如果之前的有程序占用会导致初始化失败或无法访问

[root@ubuntu1804 ~]#lsof -i :80
COMMAND   PID       USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   28851       root    7u  IPv4  88801      0t0  TCP *:http (LISTEN)
nginx   28852 gitlab-www    7u  IPv4  88801      0t0  TCP *:http (LISTEN)
nginx   28853 gitlab-www    7u  IPv4  88801      0t0  TCP *:http (LISTEN)
首次登录 gitlab web 界面

浏览器访问http://10.0.0.100/,首次登录web页面,必须先设置密码,密码要求最少8位

Gitlab安装部署插图2

本文链接:https://www.yunweipai.com/35652.html

常见的持续集成工具

Gitlab常见操作和使用

网友评论comments

发表回复

您的电子邮箱地址不会被公开。

暂无评论

Copyright © 2012-2022 YUNWEIPAI.COM - 运维派 京ICP备16064699号-6
扫二维码
扫二维码
返回顶部