如果你使用rpm方式安装gitlab-runner,则可以参考本教程。
卸载
停止和卸载gitlab-runner
停止
gitlab-runner stop
chkconfig gitlab-runner off
卸载
gitlab-runner uninstall
删除rpm包
查询出rpm包名,根据包名删除rpm。
[root@Euler02 ~]# rpm -qa | grep gitlab-runner
gitlab-runner-16.10.0-1.x86_64
[root@Euler02 ~]# rpm -e gitlab-runner-16.10.0-1.x86_64
删除gitlab-runner默认执行用户
userdel -r gitlab-runner
删除相关数据文件
先查出相关目录。
[root@Euler02 ~]# find / -name gitlab-runner
/etc/gitlab-runner
/usr/lib/gitlab-runner
/usr/share/gitlab-runner
逐个删除。最后检查是否有残留。
[root@Euler02 ~]# rm -rf /etc/gitlab-runner/
[root@Euler02 ~]# rm -rf /usr/lib/gitlab-runner/
[root@Euler02 ~]# rm -rf /usr/share/gitlab-runner/
[root@Euler02 ~]# find / -name gitlab-runner
[root@Euler02 ~]# gitlab-runner --version
-bash: /usr/bin/gitlab-runner: No such file or directory
[root@Euler02 ~]#
安装
安装Git
yum install -y git
新增gitlab-runner执行用户
新增之后立刻修改密码。
[root@Euler02 ~]# adduser pablo
[root@Euler02 ~]# passwd pablo
更改用户 pablo 的密码 。
新的密码:
重新输入新的密码:
passwd:所有的身份验证令牌已经成功更新。
[root@Euler02 ~]# ll /home/
总计 7
drwx------ 2 pablo pablo 4096 12月31日 13:23 pablo
赋予sudo权限
[root@Euler02 apache-maven-3.6.3]# vim /etc/sudoers
root ALL=(ALL) ALL
pablo ALL=(ALL) ALL
后续操作登录该用户来完成。
安装jdk
在用户根目录创建software目录,进入software目录再创建java目录。将jdk的压缩包上传到该目录。
[pablo@Euler02 java]$ pwd
/home/pablo/software/java
[pablo@Euler02 java]$ ls
jdk1.8.0_172.tar.gz
解压缩
[pablo@Euler02 java]$ tar -zxvf jdk1.8.0_172.tar.gz
重命名
[pablo@Euler02 java]$ mv jdk1.8.0_172 jdk-8
[pablo@Euler02 java]$ ls
jdk1.8.0_172.tar.gz jdk-8
编辑用户环境变量
[pablo@Euler02 ~]$ cd
[pablo@Euler02 ~]$ vim .bashrc
# Source default setting
[ -f /etc/bashrc ] && . /etc/bashrc# User environment PATH
PATH="$HOME/.local/bin:$HOME/bin:$PATH"
export PATH# JAVA_HOME
export JAVA_HOME=/home/pablo/software/java/jdk-8export PATH=$JAVA_HOME/bin:$PATH
检查
[pablo@Euler02 ~]$ source .bashrc
[pablo@Euler02 ~]$ java -version
java version "1.8.0_172"
Java(TM) SE Runtime Environment (build 1.8.0_172-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.172-b11, mixed mode)
[pablo@Euler02 ~]$ javac -version
javac 1.8.0_172
安装及配置Maven
在software目录创建一个maven目录,把要用的maven版本解压进该目录。本地缓存仓库也可以从Windows端复制到服务器上一份。
[pablo@Euler02 maven]$ pwd
/home/pablo/software/maven
[pablo@Euler02 maven]$ ll
总计 8
drwxr-xr-x 6 pablo pablo 4096 12月30日 12:16 apache-maven-3.6.3
drwxr-xr-x 85 pablo pablo 4096 12月 9日 11:28 repository
配置环境变量
[pablo@Euler02 maven]$ cd
[pablo@Euler02 ~]$ vim .bashrc
# Source default setting
[ -f /etc/bashrc ] && . /etc/bashrc# User environment PATH
PATH="$HOME/.local/bin:$HOME/bin:$PATH"
export PATH# JAVA_HOME
export JAVA_HOME=/home/pablo/software/java/jdk-8# MAVEN_HOME
export MAVEN_HOME=/home/pablo/software/maven/apache-maven-3.6.3
export PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH
检查
[pablo@Euler02 ~]$ source .bashrc
[pablo@Euler02 ~]$ mvn -v
配置maven配置文件
[pablo@Euler02 ~]$ cd software/maven/apache-maven-3.6.3/conf/
[pablo@Euler02 conf]$ ls
logging settings.xml toolchains.xml
修改本地缓存仓库
<localRepository>/home/pablo/software/maven/repository</localRepository>
修改镜像仓库为本地仓库
<mirrors><mirror><id>local</id><mirrorOf>*</mirrorOf><name>local</name><url>file:///home/pablo/software/maven/repository</url></mirror>
</mirrors>
设置jdk版本
<profiles><profile><id>jdk8</id><activation><activeByDefault>true</activeByDefault><jdk>1.8</jdk></activation><properties><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target><maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion></properties></profile>
</profiles><activeProfiles><activeProfile>jdk8</activeProfile></activeProfiles>
下载并安装rpm包
去gitlab-runner的包版本管理官网下载特定的rpm安装包。我使用的是 openEuler24的操作系统,下载了el9-x86_64的版本。gitlab版本为15.6.2的社区版,因此gitlab-runner也要下载对应的版本。
[pablo@Euler02 gitlab-runner]$ pwd
/home/pablo/software/gitlab-runner
[pablo@Euler02 gitlab-runner]$ ls
gitlab-runner-15.6.2-1.x86_64.rpm
[pablo@Euler02 gitlab-runner]$ sudo rpm -ivh gitlab-runner-15.6.2-1.x86_64.rpm --nodeps --force
警告:gitlab-runner-15.6.2-1.x86_64.rpm: 头 V4 RSA/SHA512 Signature, 密钥 ID 35dfa027: NOKEY
Verifying... ################################# [100%]
准备中... ################################# [100%]
正在升级/安装...1:gitlab-runner-15.6.2-1 ################################# [100%]
GitLab Runner: creating gitlab-runner...
Home directory skeleton not used
Runtime platform arch=amd64 os=linux pid=13528 revision=c081f284 version=15.6.2
gitlab-runner: the service is not installed
Runtime platform arch=amd64 os=linux pid=13561 revision=c081f284 version=15.6.2
gitlab-ci-multi-runner: the service is not installed
Runtime platform arch=amd64 os=linux pid=13586 revision=c081f284 version=15.6.2
Runtime platform arch=amd64 os=linux pid=13648 revision=c081f284 version=15.6.2
INFO: Docker installation not found, skipping clear-docker-cache
设置权限
赋予可执行权限、设置执行用户、设置工作目录、设置开机自启动。
[pablo@Euler02 gitlab-runner]$ which gitlab-runner
/usr/bin/gitlab-runner
[pablo@Euler02 gitlab-runner]$ sudo chmod +x /usr/bin/gitlab-runner
[pablo@Euler02 gitlab-runner]$ sudo gitlab-runner uninstall
Runtime platform arch=amd64 os=linux pid=23415 revision=c081f284 version=15.6.2
[pablo@Euler02 gitlab-runner]$ sudo gitlab-runner install --working-directory=/home/pablo/software/gitlab-runner --user=pablo
Runtime platform arch=amd64 os=linux pid=29271 revision=c081f284 version=15.6.2
[pablo@Euler02 gitlab-runner]$ sudo systemctl daemon-reload
[pablo@Euler02 gitlab-runner]$ sudo systemctl start gitlab-runner
[pablo@Euler02 gitlab-runner]$ sudo systemctl enable gitlab-runner
[pablo@Euler02 gitlab-runner]$ sudo gitlab-runner restart
Runtime platform arch=amd64 os=linux pid=33472 revision=c081f284 version=15.6.2
注册
在gitlab的web端找到你的admin area管理空间,不同版本位置不一样,我就不细说了。选择注册一个runner实例,选择好环境和架构,复制注册命令。
sudo gitlab-runner register --url http://192.168.213.130/ --registration-token ssyzyyydEXSg6sBuYR9e
将这条命令复制到gitlab-runner 的机器上运行。
核心的就三个,一个是输入正确的URL,注意端口号。第二个就是 tags,将来,作业会根据tags来选择使用哪个runner实例。最后是选择shell为执行方式。
[pablo@Euler02 ~]$ sudo gitlab-runner register --url http://192.168.213.130:9980/ --registration-token ssyzyyydEXSg6sBuYR9e
[sudo] pablo 的密码:
Runtime platform arch=amd64 os=linux pid=44375 revision=c081f284 version=15.6.2
WARNING: The 'register' command has been deprecated in GitLab Runner 15.6 and will be replaced with a 'deploy' command. For more information, see https://gitlab.com/gitlab-org/gitlab/-/issues/380872
Running in system-mode. Enter the GitLab instance URL (for example, https://gitlab.com/):
[http://192.168.213.130:9980/]:
Enter the registration token:
[ssyzyyydEXSg6sBuYR9e]:
Enter a description for the runner:
[Euler02]:
Enter tags for the runner (comma-separated):
build
Enter optional maintenance note for the runner:Registering runner... succeeded runner=ssyzyyyd
Enter an executor: docker+machine, custom, docker-ssh, shell, ssh, virtualbox, docker-ssh+machine, instance, kubernetes, docker, parallels:
shell
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!Configuration (with the authentication token) was saved in "/etc/gitlab-runner/config.toml"
注册成功之后,可以在界面中看到runner实例。