主要部分node
持续集成的分类:linux
Gitlab简介nginx
gitlab是使用Ruby语言所研发,实现自动托管的git项目仓库,能够经过web界面访问进行配置。gitlab拥有与GitHub相似的功能,可以浏览代码,管理缺陷和注释,能够管理团队对仓库的访问,它很是容易使用,并提供一个历史回顾,便于往后的管理和维护及其查找。 c++
版本控制分类:集中式版本控制、分布式版本控制,常见的集中式版本控制有:CVS,SVN,分布式版本控制有:GitLab、GitHub。git在每一个用户都有本身的私有仓库及其中央仓库,用户先提交代码到本地的私有仓库,然后肯定无误后将代码提交到中央仓库,这样大大的方便了开发者,而相比CVS和SVN都是集中式的版本控制系统,工做时须要从中央服务器获取最新代码,改完以后需推送到服务器。若是是一个比较大的文件则须要足够快的网络才能快速提交完成,而使用分布式的版本控制系统,每一个用户都是一个完整的版本库,即便没有中央服务器也能够提交代码或者回滚,最终再把改好的代码提交至中央服务器进行合并便可。 git
图示:程序员
Gitlab安装web
安装前准备:redis
yum install vim gcc gcc-c++ wget net-tools lrzsz iotop lsof iotop bash-completion -ysql
yum install curl policycoreutils openssh-server openssh-clients postfix -y数据库
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
systemctl disable firewalld
sed -i ‘/SELINUX/s/enforcing/disabled/‘ /etc/sysconfig/selinux
hostnamectl set-hostname xxx.com.cn
yum update –y && reboot
1.关闭防火墙
systemctl stop firewalld systemctl disable firewalld iptables -F setenforce 0
sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g‘ /etc/sysconfig/selinux #需重启生效
2.配置好base源和epel源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/CentOS-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
可配置好gitlab官网源使用yum进行安装,也可以使用官方下载的rpm进行安装配置
vim /etc/yum.repos.d/gitlab.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
3.安装配置gitlab依赖于Java环境,安装以前先安装jdk,可以使用rpm包进行安装等
yum -y install jdk-8u111-linux-x64.rpm
yum -y install gitlab-ce-8.13.5-ce.0.el7.rpm
4.编辑配置文件/etc/gitlab/gitlab.rb修改配置文件,测试配置文件,启动服务
external_url ‘http://node1.alren.com‘ #此处为本机IP地址
gitlab_rails[‘smtp_enable‘] = true
gitlab_rails[‘smtp_address‘] = "smtp.163.com"
gitlab_rails[‘smtp_port‘] = 25
gitlab_rails[‘smtp_user_name‘] = "chengong101300@163.com"
gitlab_rails[‘smtp_password‘] = "aaaaa"
gitlab_rails[‘smtp_domain‘] = "163.com"
gitlab_rails[‘smtp_authentication‘] = :login
gitlab_rails[‘smtp_enable_starttls_auto‘] = true
gitlab_rails[‘smtp_tls‘] = false
gitlab_rails[‘gitlab_email_from‘] = "chengong101300@163.com"
user["git_user_email"] = "chengong101300@163.com"
#gitlab-ctl reconfigure #修改配置文件后需重新编译此文件
#gitlab-ctl status #查看gitlab状态信息 默认占用80、8080端口
#gitlab-ctl stop/restart/start 关闭、重启、启动gitlab服务
[root@node1 ~]#
[root@node1 ~]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 127.0.0.1:8080 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 128 127.0.0.1:631 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 *:8060 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 ::1:631 :::*
LISTEN 0 100 ::1:25 :::*
[root@node1 ~]# gitlab-ctl status
run: gitlab-workhorse: (pid 115536) 34579s; run: log: (pid 16049) 300897s
run: logrotate: (pid 9121) 2913s; run: log: (pid 16068) 300889s
run: nginx: (pid 115547) 34579s; run: log: (pid 16055) 300895s
run: postgresql: (pid 115553) 34578s; run: log: (pid 15906) 300961s
run: redis: (pid 115561) 34578s; run: log: (pid 15823) 300967s
run: sidekiq: (pid 115565) 34577s; run: log: (pid 16038) 300903s
run: unicorn: (pid 115568) 34577s; run: log: (pid 16007) 300905s
[root@node1 ~]#
1.经过浏览器访问微博界面,接下来操做都是在web界面中进行,输入本机IP地址加上端口进行访问
2.将此处的注册按钮去除,防止其余人员配置登陆。需点击最下面的save按钮生效。
3.在建立项目以前需事先建立用户和组及其根据需求将用户加入到组中
提示:在gitlab中要事先建立组后才能在组中建立项目或以root身份建立项目,此定义在其自动生成的地址中有明确规定
建立项目(project)后将能够对项目进行必定的命令行操做。以下为命令行字符命令
Command line instructions
Git global setup #git全局设置
git config --global user.name "Administrator"
git config --global user.email "admin@example.com"
Create a new repository
git clone git@node1.alren.com:mywebs/webs.git #从仓库中克隆代码
cd webs
touch README.md
git add README.md #将修改的代码或文件提交到本地的仓库中
git commit -m "add README" #将修改的代码或文件提交到本地的仓库中并取名
git push -u origin master #推送到中央服务器中
Existing folder or Git repository
cd existing_folder
git init
git remote add origin git@node1.alren.com:mywebs/webs.git
git add .
git commit
git push -u origin master
可将多个用户添加到同一个组,之后组内的成员将对此项目拥有必定的权限
建立完成以后它提示咱们能够建立一个key对它进行管理,部署key以后则无需密码可将项目克隆到本地,仅支持ssh模式免秘钥,同时自动生成一个url,有两种形式基于HTTP,SSH
咱们点击REDME可编辑一个文档,随意写一些内容,点击提交
填写完将会出现路上所诉,可查看其内容。此时从gitlab中clone时需输入用户名和密码,免去秘钥登陆需添加ssh-key,免秘钥登陆。
[root@node1 ~]# git clone http://node1.alren.com/mywebs/webs.git
Cloning into ‘webs‘...
Username for ‘http://node1.alren.com‘: root
Password for ‘http://root@node1.alren.com‘:
fatal: Authentication failed for ‘http://node1.alren.com/mywebs/webs.git/‘
[root@node1 ~]# git clone http://node1.alren.com/mywebs/webs.git
Cloning into ‘webs‘...
Username for ‘http://node1.alren.com‘: root
Password for ‘http://root@node1.alren.com‘:
warning: You appear to have cloned an empty repository.
[root@node1 ~]# ls
anaconda-ks.cfg webapp webs
[root@node1 ~]# rm -rf webs/
[root@node1 ~]# git clone git@node1.alren.com:mywebs/webs.git
Cloning into ‘webs‘...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
[root@node1 ~]# ls
anaconda-ks.cfg webapp webs
[root@node1 ~]#
Git总结:工做区就是编辑文件的目录区域,须要将工做区的修改好的文件add到暂存区才能提交到git服务器,在工做区有多个文件的时候能够将一个或多个文件添加至暂存区提交到git服务器便可,刚提交后的暂存区和服务器的文件是一致的,所以也能够将最新的暂存区的文件进行上线和回滚,可是生产当中仍是使用服务器进行代码更新和回滚。
Jenkins简介
Jenkins是一个高度插件化的管理平台,这就是Jenkins流行的缘由,由于Jenkins什么插件都有,有很是灵活的API,开发能够调用编写插件,可完成不一样任务的编排和执行。Jenkins有Java语言所研发,此环境则需部署在Java环境之上,可下载rpm包或下载.war包丢到webapps目录下,启动服务,便可访问。
Jenkins官网地址:https://jenkins.io/
Jenkins安装及启动
经过rpm包进行安装:
rpm -ivh jdk-8u111-linux-x64.rpm
rpm -ivh https://pkg.jenkins.io/redhat/jenkins-2.27-1.1.noarch.rpm
可配置yum源,直接使用yum进行安装:
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat/jenkins.io.key
在启动以前编辑/etc/sysconfig/jenkins/配置文件,可对其数据目录、启动的用户、启动的端口等进行修改后启动,也能够默认。
JENKINS_HOME="/data" #数据库目录,使用高i/o大容量磁盘
JENKINS_USER="jenkins" #启动用户
JENKINS_PORT="8080" #启动端口
启动服务:
systemctl jenkins start 或 /etc/init.d/jenkins start
加入开机自启动(默认Jenkins启动会占用8080端口,因此其余服务不能与之冲突):
chkconfig jenkins on
输入IP地址进行访问:将/data/secrets/initialAdminPassword中将密码输入到选框中
下一步则是选择插件的步骤,能够自定义安装,也能够安装建议安装的插件,安装过程当中需链接互联网,且速度很是慢,可先忽略安装插件,直接在将插件解压至Jenkins的插件目录。
如出现插件安装失败不要紧,使用准备好的插件包解压至jenkins的plugin目录便可目录结构默认在/var/lib/jenkins/plugins/。
Jenkins基础功能
在jenkins-->系统管理-->系统设置设置管理员邮箱地址,当构建失败时,则会发邮件通知
按照实际状况配置Jenkins URL及其系统管理员邮件地址
设置邮件通知,经过设置好的邮件给须要发送的收件人发件reply-to-address
Jenkins项目构建
构建项目-->输入项目名称-->构建一个自由风格的软件项目-->点击ok,不过在建立项目以前需事先配置好jenkins的Credentials-->将私钥配置在此,将公钥部署在gitlab中,这样才能从gitlab中拉取代码或项目。
主界面包含系统的大部分配置
在系统设置中可配置邮件通知,maven、gitlab、sonar scanner邮件通知等
在系统管理--->插件管理中可安装大部分插件