【Jenkins】入门学习1. 相关文档1.1 Docker安装1.2 插件源换成清华源1.2.1 方式一Web 页面直接修改优先最简单1.2.2 方式二容器内 sed 批量替换根治推荐给 docker 部署1.2.3 方式三初始化卡住的时候还没进后台2.Docker部署GitLab3. Jenkins拉代码Docker部署1. 相关文档Jenkins docker hub https://hub.docker.com/r/jenkins/jenkins?taglatest-jdk21网友有关Jenkins的文档 https://gitee.com/liu_guo_feng/notes/blob/master/服务器/linux/jenkins/安装jenkins.mdjenkins安装及国内源配置 https://www.cnblogs.com/yw0219/p/18734501docker源的配置vim/etc/docker/daemon.json{experimental:false,registry-mirrors:[https://9migda19.mirror.aliyuncs.com,https://mirror.ccs.tencentyun.com,https://docker.1panel.live],builder:{gc:{enabled:true,defaultKeepStorage:20GB}}}1.1 Docker安装腾讯云 Docker 容器用户使用指南 https://cloud.tencent.com/document/product/1397/110965[rootVM-0-17-centos ~]# docker pull jenkins/jenkins:latest-jdk21# 1. 创建数据目录 权限jenkins容器内用户uid1000mkdir-p/data/jenkins_homechown-R1000:1000 /data/jenkins_home# 2. 启动jenkins直接用jenkins:latest-jdk21镜像dockerrun-d\--namejenkins\--restartalways\-p8080:8080\-p50000:50000\-eTZAsia/Shanghai\-eJAVA_OPTS-Xmx1536m -Xms512m\-v/data/jenkins_home:/var/jenkins_home\-v/var/run/docker.sock:/var/run/docker.sock\jenkins/jenkins:latest-jdk21⭐ 重点加了-Xmx1536m限制最大堆内存 1.5G防止 Jenkins 把你仅剩内存吃光、OOM 崩溃适配你的 3.6G 内存机器启动后操作# 看容器是否起来dockerps# 获取初始管理员密码dockerexecjenkinscat/var/jenkins_home/secrets/initialAdminPassword浏览器访问http://你的公网IP:80801.2 插件源换成清华源1.2.1 方式一Web 页面直接修改优先最简单https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json1.2.2 方式二容器内 sed 批量替换根治推荐给 docker 部署sed -i s#https://updates.jenkins.io/download#https://mirrors.tuna.tsinghua.edu.cn/jenkins#g /data/jenkins_home/updates/default.json1.2.3 方式三初始化卡住的时候还没进后台vim/data/jenkins_home/hudson.model.UpdateCenter.xmlurlhttps://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json/url2.Docker部署GitLab# 停止并删除当前异常gitlabdockerstop gitlabdockerrmgitlab# 清理旧目录旧配置已经错乱必须删rm-rf/data/gitlabmkdir-p/data/gitlab/{config,logs,data}# 全新启动命令dockerrun-d\--namegitlab\--restartalways\-p8090:80\-p8443:443\-p2222:22\--shm-size 1g\-eTZAsia/Shanghai\-eGITLAB_OMNIBUS_CONFIGexternal_url http://192.168.1.13; gitlab_rails[gitlab_shell_ssh_port] 2222; nginx[listen_https] false; nginx[redirect_http_to_https] false;\-v/data/gitlab/config:/etc/gitlab\-v/data/gitlab/logs:/var/log/gitlab\-v/data/gitlab/data:/var/opt/gitlab\registry.gitlab.cn/omnibus/gitlab-jh:17.7.0-jh.0启动后等待6~10 分钟让它 reconfigure 完成、变成 healthy。等就绪后测试# 进入容器内部测试dockerexec-itgitlabcurl-I127.0.0.1这条返回 200就正常了。然后宿主机curl-I127.0.0.1:8090访问地址依旧是http://192.168.1.13:8090GitLab 内部会自动补全端口clone 地址自动带上8090不用担心。root 账号密码登录⚡ rootnode1 ~ dockerexecgitlabcat/etc/gitlab/initial_root_password# WARNING: This value is valid only in the following conditions# 1. If provided manually (either via GITLAB_ROOT_PASSWORD environment variable or via gitlab_rails[initial_root_password] setting in gitlab.rb, it was provided before database was seeded for the first time (usually, the first reconfigure run).# 2. Password hasnt been changed manually, either via UI or via command line.## If the password shown here doesnt work, you must reset the admin password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.Password: h24EzjCJ7kZZEoJH8LKeMmapLqKNgLR4/81obBNLnY# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.3. Jenkins拉代码Docker部署