网监备案网站更换域名,网站后台psd,c 博客网站开发教程,新乡网站建设哪家实力强文章目录 DevOpsDevOps概述Code阶段工具#xff08;centos7-gitlab主机#xff09;Windows下安装Git#xff08;作用是#xff1a;使我们可以上传代码到GitLab#xff09;Linux下安装GitLab⭐#xff08;作用是#xff1a;运行一个GitLab接收代码#xff09;环境准备先… 文章目录 DevOpsDevOps概述Code阶段工具centos7-gitlab主机Windows下安装Git作用是使我们可以上传代码到GitLabLinux下安装GitLab⭐作用是运行一个GitLab接收代码环境准备先创建新的虚拟机centos7-gitlab⭐修改IP和主机名关闭防火墙安装Docker安装Docker Compose 使用Docker安装GitLab Build阶段工具centos7-jenkins主机Linux下安装Maven项目构建工具⭐环境准备先创建新的虚拟机centos7-jenkins⭐修改IP和主机名关闭防火墙 安装Maven下载Maven和JDK8的tar.gz包将Maven和JDK8的tar.gz包上传到centos7-jenkins的/root目录上 Operate阶段工具centos7-jenkins主机Linux下安装Docker和Docker-Compose⭐安装Docker安装Docker Compose DevOps
DevOps概述
软件开发最初是由两个团队共同组成没有采用DevOps之前
开发团队从头开始设计和整体系统的构建编写代码。需要系统不停的迭代更新。运维团队将开发团队的代码进行测试通过后再部署上线。确保系统稳定运行。
没有采用DevOps的缺点
这看似两个目标不同的团队需要协同完成一个软件的开发。在开发团队指定好计划并完成编写代码后需要把代码交给运维团队。运维团队向开发团队反馈需要修复的BUG以及一些需要返工的任务。这时开发团队需要经常等待运维团队的反馈。这无疑会延长整个软件开发的周期。
采用DevOps的优点
DevOps的方式可以让公司能够更快地应对更新和市场发展变化开发可以快速交付部署也更加稳定。核心就在于简化Dev和Ops团队之间的流程使整体软件开发过程更快速。说白了就是DevOps有利于快速完成项目不会浪费时间
整体的软件开发流程
PLAN开发团队根据客户的目标制定开发计划CODE根据PLAN开始编码过程需要将不同版本的代码存储在一个库中。BUILD编码完成后需要将代码构建并且运行。TEST成功构建项目后需要测试代码是否存在BUG或错误。DEPLOY代码经过手动测试和自动化测试后认定代码已经准备好部署并且交给运维团队。OPERATE运维团队将代码部署到生产环境中。MONITOR项目部署上线后需要持续的监控产品。INTEGRATE然后将监控阶段收到的反馈发送回PLAN阶段整体反复的流程就是DevOps的核心即持续集成、持续部署。
为了保证整体流程可以高效的完成各个阶段都有比较常见的工具如下图
Code阶段工具centos7-gitlab主机
在code阶段我们需要将不同版本tag的代码存储到一个远程仓库中常见的版本控制工具就是SVN或者Git这里我们采用Git作为版本控制工具GitLab作为远程仓库。GitHub和Gitee都可以不过生产上用GitLab更多 Code阶段步骤 在Windows环境下编写好代码然后将代码上传到Linux环境下的GitLab上。 Windows下安装Git作用是使我们可以上传代码到GitLab
进入Git官网安装Git到Windows环境下即可。很简单
Linux下安装GitLab⭐作用是运行一个GitLab接收代码 步骤 1新建一个服务器2核4G内存60G硬盘IP设置成192.168.184.70主机名设置成centos7-gitlab专门用来运行GitLab。 2安装Docker容器。如果已经安装过了就可以跳过这一步 3在这台新的GitLab的服务器上使用Docker的方式运行GitLab。 环境准备
先创建新的虚拟机centos7-gitlab⭐
创建新的虚拟机过程省略
修改IP和主机名
1新建服务器并将其IP地址修改成192.168.184.70
vi /etc/sysconfig/network-scripts/ifcfg-ens33找到 IPADDR 字段并将IP修改成192.168.184.70即可
然后重启网络
systemctl restart network查看IP是否修改成功可以看到ens33已经修改成功了。
[rootcentos7-clear ~]# ifconfig
ens33: flags4163UP,BROADCAST,RUNNING,MULTICAST mtu 1500inet 192.168.184.70 netmask 255.255.255.0 broadcast 192.168.184.255inet6 fe80::9ce3:a607:cc1b:e87 prefixlen 64 scopeid 0x20linkether 00:0c:29:f5:97:d0 txqueuelen 1000 (Ethernet)RX packets 550 bytes 56363 (55.0 KiB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 487 bytes 71677 (69.9 KiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0lo: flags73UP,LOOPBACK,RUNNING mtu 65536inet 127.0.0.1 netmask 255.0.0.0inet6 ::1 prefixlen 128 scopeid 0x10hostloop txqueuelen 1000 (Local Loopback)RX packets 0 bytes 0 (0.0 B)RX errors 0 dropped 0 overruns 0 frame 0TX packets 0 bytes 0 (0.0 B)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 02修改服务器的主机名
hostnamectl set-hostname centos7-gitlab关闭防火墙
systemctl stop firewalld
systemctl disable firewalld安装Docker
1切换镜像源
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo2安装特定版本的docker-ce
yum -y install docker-ce-3:20.10.8-3.el7.x86_64 docker-ce-cli-3:20.10.8-3.el7.x86_64 containerd.io3给Docker接入阿里云镜像加速器
配置镜像加速器方法。
准备工作1首先进入阿里云容器镜像服务 https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors2点击镜像工具下面的镜像加速器3拿到你的加速器地址和下面第二步的registry-mirrors的值替换即可。
针对Docker客户端版本大于 1.10.0 的用户可以通过修改daemon配置文件/etc/docker/daemon.json来使用加速器
第一步
mkdir -p /etc/docker第二步
cat EOF /etc/docker/daemon.json
{exec-opts: [native.cgroupdriversystemd], registry-mirrors: [https://u01jo9qv.mirror.aliyuncs.com,https://hub-mirror.c.163.com,https://mirror.baidubce.com],live-restore: true,log-driver:json-file,log-opts: {max-size:500m, max-file:3},max-concurrent-downloads: 10,max-concurrent-uploads: 5,storage-driver: overlay2
}
EOF第三步
sudo systemctl daemon-reload第四步
sudo systemctl restart docker最后就接入阿里云容器镜像加速器成功啦。
4设置Docker开机自动启动
[rootcentos7-clear ~]# sudo systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.安装Docker Compose
1拉取docker-compose
curl -L https://get.daocloud.io/docker/compose/releases/download/v2.4.1/docker-compose-uname -s-uname -m /usr/local/bin/docker-compose2给docker-compose分配权限
chmod x /usr/local/bin/docker-compose3查看docker-compose的版本
docker-compose --version使用Docker安装GitLab
1查看gitlab镜像
[rootcentos7-clear ~]# docker search gitlab-ce
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
gitlab/gitlab-ce GitLab Community Edition docker image based … 3642 [OK]2拉取最新版的gitlab镜像gitlab的镜像十分大2个多GB的大小
[rootcentos7-gitlab gitlab]# docker pull gitlab/gitlab-ce:latest
latest: Pulling from gitlab/gitlab-ce
7b1a6ab2e44d: Pull complete
6c37b8f20a77: Pull complete
f50912690f18: Pull complete
bb6bfd78fa06: Pull complete
2c03ae575fcd: Pull complete
839c111a7d43: Pull complete
4989fee924bc: Pull complete
666a7fb30a46: Pull complete
Digest: sha256:5a0b03f09ab2f2634ecc6bfeb41521d19329cf4c9bbf330227117c048e7b5163
Status: Downloaded newer image for gitlab/gitlab-ce:latest
docker.io/gitlab/gitlab-ce:latest3查看gitlab的镜像是否拉取成功
[rootcentos7-gitlab gitlab]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
gitlab/gitlab-ce latest 46cd6954564a 6 months ago 2.36GB4准备docker-compose.yml文件
创建文件夹
[rootcentos7-clear ~]# mkdir gitlab cd gitlab创建文件
vi docker-compose.yml文件内容如下记得修改external_url的ip地址为你的gitlab的服务器地址我们的是192.168.184.70
version: 3.1
services:gitlab:image: gitlab/gitlab-ce:latestcontainer_name: gitlabrestart: alwaysenvironment:GITLAB_OMNIBUS_CONFIG: |external_url http://192.168.184.70:8929gitlab_rails[gitlab_shell_ssh_port] 2224ports:- 8929:8929- 2224:2224volumes:- ./config:/etc/gitlab- ./logs:/var/log/gitlab- ./data:/var/opt/gitlab5执行docker-compose配置文件执行完需要等待
[rootcentos7-gitlab gitlab]# docker-compose up -d6访问GitLab首页 网址是 192.168.184.70:8929 7查看root用户初始密码下面password就是我们的默认密码
[rootcentos7-gitlab gitlab]# docker exec -it gitlab cat /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: 6PHFewZSOcvt5rQD65mlCP5Tr5i8MRYTadwa3VGvkPo# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.8返回刚刚的登陆界面登陆gitlab 9登陆gitlab成功后的首页 10修改gitlab密码然后重新登陆即可我修改成root123456 Build阶段工具centos7-jenkins主机
构建Java项目的工具一般有两种选择一个是Maven一个是Gradle。这里我们选择Maven作为项目的编译工具。
Linux下安装Maven项目构建工具⭐ 步骤 1新建一个服务器2核4G内存60G硬盘IP设置成192.168.184.80主机名设置成centos7-jenkins。 2安装Docker容器。如果已经安装过了就可以跳过这一步 环境准备
先创建新的虚拟机centos7-jenkins⭐
创建新的虚拟机过程省略
修改IP和主机名
1新建服务器并将其IP地址修改成192.168.184.80
vi /etc/sysconfig/network-scripts/ifcfg-ens33找到 IPADDR 字段并将IP修改成192.168.184.80即可
然后重启网络
systemctl restart network查看IP是否修改成功可以看到ens33已经修改成功了。
[rootcentos7-clear ~]# ifconfig
ens33: flags4163UP,BROADCAST,RUNNING,MULTICAST mtu 1500inet 192.168.184.80 netmask 255.255.255.0 broadcast 192.168.184.255inet6 fe80::9aa7:2f1d:4559:d9c8 prefixlen 64 scopeid 0x20linkether 00:0c:29:63:69:7f txqueuelen 1000 (Ethernet)RX packets 136 bytes 17161 (16.7 KiB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 157 bytes 20956 (20.4 KiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0lo: flags73UP,LOOPBACK,RUNNING mtu 65536inet 127.0.0.1 netmask 255.0.0.0inet6 ::1 prefixlen 128 scopeid 0x10hostloop txqueuelen 1000 (Local Loopback)RX packets 0 bytes 0 (0.0 B)RX errors 0 dropped 0 overruns 0 frame 0TX packets 0 bytes 0 (0.0 B)TX2修改服务器的主机名
hostnamectl set-hostname centos7-jenkins关闭防火墙
systemctl stop firewalld
systemctl disable firewalld安装Maven
下载Maven和JDK8的tar.gz包 将Maven和JDK8的tar.gz包上传到centos7-jenkins的/root目录上
1查看当前目录
[rootcentos7-jenkins ~]# pwd
/root2使用XFTP把刚刚下载好的两个包上传上去 3查看上传好的包
[rootcentos7-jenkins ~]# ls
anaconda-ks.cfg apache-maven-3.8.6-bin.tar.gz jdk-8u333-linux-x64.tar.gz4解压JDK包到/usr/local
tar -zxvf jdk-8u333-linux-x64.tar.gz -C /usr/local5解压Maven包到/usr/local
tar -zxvf apache-maven-3.8.6-bin.tar.gz -C /usr/local6切换到/usr/local目录下
cd /usr/local7给JDK和Maven的文件夹进行改名
mv jdk1.8.0_333 jdkmv apache-maven-3.8.6 maven8查看/usr/local
[rootcentos7-jenkins local]# ls
bin etc games include jdk lib lib64 libexec maven sbin share src9修改Maven配置文件配置阿里云镜像加速和JDK8设置1阿里云镜像加速配置
cd maven/conf[rootcentos7-jenkins conf]# vi settings.xml插入内容如下插入到/ mirrors 这个标签上面即可先不用保存退出
mirroridnexus-aliyun/idmirrorOfcentral/mirrorOfnameNexus aliyun/nameurlhttp://maven.aliyun.com/nexus/content/groups/public/url
/mirror2JDK8设置
插入内容如下插入到 /profiles 标签上面即可
profileidjdk8/idactivationactiveByDefaulttrue/activeByDefaultjdk1.8/jdk/activationpropertiesmaven.compiler.source1.8/maven.compiler.sourcemaven.compiler.target1.8/maven.compiler.targetmaven.compiler.compilerVersion1.8/maven.compiler.compilerVersion/properties
/profile并插入如下内容用于开启上面的jdk配置插入到最下面的 /settings 标签上面即可然后保存退出
activeProfilesactiveProfilejdk8/activeProfile
/activeProfilesOperate阶段工具centos7-jenkins主机
Linux下安装Docker和Docker-Compose⭐
安装Docker
1切换镜像源
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo2安装特定版本的docker-ce
yum -y install docker-ce-3:20.10.8-3.el7.x86_64 docker-ce-cli-3:20.10.8-3.el7.x86_64 containerd.io3给Docker接入阿里云镜像加速器
配置镜像加速器方法。
准备工作1首先进入阿里云容器镜像服务 https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors2点击镜像工具下面的镜像加速器3拿到你的加速器地址和下面第二步的registry-mirrors的值替换即可。
针对Docker客户端版本大于 1.10.0 的用户可以通过修改daemon配置文件/etc/docker/daemon.json来使用加速器
第一步
mkdir -p /etc/docker第二步
cat EOF /etc/docker/daemon.json
{exec-opts: [native.cgroupdriversystemd], registry-mirrors: [https://u01jo9qv.mirror.aliyuncs.com,https://hub-mirror.c.163.com,https://mirror.baidubce.com],live-restore: true,log-driver:json-file,log-opts: {max-size:500m, max-file:3},max-concurrent-downloads: 10,max-concurrent-uploads: 5,storage-driver: overlay2
}
EOF第三步
sudo systemctl daemon-reload第四步
sudo systemctl restart docker最后就接入阿里云容器镜像加速器成功啦。
4设置Docker开机自动启动
sudo systemctl enable docker安装Docker Compose
1拉取docker-compose
curl -L https://get.daocloud.io/docker/compose/releases/download/v2.4.1/docker-compose-uname -s-uname -m /usr/local/bin/docker-compose2给docker-compose分配权限
chmod x /usr/local/bin/docker-compose3查看docker-compose的版本
[rootcentos7-jenkins conf]# docker-compose --version
Docker Compose version v2.4.1