服务器
CentOS 7.5 64位
安装FinalShell软件
连接服务器
gitlab部署
参考网址: https://www.cnblogs.com/LUA123/p/9675191.html
- 先检查一下依赖:sshd
[root@localhost soft]# rpm -qa|grep openssh-server
openssh-server-7.4p1-11.el7.x86_64
[root@localhost soft]# ps -e|grep sshd
1107 ? 00:00:00 sshd
12585 ? 00:00:00 sshd
12590 ? 00:00:00 sshd
如果你没有,那么
sudo yum install -y curl policycoreutils-python openssh-server
sudo systemctl enable sshd
sudo systemctl start sshd
sudo firewall-cmd --permanent --add-service=http
sudo systemctl reload firewalld
- 再检查一下postfix
[root@localhost soft]# rpm -qa|grep postfix
postfix-2.10.1-6.el7.x86_64
[root@localhost soft]# ps -e|grep postfix
如果你没有,那么
sudo yum install postfix
sudo systemctl enable postfix
sudo systemctl start postfix
- 最后找到你存放rpm目录并进入
[root@localhost soft]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-11.0.6-ce.0.el7.x86_64.rpm
--2018-09-19 03:12:09-- https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-11.0.6-ce.0.el7.x86_64.rpm
Resolving mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)... 101.6.8.193, 2402:f000:1:408:8100::1
Connecting to mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|101.6.8.193|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 436017937 (416M) [application/x-redhat-package-manager]
Saving to: ‘gitlab-ce-11.0.6-ce.0.el7.x86_64.rpm’
100%[=========================================================================================================================================================>] 436,017,937 1.50MB/s in 4m 37s
2018-09-19 03:16:46 (1.50 MB/s) - ‘gitlab-ce-11.0.6-ce.0.el7.x86_64.rpm’ saved [436017937/436017937]
当使用wget下载https的内容时,会会报 --no-check-certificate 错误,在wget后加入–no-check-certificate 参数即可,例如:
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-11.0.6-ce.0.el7.x86_64.rpm --no-check-certificate
- 查看
[root@localhost soft]# ll
total 695524
-rw-r--r--. 1 root root 436017937 Sep 7 01:24 gitlab-ce-11.0.6-ce.0.el7.x86_64.rpm
-rw-r--r--. 1 root root 189756259 Mar 26 07:20 jdk-8u161-linux-x64.tar.gz
-rw-r--r--. 1 root root 49766096 Mar 26 07:20 kafka_2.11-1.0.1.tgz
-rw-r--r--. 1 root root 36668066 Mar 26 07:20 zookeeper-3.4.11.tar.gz
[root@localhost soft]#
若报错,可更新yum
yum update
- 安装
[root@localhost soft]# rpm -ivh gitlab-ce-11.0.6-ce.0.el7.x86_64.rpm
warning: gitlab-ce-11.0.6-ce.0.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:gitlab-ce-11.0.6-ce.0.el7 ################################# [100%]
It looks like GitLab has not been configured yet; skipping the upgrade script.
*. *.
*** ***
***** *****
.****** *******
******** ********
,,,,,,,,,***********,,,,,,,,,
,,,,,,,,,,,*********,,,,,,,,,,,
.,,,,,,,,,,,*******,,,,,,,,,,,,
,,,,,,,,,*****,,,,,,,,,.
,,,,,,,****,,,,,,
.,,,***,,,,
,*,.
_______ __ __ __
/ ____(_) /_/ / ____ _/ /_
/ / __/ / __/ / / __ `/ __ \
/ /_/ / / /_/ /___/ /_/ / /_/ /
\____/_/\__/_____/\__,_/_.___/
Thank you for installing GitLab!
GitLab was unable to detect a valid hostname for your instance.
Please configure a URL for your GitLab instance by setting `external_url`
configuration in /etc/gitlab/gitlab.rb file.
Then, you can start your GitLab instance by running the following command:
sudo gitlab-ctl reconfigure
For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md
- 然后编辑
vim /etc/gitlab/gitlab.rb
修改 url
在此输入服务器url(按着键盘上 i ,进入linux的编辑模式,输入完,按Esc,再输入 :wq 即可保存并退出)
- 然后执行
gitlab-ctl reconfigure
- 启动
gitlab-ctl restart
- 查看端口占用
[root@localhost soft]# netstat -tunlp
- 查看防火墙
[root@localhost soft]# firewall-cmd --zone=public --list-ports
2888/tcp 3888/tcp 2181/tcp
[root@localhost soft]# firewall-cmd --zone=public --add-port=80/tcp --permanent
success
[root@localhost soft]# firewall-cmd --reload
success
-
打开浏览器,访问
-
创建项目
-
设置SSH Key,在jenkins服务器上配置
cd /root
ssh-keygen (一直enter,生成ssh密钥)
cd .ssh
cat id_rsa.pub
将ssh复制进gitlab中即可
- 在jenkins服务器上,验证ssh是否有效
cd /soft
git clone ssh url 地址
此时gitlab已经配置完成,接下来该jenkins
阿里云部署jenkins
参照网址:https://www.cnblogs.com/superjie/p/9876028.html
- 在安装jenkins之前,服务器先安装JDK
yum install java-1.8.0-openjdk
再安装 git
yum install -y git
若报错,可更新yum
yum update
- 1.添加官方的rpm包源,进行yum安装
[root@iZbp ~]# wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
[root@iZbp ~]# rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
- yum安装jenkins
root@iZbp ~]# yum -y install jenkins
- 2.编辑jenkins的/etc/init.d/jenkins程序文件,添加java路径
查看Linux中的java环境变量的绝对路径
[root@iZbp jenkins]# echo $JAVA_HOME
/usr/java/jdk1.8.0_121
查看jenkins的程序文件,确认java的路径是否正确,如果正确,则不需要修改;
如果不正确,那么修改java的绝对路径,然后注释默认的java路径,保存退出
[root@iZbp jenkins]# vim /etc/init.d/jenkins
66 candidates="
67 /etc/alternatives/java
68 /usr/lib/jvm/java-1.8.0/bin/java
69 /usr/lib/jvm/jre-1.8.0/bin/java
70 /usr/lib/jvm/java-1.7.0/bin/java
71 /usr/lib/jvm/jre-1.7.0/bin/java
72 # /usr/bin/java
73 # /usr/java/jdk1.8.0_121
74
75 # Add JAVA_HOME/bin/java by liyasong 20170228
76 /usr/java/jdk1.8.0_121/bin/java
- 3.编辑jenkins的/etc/sysconfig/jenkins配置文件,修改端口、系统运行账户 (编辑端口:输入命令vim /etc/sysconfig/jenkins之后,进入如下页面,按“i”键进行编辑,编辑完端口之后,按“esc”键,再按“:wq”退出并保存)
[root@iZbp jenkins]# vim /etc/sysconfig/jenkins
默认运行用户为jenkins,更改为root
默认侦听端口为8080,可自行修改
- 4.编辑/etc/profiles文件添加jenkins的环境变量
[root@iZbp jenkins]# vim /etc/profile
export JENKINS_HOME=/var/lib/jenkins
source使profile中新添加的环境变量立即生效(无需重启)
[root@iZbp11rfoyeescusr9ha9qZ jenkins]# source /etc/profile
- 检查环境变量是否配置成功
[root@iZbp11rfoyeescusr9ha9qZ jenkins]# echo $JENKINS_HOME
/var/lib/jenkins/
- 5.启动jenkins服务
[root@iZbp wwwroot]# service jenkins start
- 这时候会发现/usr/lib/jenkins/下面就有了jenkins.war文件,无需wget从官网下载
[root@iZbp11rfoyeescusr9ha9qZ jenkins]# cd /usr/lib/jenkins/
[root@iZbp11rfoyeescusr9ha9qZ jenkins]# ls
jenkins.war
- 查看jenkins的日志,最后一行显示Listed all plugins,表示jenkins服务正常运行中
[root@iZbp ~]# vim /var/log/jenkins/jenkins.log
#最后一行消息
INFO: Listed all plugins
-
6.打开浏览器,访问:http://x.x.x.x:9009
看到如下界面,在finallshell中输入如下文件的路径查看初始密码:vim /var/lib/jenkins/secrets/initialAdminPassword
此时jenkis安装配置ok啦! -
在jenkins中安装nodejs插件,并且在【系统配置】中安装npm14.6.0
点击 系统管理----插件管理–安装node
点击 系统管理----全局工具配置–nodejs 安装14.6.0版本 -
在finallshell中先
mkdir soft cd /soft
-
回到gitlab中,新建一个项目,并把本地的项目传到gitlab中后,复制gitlab地址,放到以下shell命令中 ,如git@118.178.234.224:root/test666.git
-
新建任务
-
点击 【配置】-【构建环境】中勾选,Provide Node & npm bin/ folder to PATH
-
点击【构建】选择【增加构建步骤】勾选【执行shell】,在里面输入npm -v,先检查npm是否安装
-
点击【构建】选择【增加构建步骤】勾选【执行shell】,在shell里面输入相应打包命令
echo "开始构建前端环境"
cd /soft
if [ ! -d "./test666" ]; then
git clone git@118.178.234.224:root/test666.git
fi
cd test666
git pull
npm install
npm run build
- 返回视图,点击【立即构建】
如果构建失败,查看控制台,逐一安装以上命令,直至构建成功。