gitlab安装与CICD配置

gitlab安装与CICD配置 极狐GitLab是基于开源GitLab EE的中国发行版,专为中国用户提供企业级DevOps平台解决方案。官网地址 https://gitlab.cn/installlinux软件安装包下载Gitlab下载地址 https://packages.gitlab.cn/#browse/browse本次使用软件包如下首先安装gtlab安装包较大建议下载好手动上传服务器。这里上传到/opt/software2编写安装脚本cd ~/bin vim gitlab-install.sh脚本内容如下sudo yum install -y curl policycoreutils-python openssh-server perl curl -fsSL https://packages.gitlab.cn/repository/raw/scripts/setup.sh | /bin/bash sudo rpm -ivh gitlab-jh-16.6.1-jh.0.el7.x86_64.rpm sudo yum install -y postfix sudo systemctl enable postfix sudo systemctl start postfix3修改脚本执行权限并执行chmod x gitlab-install.sh sh gitlab-install.sh**4**修改external_url编辑gitlab.rb[atguiguhadoop104 ~]$ sudo vim /etc/gitlab/gitlab.rb在文件中找到external_url修改为如下内容external_url http://hadoop104保存退出**5**修改host编辑gitlab.yml[atguiguhadoop104 ~]$sudovim/opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml.example找到gitlab.host修改为如下内容gitlab: \## Web server settings (**note:** host is the FQDN, do not include http://) host: http://ip port: 80 https: false保存退出修改文件名称[atguiguhadoop104 ~]$ sudo mv /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml.example /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml2.1.3执行初始化执行过程大概需要3分钟sudo gitlab-ctl reconfigure2.1.4启停命令1启动命令sudo gitlab-ctl start2停止命令sudo gitlab-ctl stop2.1.5修改 root密码根据安装后提示找到线索Default admin account has been configured with following details: Username: root Password: You didnt opt-in to print initial root password to STDOUT. Password stored to /etc/gitlab/initial_root_password. Thisfilewill be cleaned upinfirst reconfigure run after24hours.cat /etc/gitlab/initial_root_password根据密码进行登录root修改语言为中文如果是重新安装需要如下操作6重装需要彻底卸载1 卸载gitlab[atguiguhadoop104 opt]$ sudo rpm -e gitlab-jh-16.6.12 删除gitlab文件[atguiguhadoop104 opt]$ sudo rm -rf /etc/gitlab [atguiguhadoop104 opt]$ sudo rm -rf /var/opt/gitlab [atguiguhadoop104 opt]$ sudo rm -rf /opt/gitlab3 重装如果卡在sudo gitlab-ctl reconfigure配置命令上可以使用另外一个窗口执行sudo systemctl restart gitlab-runsvdir再重新执行初始化安装runner‌GitLab Runner 是 GitLab CI/CD 体系中负责实际执行流水线作业的开源应用程序‌它和 GitLab 内置的 CI 调度能力配合完成代码测试、构建、部署等自动化任务。核心作用GitLab 本身只负责 CI/CD 作业的调度分配Runner 作为执行端会主动连接 GitLab 实例、领取待执行的作业在指定环境中运行任务脚本并把执行日志和结果实时回传给 GitLab。主要特点用 Go 语言编写以单二进制包分发无额外依赖跨平台支持 Linux、macOS、Windows 系统。支持本地、Docker、SSH、Kubernetes 等多种执行器可灵活适配不同的作业运行环境。支持多作业并发执行可按需求限制单 Runner 的并行任务数还能基于云资源实现自动扩缩容。按作用范围可分为共享实例级、群组级、项目级三类满足不同层级的资源共享需求。安装步骤1.rpm安装rpm -ivh gitlab-runner-16.6.1-1.x86_64.rpm2.找到仓库的注册令牌3.之后运行注册命令3.1 这一步骤支持docker,k8s部署可后续选择进行配置此处选择shell方式[rootgitlab software]# gitlab-runner registerRuntime platformarchamd64oslinuxpid17002revisionf5da3c5aversion16.6.1 Runninginsystem-mode. Enter the GitLab instance URL(for example, https://gitlab.com/): http://192.168.100.191 Enter the registration token: PvSQyPCKRPyodKYjnUT_ GR1348941byTVyHi6xU5aahKYRB_z Enter a descriptionforthe runner:[gitlab]: Enter tagsforthe runner(comma-separated):testEnter optional maintenance noteforthe runner: ci WARNING: Supportforregistration tokens and runner parametersintheregistercommandhas been deprecatedinGitLab Runner15.6and will be replaced with supportforauthentication tokens. Formoreinformation, see https://docs.gitlab.com/ee/ci/runners/new_creation_workflow Registering runner... succeededrunnerPvSQyPCK Enter an executor: kubernetes, docker-windows, parallels, shell, ssh, virtualbox, custom, docker, docker-autoscaler, dockermachine, instance: shell Runner registered successfully. Feelfreeto start it, butifits running already the config should be automatically reloaded!Configuration(with the authentication token)was savedin/etc/gitlab-runner/config.tomlYou have new mailin/var/spool/mail/root[rootgitlab software]#4.之后可以看到runner已经注册到gitlab上了可以进行一些设置5,。创建仓库基于分支创建流水线6.这里采用默认最简单配置7.回到流水线查看执行情况仓库代码提交设置自动触发流水线开启此处配置即可