Debian11上安装GitLab
Debian11上安装GitLab reference-site-list
steps 安装准备 1 2 3 4 5 6 7 8 apt-get update apt-get install -y curl openssh-server ca-certificates perl apt-get install -y postfix
添加包仓库并安装 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh | bash EXTERNAL_URL="https://gitlab.xplorist.tech" GITLAB_ROOT_PASSWORD="password" apt-get install gitlab-ee cd /var/cache/apt/archivesEXTERNAL_URL="https://gitlab.xplorist.tech" GITLAB_ROOT_PASSWORD="password" apt-get install gitlab-ee systemctl enable gitlab-runsvdir.service
设置GitLab
浏览器打开 https://gitlab.xplorist.tech
使用root账号登陆,然后找到右上角的用户图标,点击下拉框中的Edit profile, 再选择Password,就可以修改安装时设置得不够安全的密码
点击左上角的Menu,选择Admin,进入Settings => General => Sign-up restrictions, 取消 Sign-up enabled 选中,不允许其他人注册
安装GitLab-runner
1 2 3 4 5 6 7 8 9 10 11 12 curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh" | bash apt-get update cd /var/cache/apt/archivesapt-get install gitlab-runner
本地push项目到GitLab 1 2 3 4 5 6 7 8 9 10 11 12 13 14 git config --global user.email "xplorist@163.com" git config --global user.name "xplorist" git config --global credential.helper store git init git remote add origin https://gitlab.xplorist.tech/xplorist/keep.git git add . git commit -m "init commit" git push -u origin master:master
GitLab和GitLab-runner进行交互式注册
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 gitlab-runner register 1.Enter the GitLab instance URL (for example, https://gitlab.com/): https://gitlab.xplorist.tech 2. Enter the registration token: dasdfasdfeta 3.Enter a description for the runner: shared_runner 4.Enter tags for the runner (comma-separated): shared_runner 5.Enter an executor: parallels, ssh, virtualbox, kubernetes, docker-windows, docker, docker-ssh, shell, docker+machine, docker-ssh+machine, custom: shell Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
在项目中添加.gitlab-ci.yml文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 build: stage: build before_script: - yarn script: - hexo deploy - rsync -av ./public/ /usr/share/nginx/html/keep/ tags: - shared_runner only: - main
tags这里的tags要和注册的gitlab-runner的tag一样
only 指定 gitlab repository 中的指定分支,就是GitLab服务器上的远程分支
配置项目中hexo的配置文件_config.yml中的deploy 1 2 3 4 deploy: type: git repo: git@github.com:Xplorist/Xplorist.github.io.git branch: master
将wordpress文件夹复制到keep文件夹下 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 cd /usr/share/nginx/htmlmkdir keepcp /usr/share/nginx/html/index.html /usr/share/nginx/html/keep/index.htmlcp -r /usr/share/nginx/html/wordpress /usr/share/nginx/html/keep/wordpressmv /usr/share/nginx/html/wordpress /usr/share/nginx/html/wordpress_bakmv /usr/share/nginx/html/picture /usr/share/nginx/html/keep/picturemv /usr/share/nginx/html/info.php /usr/share/nginx/html/keep/info.phpchmod -R -f 777 /usr/share/nginx/html/keep/
配置nginx 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 vi /etc/nginx/conf.d/xplorist.tech.conf location / { root /usr/share/nginx/html/keep; index index.html index.htm index.php; } location ~ \.php$ { root /usr/share/nginx/html/keep; include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.3-fpm.sock; } nginx -s reload
上传keep项目的public文件夹测试hexo效果
将本地开发开发的keep项目生成的public文件夹打包成public.zip后通过SFTP上传到服务器,然后解压
1 2 3 4 5 6 7 cd /usr/share/nginx/htmlunzip public.zip cp -r /usr/share/nginx/html/public/* /usr/share/nginx/html/keep
gitlab-runner服务器上进行相关配置
本地提交keep项目的源码到GitLab
GitLab 检测到.gitlabci.yml , 触发GitLab-runner的 shell 执行器,执行 .gitlabci.yml 中的shell脚本
GitLab-runner从 GitLab 仓库 pull 最新的代码,然后执行 .gitlabci.yml 脚本
.gitlabci.yml 脚本中的主要内容就是实现 hexo deploy,在本地生成public文件夹中编译好的静态html网页
然后利用rsync将public文件夹中的内容增量更新到nginx的html文件夹中
hexo deploy会触发hexo项目中的_config.yml中的deploy设置,从而执行hexo deploy命令
hexo deploy中的设置就是将public文件夹中的静态html网页全部push到github.io仓中
git客户端到github的操作则是配置了ssh的方式实现免密,所以github仓库链接也是ssh的链接
1 2 3 4 5 6 cd ~curl -sL https://deb.nodesource.com/setup_16.x -o nodesource_setup.sh bash nodesource_setup.sh apt-get install -y nodejs npm install --global yarn
配置SSH实现免密同步到GitHub pages
1 ssh-keygen -t ed25519 -C "xplorist@163.com"
复制ssh key到gitlab-runner账号文件夹下
1 2 3 4 5 6 7 8 cp -r /root/.ssh /home/gitlab-runnerchmod -R -f 777 /home/gitlab-runner/.ssh/
登录GitHub后,进入Settings 的 SSH and GPG keys, 新增SSH key将公钥复制进去
1 cat /home/gitlab-runner/.ssh/id_ed25519.pub
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 git config --global user.email "xplorist@163.com" git config --global user.name "xplorist" git config --global credential.helper store git clone git@github.com:Xplorist/readme.git cd readmevi test.md git add . git commit -m "add test" git push -u origin main:main cp /root/.ssh/known_hosts /home/gitlab-runner/.ssh/known_hostscd /root/.sshls cd /home/gitlab-runner/.sshls
提交keep项目到服务器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 git init git remote add origin https://gitlab.xplorist.tech/xplorist/keep.git git fetch origin main git merge origin/main git branch git checkout -b main git status git add . git commit -m "init commit" git push -u origin main:main
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 INFO 171 files generated in 1.9 s INFO Deploying: git INFO Setting up Git deployment... Initialized empty Git repository in /home/gitlab-runner/builds/xTeKDtDV/0/xplorist/keep/.deploy_git/.git/ *** Please tell me who you are. Run git config --global user.email "you@example.com" git config --global user.name "Your Name" to set your account's default identity. Omit --global to set the identity only in this repository. fatal: unable to auto-detect email address (got ' gitlab-runner@iZ2vcevk40p3shxd80kkt7Z.(none)') FATAL { err: Error: Spawn failed at ChildProcess.<anonymous> (/home/gitlab-runner/builds/xTeKDtDV/0/xplorist/keep/node_modules/hexo-util/lib/spawn.js:51:21) at ChildProcess.emit (node:events:390:28) at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12) { code: 128 } } Something' s wrong. Maybe you can find the solution here: %s https://hexo.io/docs/troubleshooting.html
那就到切换到该目录下手动操作
1 2 3 4 5 6 7 8 9 10 11 12 13 cd /home/gitlab-runner/builds/xTeKDtDV/0/xplorist/keep/public/git config --global user.email "xplorist163.com" git config --global user.name "xplorist" hexo deploy cp -r /root/.ssh/* /home/gitlab-runner/.sshchmod -R -f 777 /home/gitlab-runner/.sshcp /root/.gitconfig /home/gitlab-runner/.gitconfigchmod -R -f 777 /home/gitlab-runner
如果是Permission denied报错如下:
1 2 3 4 5 Fetching changes with git depth set to 50... Reinitialized existing Git repository in /home/gitlab-runner/builds/xTeKDtDV/0/xplorist/keep/.git/ Checking out 73be115a as main... warning: failed to remove ".deploy_git/2020/12/16/GitLab\344\271\213CI_CD\351\205\215\347\275\256/index.html" : Permission denied warning: failed to remove ".deploy_git/2020/12/18/\351\227\250\346\210\267\347\263\273\347\273\237\344\270\255\347\263\273\347\273\237\347\273\237\350\256\241Matomo\351\205\215\347\275\256/index.html" : Permission denied
执行添加权限
1 2 3 rm -rf /home/gitlab-runner/builds/xTeKDtDV/0/xplorist/keep/.deploy_gitchmod -R -f 777 /home/gitlab-runner/builds/xTeKDtDV/
如果hexo deploy报错,就手动执行调用hexo deploy 进行部署到GitHub上github.io库,生成GitHub pages
1 2 3 4 cd /home/gitlab-runner/builds/y6tSEeXS/0/xplorist/keep/public/hexo deploy
如果rsync Permission denied报错如下:
1 rsync: mkstemp "/usr/share/nginx/html/keep/2020/12/16/GitLab之CI_CD配置/.index.html.rTEdp0" failed: (13)
就手动初始化同步操作
1 2 3 4 5 6 chmod -R -f 777 /usr/share/nginx/html/keep/cd /home/gitlab-runner/builds/xTeKDtDV/0/xplorist/keeprsync -av ./public/ /usr/share/nginx/html/keep/
最后重启gitlab流水线中的job,看命令行结果
将内网GitLab仓库全部更新为公网的远程仓库
内网GitLab服务结束其过渡的使命,正式全面使用公网GitLab服务器
本文标题:Debian11上安装GitLab
本文作者:Xplorist
创建时间:2021-11-10 09:16:00
本文链接:https://xplorist.tech/2021/11/10/f14df2bb3290/
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
$tools-item-width = 2.2rem
$tools-item-font-size = 1.1rem
$tools-item-border-radius = 0.1rem
.side-tools-container {
position relative
.tools-item {
width $tools-item-width
height $tools-item-width
margin-bottom 0.2rem
color var(--default-text-color)
font-size $tools-item-font-size
background var(--background-color)
border-right none
border-radius $tools-item-border-radius
box-shadow 0.1rem 0.1rem 0.2rem var(--shadow-color)
cursor pointer
i {
color var(--default-text-color)
}
&:hover {
color var(--background-color)
background var(--primary-color)
box-shadow 0.2rem 0.2rem 0.4rem var(--shadow-color)
i {
color var(--background-color)
}
}
+keep-tablet() {
width $tools-item-width * 0.9
height $tools-item-width * 0.9
margin-bottom 0.2rem
font-size $tools-item-font-size * 0.9
}
&.rss {
a {
width 100%
height 100%
border-radius $tools-item-border-radius
&:hover {
color var(--background-color)
background var(--primary-color)
box-shadow 0.2rem 0.2rem 0.4rem var(--shadow-color)
}
}
}
}
.side-tools-list {
transform translateX(100%)
opacity 0
transition-t("transform, opacity", "0, 0", "0.2, 0.2", "linear, linear")
.tool-expand-width {
+keep-tablet() {
display none
}
}
&.show {
transform translateX(0)
opacity 1
}
}
.exposed-tools-list {
if (hexo-config('style.scroll.percent.enable') == true) {
.tool-scroll-to-top {
display none
&.show {
display flex
}
&:hover {
.percent {
display none
}
.arrow-up {
display flex
}
}
.arrow-up {
display none
}
.percent {
display flex
font-size 1rem
}
}
}
}
}