持续集成(gitLab版)
gitlab 安装及汉化
GitLab简介:
GitLab是一个用于仓库管理系统的开源项目。使用Git作为代码管理工具,并在此基础上搭建起来的Web服务。可通过Web界面进行访问公开的或者私人项目。它拥有GitHub类似的功能,能够浏览源代码,管理缺陷和注释。可以管理团队对仓库的访问,它非常易于浏览提交过的版本并提供一个文件历史库。团队成员可以利用内置的简单聊天程序(Wall)进行交流。它还提供了一个代码片段收集功能可以轻松实现代码复用。
常用的网站:
国内镜像:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/
Gitlab相关操作及说明:
/etc/gitlab/gitlab.rb #gitlab配置文件
/opt/gitlab #gitlab的程序安装目录
/var/opt/gitlab #gitlab目录数据目录
/var/opt/gitlab/git-data #存放仓库数据
gitlab-ctl reconfigure #重新加载配置
gitlab-ctl status #查看当前gitlab所有服务运行状态
gitlab-ctl stop #停止gitlab服务
gitlab-ctl stop nginx #单独停止某个服务
gitlab-ctl tail #查看所有服务的日志
Gitlab的服务构成:
nginx: 静态web服务器
gitlab-workhorse 轻量级反向代理服务器
logrotate 日志文件管理工具
postgresql 数据库
redis 缓存数据库
sidekiq 用于在后台执行队列任务(异步执行)
安装gitlab
安装环境:
(1)CentOS 6或者7 (此处使用7)
(2)2G内存(实验)生产(至少4G),不然会很卡
(3)安装包:gitlab-ce-10.2.2-ce
(4)禁用防火墙,关闭selinux
安装步骤:
(1)安装软件
[aaa@qq.com ~]# yum install -y curl policycoreutils-python openssh-server #安装依赖
[aaa@qq.com ~]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-10.2.2-ce.0.el7.x86_64.rpm #下载软件包
[aaa@qq.com ~]# rpm -ivh gitlab-ce-10.2.2-ce.0.el7.x86_64.rpm #安装gitlab
(2)根据安装完成提示界面进行访问URL更改及重新加载配置文件 更改次选项为自己的域名或者IP external_url 'http://gitlab.example.com'
[aaa@qq.com ~]# vim /etc/gitlab/gitlab.rb #编辑配置文件
external_url 'http://192.168.1.21' #改为自己的IP地址
[aaa@qq.com ~]# gitlab-ctl reconfigure #重新加载配置文件
(3)重装完成访问http://192.168.1.21,会首先叫更改密码(root用户),改完后登录。如下界面:
(4)汉化
1、下载汉化补丁
[aaa@qq.com ~]# git clone https://gitlab.com/xhang/gitlab.git
[aaa@qq.com ~]# cd gitlab
2、查看全部分支版本
[aaa@qq.com ~]# git branch -a
3、对比版本、生成补丁包
[aaa@qq.com ~]# git diff remotes/origin/10-2-stable remotes/origin/10-2-stable-zh > /tmp/10.2.2-zh.diff
4、停止服务器
[aaa@qq.com ~]# gitlab-ctl stop
5、打补丁
[aaa@qq.com ~]# patch -d /opt/gitlab/embedded/service/gitlab-rails -p1 < /tmp/10.2.2-zh.diff
6、启动和重新配置
[aaa@qq.com ~]# gitlab-ctl start
[aaa@qq.com ~]# gitlab-ctl reconfigure
说明:这里如果使用的同样是gitlab10.2.2,下载汉化较慢的话,可以直接在这里下载10.2.2-zh.diff。提取码:kaiw
汉化完成后再次刷新页面如下
(5)设置开机自启
systemctl enable gitlab-runsvdir.service
安装Jenkins(持续集成平台)
安装nexus
- 下载
官网:https://www.sonatype.com/download-oss-sonatype
网盘:https://blog.csdn.net/u010741112/article/details/103886347
- 解压
tar -zxvf nexus-3.20.1-01-unix.tar.gz -C /usr/local/
- 配置文件
vim /usr/local/nexus/etc/nexus-default.properties
端口默认8081,可根据情况进行修改
- 运行命令启动(root用户启动警告信息不影响)
/usr/local/nexus/bin/nexus start
- 访问
浏览器输入框地址 http://ip:port
默认账号 admin 密码admin123
- 中途遇到的坑!!!
如果启动不能访问请关闭防火墙
查看防火墙状态: systemctl status firewalld.service
执行关闭命令: systemctl stop firewalld.service
再次执行查看防火墙命令:systemctl status firewalld.service
执行开机禁用防火墙自启命令 : systemctl disable firewalld.service
启动:systemctl start firewalld.service
防火墙随系统开启启动 : systemctl enable firewalld.service
- 设置开机自启
1、vim 打开 nexus 入口程序文件,配置jdk目录
vim /usr/local/nexus/bin/nexus
2、创建nexus服务配置文件
vim /etc/systemd/system/nexus.service
红色部分根据情况进行调整
3、刷新系统文件,开机自启动
sudo systemctl daemon-reload // 刷新配置
sudo systemctl enable nexus.service //设置自启动
sudo systemctl start nexus.service //启动服务
安装maven
- 解压maven tar包
tar -zxvf apache-maven-3.0.4-bin.tar.gz -C /usr/local/
- 配置环境变量, 重启生效
[aaa@qq.com local]# vim /etc/profile
[aaa@qq.com local]# source /etc/profile
- 修改 settings.xml 配置文件
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!--
| This is the configuration file for Maven. It can be specified at two levels:
|
| 1. User Level. This settings.xml file provides configuration for a single user,
| and is normally provided in ${user.home}/.m2/settings.xml.
|
| NOTE: This location can be overridden with the CLI option:
|
| -s /path/to/user/settings.xml
|
| 2. Global Level. This settings.xml file provides configuration for all Maven
| users on a machine (assuming they're all using the same Maven
| installation). It's normally provided in
| ${maven.home}/conf/settings.xml.
|
| NOTE: This location can be overridden with the CLI option:
|
| -gs /path/to/global/settings.xml
|
| The sections in this sample file are intended to give you a running start at
| getting the most out of your Maven installation. Where appropriate, the default
| values (values used when the setting is not specified) are provided.
|
|-->
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ~/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->
<localRepository>/usr/local/maven/Repository</localRepository>
<!-- interactiveMode
| This will determine whether maven prompts you when it needs input. If set to false,
| maven will use a sensible default value, perhaps based on some other setting, for
| the parameter in question.
|
| Default: true
<interactiveMode>true</interactiveMode>
-->
<!-- offline
| Determines whether maven should attempt to connect to the network when executing a build.
| This will have an effect on artifact downloads, artifact deployment, and others.
|
| Default: false
<offline>false</offline>
-->
<!-- pluginGroups
| This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
| when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
| "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
|-->
<pluginGroups>
<!-- pluginGroup
| Specifies a further group identifier to use for plugin lookup.
<pluginGroup>com.your.plugins</pluginGroup>
-->
</pluginGroups>
<!-- proxies
| This is a list of proxies which can be used on this machine to connect to the network.
| Unless otherwise specified (by system property or command-line switch), the first proxy
| specification in this list marked as active will be used.
|-->
<proxies>
<!-- proxy
| Specification for one proxy, to be used in connecting to the network.
|
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username>proxyuser</username>
<password>proxypass</password>
<host>proxy.host.net</host>
<port>80</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
-->
</proxies>
<!-- servers
| This is a list of authentication profiles, keyed by the server-id used within the system.
| Authentication profiles can be used whenever maven must make a connection to a remote server.
|-->
<!-- server
| Specifies the authentication information to use when connecting to a particular server, identified by
| a unique name within the system (referred to by the 'id' attribute below).
|
| NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
| used together.
|
<server>
<id>deploymentRepo</id>
<username>repouser</username>
<password>repopwd</password>
</server>
-->
<!-- Another sample, using keys to authenticate.
<server>
<id>siteServer</id>
<privateKey>/path/to/private/key</privateKey>
<passphrase>optional; leave empty if not used.</passphrase>
</server>
-->
<!--配置权限,使用默认用户-->
<servers>
<server>
<id>nexus-releases</id>
<username>deployment</username>
<password>deployment123</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>deployment</username>
<password>deployment123</password>
</server>
</servers>
<!-- mirrors
| This is a list of mirrors to be used in downloading artifacts from remote repositories.
|
| It works like this: a POM may declare a repository to use in resolving certain artifacts.
| However, this repository may have problems with heavy traffic at times, so people have mirrored
| it to several places.
|
| That repository definition will have a unique id, so we can create a mirror reference for that
| repository, to be used as an alternate download site. The mirror site will be the preferred
| server for that repository.
|-->
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
<profiles>
<profile>
<id>nexus-wfm</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
<repositories>
<!-- 私有库地址-->
<repository>
<id>nexus</id>
<url>http://localhost:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<!--插件库地址-->
<pluginRepository>
<id>nexus</id>
<url>http://localhost:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<!-- ** -->
<activeProfiles>
<activeProfile>nexus-wfm</activeProfile>
</activeProfiles>
<!-- profiles
| This is a list of profiles which can be activated in a variety of ways, and which can modify
| the build process. Profiles provided in the settings.xml are intended to provide local machine-
| specific paths and repository locations which allow the build to work in the local environment.
|
| For example, if you have an integration testing plugin - like cactus - that needs to know where
| your Tomcat instance is installed, you can provide a variable here such that the variable is
| dereferenced during the build process to configure the cactus plugin.
|
| As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
| section of this document (settings.xml) - will be discussed later. Another way essentially
| relies on the detection of a system property, either matching a particular value for the property,
| or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
| value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
| Finally, the list of active profiles can be specified directly from the command line.
|
| NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
| repositories, plugin repositories, and free-form properties to be used as configuration
| variables for plugins in the POM.
|
|-->
<!-- profile
| Specifies a set of introductions to the build process, to be activated using one or more of the
| mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
| or the command line, profiles have to have an ID that is unique.
|
| An encouraged best practice for profile identification is to use a consistent naming convention
| for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
| This will make it more intuitive to understand what the set of introduced profiles is attempting
| to accomplish, particularly when you only have a list of profile id's for debug.
|
| This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
<profile>
<id>jdk-1.4</id>
<activation>
<jdk>1.4</jdk>
</activation>
<repositories>
<repository>
<id>jdk14</id>
<name>Repository for JDK 1.4 builds</name>
<url>http://www.myhost.com/maven/jdk14</url>
<layout>default</layout>
<snapshotPolicy>always</snapshotPolicy>
</repository>
</repositories>
</profile>
-->
<!--
| Here is another profile, activated by the system property 'target-env' with a value of 'dev',
| which provides a specific path to the Tomcat instance. To use this, your plugin configuration
| might hypothetically look like:
|
| ...
| <plugin>
| <groupId>org.myco.myplugins</groupId>
| <artifactId>myplugin</artifactId>
|
| <configuration>
| <tomcatLocation>${tomcatPath}</tomcatLocation>
| </configuration>
| </plugin>
| ...
|
| NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
| anything, you could just leave off the <value/> inside the activation-property.
|
<profile>
<id>env-dev</id>
<activation>
<property>
<name>target-env</name>
<value>dev</value>
</property>
</activation>
<properties>
<tomcatPath>/path/to/tomcat/instance</tomcatPath>
</properties>
</profile>
-->
<!-- activeProfiles
| List of profiles that are active for all builds.
|
<activeProfiles>
<activeProfile>alwaysActiveProfile</activeProfile>
<activeProfile>anotherAlwaysActiveProfile</activeProfile>
</activeProfiles>
-->
</settings>
安装Jenkins
- 首先创建文件夹JenkinsHome、配置环境变量、重启生效
[aaa@qq.com conf]# mkdir /usr/local/JenkinsHome
[aaa@qq.com conf]# vim /etc/profile
[aaa@qq.com conf]# source /etc/profile
添加如下配置:
- 安装jenkins-tomcat
tar -zxvf apache-tomcat-8.5.46.tar.gz
mv apache-tomcat-8.5.46 /usr/local/jenkins-tomcat
- 修改server.xml文件
vim /usr/local/jenkins-tomcat/conf/server.xml
修改内容:
<Server port="7005" shutdown="SHUTDOWN">
<Connector port="7070" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="7443" URIEncoding="UTF-8" />
<Connector port="7009" protocol="AJP/1.3" redirectPort="7443" />
- 修改tomcat内存
vim /usr/local/jenkins-tomcat/bin/catalina.sh
修改内容:
JAVA_OPTS='-Xms256m -Xmx512m'
- 上传jenkins.war到 /usr/local/jenkins-tomcat/webapps下
cd /usr/local/jenkins-tomcat/webapps/
unzip jenkins.war -d jenkins
rm -f jenkins.war
- 启动tomcat:命令:/usr/local/jenkins-tomcat/bin/startup.sh
- 查看启动日志:tail -f -n 500 /usr/local/jenkins-tomcat/logs/catalina.out
- 浏览器访问:http://IP:7070/jenkins,看到下图表示启动成功
下一篇: 对分布式系统课程秒杀项目的再思考
推荐阅读