持续集成概念

  1. 持续集成Continuous Integration
  2. 持续交付Continuous Delivery
  3. 持续部署Continuous Deployment

1.1 什么是持续集成:

 

1.3 什么是持续交付:

 

1.4 持续部署:

1.5 部署代码上线流程

  1. 代码获取(直接了拉取)
  2. 编译 (可选)
  3. 配置文件放进去
  4. 打包
  5. scp到目标服务器
  6. 将目标服务器移除集群
  7. 解压并放置到Webroot
  8. Scp 差异文件
  9. 重启 (可选)
  10. 测试
  11. 加入集群

运维必知OWASP

https://www.owasp.org/index.php/Top_10_2013-Top_10

Gitlab介绍

 
  GitLab拥有与Github类似的功能,能够浏览源代码,管理缺陷和注释。可以管理团队对仓库的访问,它非常易于浏览提交过的版本并提供一个文件历史库。它还提供一个代码片段收集功能可以轻松实现代码复用,便于日后有需要的时候进行查找。

环境准备

[root@linux-node1 ~]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
[root@linux-node1 ~]# uname -r
3.10.0-514.2.2.el7.x86_64
下载epel源
[root@linux-node1 ~]# wget http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
[root@linux-node1 ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
关闭 NetworkManager 和防火墙
[root@linux-node1 ~]#systemctl stop firewalld.service
systemctl disable firewalld
systemctl disable NetworkManager
关闭SELinux并确认处于关闭状态
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
grep SELINUX=disabled /etc/selinux/config
setenforce 0
更新系统并重启
[root@linux-node1 ~]# yum update -y && reboot

我们一共有2台:192.168.56.11192.168.56.12我们安装在192.168.56.11上

[root@linux-node1 /]# yum install curl policycoreutils openssh-server openssh-clients postfix -y
[root@linux-node1 /]# systemctl start postfix
[root@linux-node1 /]# curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
[root@linux-node1 /]# yum install -y gitlab-ce

#由于网络问题,国内用户,建议使用清华大学的镜像源进行安装

[root@linux-node1 ~]# cat /etc/yum.repos.d/gitlab-ce.repo
[gitlab-ce]
name=gitlab-ce
baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7
repo_gpgcheck=0
gpgcheck=0
enabled=1
gpgkey=https://packages.gitlab.com/gpg.key
[root@linux-node1 ~]# yum makecache
[root@linux-node1 /]# yum install -y gitlab-ce

在安装一个git客户端

[root@linux-node1 /]# yum install -y git

配置并启动gitlab-ce

[root@linux-node1 ~]# gitlab-ctl reconfigure
#时间可能比较长,耐心你等待即可!----
gitlab常用命令:
关闭gitlab:[root@linux-node2 ~]# gitlab-ctl stop
启动gitlab:[root@linux-node2 ~]# gitlab-ctl start
重启gitlab:[root@linux-node2 ~]# gitlab-ctl restart
重载配置文件: gitlab-ctl reconfigure

可以使用gitlab-ctl管理gitlab,例如查看gitlab状态:

[root@linux-node1 /]# gitlab-ctl status
run: gitlab-workhorse: (pid 7437) 324s; run: log: (pid 7436) 324s
run: logrotate: (pid 7452) 316s; run: log: (pid 7451) 316s
run: nginx: (pid 8168) 2s; run: log: (pid 7442) 318s
run: postgresql: (pid 7293) 363s; run: log: (pid 7292) 363s
run: redis: (pid 7210) 369s; run: log: (pid 7209) 369s
run: sidekiq: (pid 7479) 265s; run: log: (pid 7426) 326s
run: unicorn: (pid 7396) 327s; run: log: (pid 7395) 327s

 我们要保证80端口不被占用

我们可以查看一下端口

[root@linux-node1 /]# gitlab-ctl restart
ok: run: gitlab-workhorse: (pid 8353) 0s
ok: run: logrotate: (pid 8360) 1s
ok: run: nginx: (pid 8367) 0s
timeout: down: postgresql: 0s, normally up, want up
ok: run: redis: (pid 8437) 0s
ok: run: sidekiq: (pid 8445) 0s
ok: run: unicorn: (pid 8450) 0s
[root@linux-node1 /]# lsof -i:80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 8367 root 7u IPv4 54972 0t0 TCP *:http (LISTEN)
nginx 8368 gitlab-www 7u IPv4 54972 0t0 TCP *:http (LISTEN)

提示:启动gitlab需要时间!

Web页面提示我们需要设置一个账号密码(我们要设置最少8位数的一个账号密码)我们设置密码为:12345678


我们点击右上角管理区域

提示:Save在页面最下放!!!!!! 记得点保存!!!!!!!!!!!!

现在在查看首页就没有注册页面了

第二步:我们创建一个用户,在创建一个项目

点击下方Create group

然后我们在组里面创建项目

创建完成之后它提示我们可以创建一个key对它进行管理


填写完成我们点击前面进行查看

我们要做免密验证,现在去192.168.56.11复制下面的.ssh/id_rsa.pub

[www@linux-node1 ~]$ cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC8wfTSQcSyhlsGYDSUtuxZNb1Gl3VU56nAPuxAEF2wP2ZWZ2yva354ZdKOOb6rZx2yZxqy5XIj7opBJPbhraXap+NtCH5qWyktR7dH19RBmCS7vUGgvk/5RQC0mVFrC8cztBp0M/5HxMuhVir6mD1rhbDvvaLL6S5y4gljzC1Gr2VRHIb4Et9go/38c2tqMjYCike7WWbFRyL9wTal6/146+9uREZ/r69TBTKrGuRqF44fROQP8/ly02XFjlXyl6J5NnGTk6AU855pwasX0W9aNPce3Ynrpe1TBTubmfQhrH1BwteEmg+ZXNRupxjumA+tPWfBUX+u51r/w7W/d4PD www@linux-node1
#提示:需要提前做秘钥认证

点击Projects 选择SSH,我们要将代码拉去下来

[www@linux-node1 ~]$ cd /deploy/code/
[www@linux-node1 code]$ ls
web-demo
[www@linux-node1 code]$ rm -rf web-demo/
[www@linux-node1 ~]$ git clone git@linux-node1:web/web-demo.git
Cloning into 'web-demo'...
The authenticity of host 'linux-node1 (192.168.56.11)' can't be established.
ECDSA key fingerprint is b5:74:8f:f1:03:2d:cb:7d:01:28:30:12:34:9c:35:8c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'linux-node1' (ECDSA) to the list of known hosts.
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
[www@linux-node1 ~]$ ls web-demo/
README.md
#git clone是克隆的意思

我们来模拟开发继续写代码提交

[www@linux-node1 ~]$ mkdir -p /web-demo
[www@linux-node1 ~]$ vim web-demo/index.html
[www@linux-node1 ~]$ cd web-demo/
[www@linux-node1 web-demo]$
[www@linux-node1 web-demo]$ ls
index.html README.md
[www@linux-node1 web-demo]$ git add *
[www@linux-node1 web-demo]$ git commit -m "add index.html"
*** 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: empty ident name (for <www@linux-node1.(none)>) not allowed

需要身份验证:

[www@linux-node1 web-demo]$ git config --global user.email "you@example.com"
[www@linux-node1 web-demo]$ git config --global user.name "Your Name"
[www@linux-node1 web-demo]$ git commit -m "add index.html"
[master be8a547] add index.html
1 file changed, 169 insertions(+)
create mode 100644 index.html

git push命令用于将本地分支的更新,推送到远程主机。它的格式与git pull命令相仿。

[www@linux-node1 web-demo]$ git push
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:
git config --global push.default matching
To squelch this message and adopt the new behavior now, use:
git config --global push.default simple
See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 7.66 KiB | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@linux-node1:web/web-demo.git
0c1d357..be8a547 master -> master


#现在git 需要加上主机名,我们可以修改配置文件,让它使用IP进行访问

编辑配置文件

[root@linux-node1 ~]# vim /etc/gitlab/gitlab.rb
external_url 'http://192.168.56.11'
[root@linux-node1 ~]# gitlab-ctl reconfigure
#提示:修改完需要使用reconfigure重载配置才会生效


咦! 为啥还没改呢! 我们从新创建一个项目在试一下

廖雪峰Git

自动化运维之DevOps

 
  它的出现是由于软件行业日益清晰地认识到:为了按时交付软件产品和服务,开发和运营工作必须紧密合作

简单的来说DevOps是一种文化,是让开发开发、运维、测试能够之间沟通和交流

 
  如果运维对git不熟,是无法做自动化部署。因为所有的项目都受制于开发

Jenkins 介绍

 
Hudson是Jenkins的前身,是基于Java开发的一种持续集成工具,用于监控程序重复的工作,Hudson后来被收购,成为商业版。后来创始人又写了一个jenkins,jenkins在功能上远远超过hudson

https://jenkins.io/

 
  Jenkins是Java编写的,所以需要先安装JDK,这里采用yum安装,如果对版本有需求,可以直接在Oracle官网下载JDK。

[root@linux-node1 ~]# yum install -y java-1.8.0

安装jenkins

[root@linux-node1 ~]# cd /etc/yum.repos.d/
[root@linux-node1 yum.repos.d]# wget http://pkg.jenkins.io/redhat/jenkins.repo
[root@linux-node1 ~]# rpm --import http://pkg.jenkins.io/redhat/jenkins.io.key
[root@linux-node1 ~]# yum install -y jenkins
[root@linux-node1 ~]# systemctl start jenkins
#本文使用yum进行安装,大家也可以使用编译安装。 

新版本的jenkins为了保证安全,在安装之后有一个锁,需要设置密码之后才可以解锁

 
[root@linux-node1 ~]# cat /var/lib/jenkins/secrets/initialAdminPassword
490a2f35a2df49b6b8787ecb27122a3a

复制这个文件下面的ID,否则不可以进行安装。

我们选择推荐安装即可

 

我们先来介绍一下jenkins基础功能

这里就是构建一个项目

可以看到当前登陆用户及用户权限等


#之所以叫构建,是因为都是java,因为如果不是java程序就没有构建这个词。但是我们也可以把一些工作称之为构建

系统管理:-系统设置


#因为jenkins所有的东西都需要靠插件来完成,

我们想安装什么插件,我们可以选择可选插件


因为很多插件需要FQ才可以继续下载,jenkins还提供了代理的设置

 
    1. 还是在服务器目录下进行上传插件
    2. 目录路径= /var/lib/jenkins/plugins/
    3. 这个目录下是我们安装所有的插件

相关文章:

  • 2021-09-20
  • 2021-10-09
  • 2022-12-23
  • 2021-10-09
  • 2021-05-17
  • 2021-06-21
猜你喜欢
  • 2021-08-14
  • 2021-07-24
  • 2022-12-23
  • 2022-12-23
  • 2021-11-04
相关资源
相似解决方案