环境:
操作系统: Centos7.6
IP地址: 192.168.31.60
内核版本: 3.10.0-957.el7.x86_64
第一种方式: 使用RPM方式安装
源地址:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/
1)安装部署
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-12.9.0-ce.0.el7.x86_64.rpm
rpm -ivh gitlab-ce-12.9.0-ce.0.el7.x86_64.rpm
vim /etc/gitlab.rb # 编辑站点地址
external_url 'http://gitlab.ziioffice.com'
git_data_dirs({ "default" => { "path" => "/data/git-data" } })
gitlab_rails['backup_path'] = "/data/git-data/backups"
#配置邮箱
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = 'xionghaihua@distrii.com' gitlab_rails['gitlab_email_display_name'] = 'xionghaihua' gitlab_rails['gitlab_email_reply_to'] = 'xhaihua@distrii.com'
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.distrii.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "xionghaihua@distrii.com"
gitlab_rails['smtp_password'] = "123456"
gitlab_rails['smtp_domain'] = "smtp.distrii.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_openssl_verify_mode'] = 'peer'
gitlab_rails['smtp_tls'] = true2)启动gitlab
gitlab-ctl reconfigure
gitlab-ctl start
gitlab-ctl status
gitlab-ctl stop
3)日志查看:
日志路径: /var/log/gitlab
查看所有日志:gitlab-ctl tail
查看nginx日志:gitlab-ctl tail nginx/gitlab_access.log
查看指数据库日志:gitlab-ctl tail postgresql
第二种方式: 使用Docker-compose方式安装
1)安装部署docker
yum -y install yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum -y install docker-ce
systemctl enable docker && systemctl start dockermkdir -p /data/docker
cat >>/etc/docker/daemon.json <<-EOF
{ "registry-mirrors": ["https://wxezogdu.mirror.aliyuncs.com"],
"graph": "/data/docker"
}
EOF
systemctl restart docker
#安装docker-compose
curl -L https://get.daocloud.io/docker/compose/releases/download/1.24.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
#验证
[root@openldap ~]# docker-compose -v
docker-compose version 1.24.0, build 0aa59064
[root@openldap ~]# docker -v
Docker version 19.03.8, build afacb8b2)编写docker-compose.yml文件
#拉取镜像
docker pull gitlab/gitlab-ce:12.9.0-ce.0#创建目录
mkdir -p /data/gitlab
mkdir /data/gitlab/{config,data,logs}#编写docker-compose.yml文件
cd /data/gitlab
cat >docker-compose.yml <<-EOF
version: "3"
services:
gitlab:
image: gitlab/gitlab-ce:12.9.0-ce.0
container_name: gitlab
restart: always
hostname: 'gitlab.ziioffice.com'
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url "http://gitlab.ziioffice.com"
gitlab_rails['gitlab_shell_ssh_port'] = 2222
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = 'xionghaihua@distrii.com'
gitlab_rails['gitlab_email_display_name'] = 'xionghaihua'
gitlab_rails['gitlab_email_reply_to'] = 'xionghaihua@distrii.com'
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.distrii.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "xhaihua@distrii.com"
gitlab_rails['smtp_password'] = "123456"
gitlab_rails['smtp_domain'] = "smtp.distrii.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_openssl_verify_mode'] = 'peer'
gitlab_rails['smtp_tls'] = true
ports:
- '443:443'
- '2222:22'
- "80:80"
volumes:
- '/data/gitlab/config:/etc/gitlab'
- '/data/gitlab/logs:/var/log/gitlab'
- '/data/gitlab/data:/var/opt/gitlab'
logging:
driver: "json-file"
options:
max-size: "20m"
max-file: "10"EOF
#执行启动
[root@gitlab gitlab]# docker-compose up -d
Creating network "gitlab_default" with the default driver
Creating gitlab ... done
[root@gitlab gitlab]# docker-compose ps
Name Command State Ports -----------------------------------------------------------------------------------------------------------------
gitlab /assets/wrapper Up (health: starting) 0.0.0.0:2222->22/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:80->80/tcp#gitlab访问
http://gitlab.ziioffice.com
第三种方式: kubernetes部署gitlab
https://gitee.com/xhaihua/devops/blob/master/gitlab/deploy-gitlab.yaml
---
kind: Deployment
apiVersion: apps/v1
metadata:
labels:
k8s-app: gitlab
name: gitlab
namespace: devops
spec:
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
k8s-app: gitlab
template:
metadata:
labels:
k8s-app: gitlab
namespace: devops
name: gitlab
spec:
containers:
- name: gitlab
image: gitlab/gitlab-ce:12.9.0-ce.0
imagePullPolicy: IfNotPresent
ports:
- containerPort: 30088
name: web
protocol: TCP
- containerPort: 22
name: agent
protocol: TCP
resources:
limits:
cpu: 2000m
memory: 8Gi
requests:
cpu: 500m
memory: 512Mi
livenessProbe:
httpGet:
path: /users/sign_in
port: 30088
initialDelaySeconds: 60
timeoutSeconds: 5
failureThreshold: 12
readinessProbe:
httpGet:
path: /users/sign_in
port: 30088
initialDelaySeconds: 60
timeoutSeconds: 5
failureThreshold: 12
volumeMounts:
- name: gitlab-conf
mountPath: /etc/gitlab
- name: gitlab-log
mountPath: /var/log/gitlab
- name: gitlab-data
mountPath: /var/opt/gitlab
env:
- name: gitlab_HOME
value: /var/lib/gitlab
volumes:
- name: gitlab-conf
hostPath:
path: /data/devops/gitlab/config
type: Directory
- name: gitlab-log
hostPath:
path: /data/devops/gitlab/logs
type: Directory
- name: gitlab-data
hostPath:
path: /data/devops/gitlab/data
type: Directory
serviceAccountName: gitlab
---
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
k8s-app: gitlab
name: gitlab
namespace: devops
---
kind: Service
apiVersion: v1
metadata:
labels:
k8s-app: gitlab
name: gitlab
namespace: devops
spec:
type: NodePort
ports:
- name: web
port: 30088
targetPort: 30088
nodePort: 30088
- name: slave
port: 22
targetPort: 22
nodePort: 30022
selector:
k8s-app: gitlab
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: gitlab
namespace: devops
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["create","delete","get","list","patch","update","watch"]
- apiGroups: [""]
resources: ["pods/exec"]
verbs: ["create","delete","get","list","patch","update","watch"]
- apiGroups: [""]
resources: ["pods/log"]
verbs: ["get","list","watch"]
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: RoleBinding
metadata:
name: gitlab
namespace: devops
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: gitlab
subjects:
- kind: ServiceAccount
name: gitlab
namespace: devops
网友评论