文章目录

DevOpsDevOps概述Code阶段工具(centos7-gitlab主机)Windows下安装Git(作用是:使我们可以上传代码到GitLab)Linux下安装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已经修改成功了。)

[root@centos7-clear ~]# ifconfig

ens33: flags=4163 mtu 1500

inet 192.168.184.70 netmask 255.255.255.0 broadcast 192.168.184.255

inet6 fe80::9ce3:a607:cc1b:e87 prefixlen 64 scopeid 0x20

ether 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 0

TX packets 487 bytes 71677 (69.9 KiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73 mtu 65536

inet 127.0.0.1 netmask 255.0.0.0

inet6 ::1 prefixlen 128 scopeid 0x10

loop txqueuelen 1000 (Local Loopback)

RX packets 0 bytes 0 (0.0 B)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 0 bytes 0 (0.0 B)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

2:修改服务器的主机名:

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.repo

2:安装特定版本的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.io

3:给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 < /etc/docker/daemon.json

{

"exec-opts": ["native.cgroupdriver=systemd"],

"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开机自动启动:

[root@centos7-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-compose

2:给docker-compose分配权限:

chmod +x /usr/local/bin/docker-compose

3:查看docker-compose的版本:

docker-compose --version

使用Docker安装GitLab

1:查看gitlab镜像:

[root@centos7-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的大小)

[root@centos7-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:latest

3:查看gitlab的镜像是否拉取成功:

[root@centos7-gitlab gitlab]# docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

gitlab/gitlab-ce latest 46cd6954564a 6 months ago 2.36GB

4:准备docker-compose.yml文件:

创建文件夹:

[root@centos7-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:latest'

container_name: gitlab

restart: always

environment:

GITLAB_OMNIBUS_CONFIG: |

external_url 'http://192.168.184.70:8929'

gitlab_rails['gitlab_shell_ssh_port'] = 2224

ports:

- '8929:8929'

- '2224:2224'

volumes:

- './config:/etc/gitlab'

- './logs:/var/log/gitlab'

- './data:/var/opt/gitlab'

5:执行docker-compose配置文件:(执行完需要等待)

[root@centos7-gitlab gitlab]# docker-compose up -d

6:访问GitLab首页:

网址是 192.168.184.70:8929

7:查看root用户初始密码:(下面password就是我们的默认密码)

[root@centos7-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 hasn't been changed manually, either via UI or via command line.

#

# If the password shown here doesn't 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已经修改成功了。)

[root@centos7-clear ~]# ifconfig

ens33: flags=4163 mtu 1500

inet 192.168.184.80 netmask 255.255.255.0 broadcast 192.168.184.255

inet6 fe80::9aa7:2f1d:4559:d9c8 prefixlen 64 scopeid 0x20

ether 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 0

TX packets 157 bytes 20956 (20.4 KiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73 mtu 65536

inet 127.0.0.1 netmask 255.0.0.0

inet6 ::1 prefixlen 128 scopeid 0x10

loop txqueuelen 1000 (Local Loopback)

RX packets 0 bytes 0 (0.0 B)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 0 bytes 0 (0.0 B)

TX

2:修改服务器的主机名:

hostnamectl set-hostname centos7-jenkins

关闭防火墙

systemctl stop firewalld

systemctl disable firewalld

安装Maven

下载Maven和JDK8的tar.gz包

将Maven和JDK8的tar.gz包上传到centos7-jenkins的/root目录上

1:查看当前目录:

[root@centos7-jenkins ~]# pwd

/root

2:使用XFTP把刚刚下载好的两个包上传上去: 3:查看上传好的包:

[root@centos7-jenkins ~]# ls

anaconda-ks.cfg apache-maven-3.8.6-bin.tar.gz jdk-8u333-linux-x64.tar.gz

4:解压JDK包到/usr/local:

tar -zxvf jdk-8u333-linux-x64.tar.gz -C /usr/local

5:解压Maven包到/usr/local:

tar -zxvf apache-maven-3.8.6-bin.tar.gz -C /usr/local

6:切换到/usr/local目录下:

cd /usr/local

7:给JDK和Maven的文件夹进行改名:

mv jdk1.8.0_333 jdk

mv apache-maven-3.8.6 maven

8:查看/usr/local:

[root@centos7-jenkins local]# ls

bin etc games include jdk lib lib64 libexec maven sbin share src

9:修改Maven配置文件:(配置阿里云镜像加速和JDK8设置)(1)阿里云镜像加速配置:

cd maven/conf

[root@centos7-jenkins conf]# vi settings.xml

插入内容如下:(插入到 这个标签上面即可),先不用保存退出

nexus-aliyun

central

Nexus aliyun

http://maven.aliyun.com/nexus/content/groups/public

(2)JDK8设置:

插入内容如下:(插入到 < /profiles > 标签上面即可)

jdk8

true

1.8

1.8

1.8

1.8

并插入如下内容:(用于开启上面的jdk配置,插入到最下面的< /settings >标签上面即可),然后保存退出

jdk8

Operate阶段工具(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.repo

2:安装特定版本的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.io

3:给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 < /etc/docker/daemon.json

{

"exec-opts": ["native.cgroupdriver=systemd"],

"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-compose

2:给docker-compose分配权限:

chmod +x /usr/local/bin/docker-compose

3:查看docker-compose的版本:

[root@centos7-jenkins conf]# docker-compose --version

Docker Compose version v2.4.1

推荐链接

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: