gitlab与jenkins的安装使用
Git仓库部署
初始化版本库
cd
mkdir git
cd git/
git init
touch readme.md
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
.git目录是git跟踪管理版本库的
[root@jenkins ~]# cd git/
[root@jenkins git]# git init
初始化空的 Git 版本库于 /root/git/.git/
到GitHub或Gitee等注册账号,创建仓库。

origin git@gitee.com:H_zhinan/test.git (push)
git push -u origin master进行推送,第一次推送需要加- u 参数。
[root@gitlab git]# git push -u origin "master"
The authenticity of host 'gitee.com (180.76.198.77)' can't be established.
ECDSA key fingerprint is SHA256:FQGC9Kn/eye1W8icdBgrQp+KkGYoFgbVr17bmjey0Wc.
ECDSA key fingerprint is MD5:27:e5:d3:f7:2a:9e:eb:6c:93:cd:1f:c1:47:a3:54:b1.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'gitee.com,180.76.198.77' (ECDSA) to the list of known hosts.
Counting objects: 3, done.
Writing objects: 100% (3/3), 205 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-6.4]
To git@gitee.com:H_zhinan/test.git
* [new branch] master -> master
分支 master 设置为跟踪来自 origin 的远程分支 master。
Gitlab仓库
官网:https://gitlab.cn/install/
国内镜像下载地址:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/
下文使用官网下载安装gitlab。
安装和配置必须得依赖项
在系统防火墙中打开 HTTP、HTTPS 和 SSH 访问
sudo yum install -y curl policycoreutils-python openssh-server perl
sudo systemctl enable sshd
sudo systemctl start sshd
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo systemctl reload firewalld
下载极狐Gitlab
curl -fsSL https://packages.gitlab.cn/repository/raw/scripts/setup.sh | /bin/bash
sudo yum install gitlab-jh
Thank you for installing JiHu GitLab!
GitLab was unable to detect a valid hostname for your instance.
Please configure a URL for your JiHu GitLab instance by settingexternal_url
configuration in /etc/gitlab/gitlab.rb file.
Then, you can start your JiHu GitLab instance by running the following command:
sudo gitlab-ctl reconfigure
根据提示修改配置文件,更改external_url。
启动gitlab
gitlab-ctl reconfigure
第一次登录密码存储在/etc/gitlab/initial_root_password。
cat /etc/gitlab/initial_root_password
登录后修改密码和偏好设置。
git add example.html
git commit -m "add example.html"
git push -uf origin main
Jenkins
安装jdk
yum install fontconfig java-11-openjdk -y
安装jenkins
软件下载:https://jenkins.io/ zh /download/
国内镜像网站:https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat/
下载最新版的镜像
rpm -ivh jenkins-2.420-1.1.noarch.rpm
[root@jenkins ~]# rpm -ivh jenkins-2.420-1.1.noarch.rpm
警告:jenkins-2.420-1.1.noarch.rpm: 头V4 RSA/SHA512 Signature, 密钥 ID ef5975ca: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:jenkins-2.420-1.1 ################################# [100%]
启动服务
systemctl start jenkins.service
访问jenkins页面。jenkins默认端口号为8080,初始密码在/var/lib/jenkins/secrets/initialAdminPassword中。
创建用户后,添加国内插件地址。
https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json
并更改jenkins的配置,重启jenkins。
cd /var/lib/jenkins/updates
sed -i 's/http:\/\/updates.jenkinsci.org\/download/https:\/\/mirrors.tuna.tsinghua.edu.cn\/jenkins/g' default.json && sed -i 's/http:\/\/www.google.com/https:\/\/www.baidu.com/g' default.json
systemctl daemon-reload
systemctl restart jenkins.service