当前位置:   article > 正文

Jenkins搭建CI环境

Jenkins搭建CI环境
ip: 192.168.80.132

一、安装sshd
1.  apt-get install openssh-server


二、将ubuntu的repository设置为阿里云
1. 替换 /etc/apt/sources.list 的内容如下:
deb cdrom:[Ubuntu-Server 16.04.1 LTS _Xenial Xerus_ - Release amd64 (20160719)]/ xenial main restricted
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb https://apt.dockerproject.org/repo/ ubuntu-xenial main


2. sudo apt-get update


3. ubunut使用代理访问软件源(本人内网环境,需要通过https/http代理访问外网。所以需要配置此步骤,可以直接访问外网的同学跳过此步骤)
新建文件 apt_proxy_conf(文件名任意)

root@CI:/etc/apt# cat apt_proxy_conf

#配置文件如下:·
Acquire::http::proxy "http://192.168.18.81:9009/";
Acquire::ftp::proxy "ftp://192.168.18.81:9009/";
Acquire::https::proxy "https://192.168.18.81:443/";

往后就可以在apt-get之后加上 -c apt_proxy_conf 来执行。

三、安装java
sudo mkdir /opt/java
cd /opt/java
sudo tar zxvf jdk-8u112-linux-x64.tar.gz
sudo vim /etc/profile

#在文件结尾处增加
export JAVA_HOME=/opt/java/jdk1.8.0_112
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH

source /etc/profile
sudo ln -s /opt/java/jdk1.8.0_112/bin/java /bin/java


四、安装mavne
cd /opt/java
sudo tar zxvf apache-maven-3.3.9-bin.tar.gz

#设置环境变量  /opt/java/apache-maven-3.3.9
sudo vim /etc/profile
#在文件结尾处增加
export M2_HOME=/opt/java/apache-maven-3.3.9
export PATH=$M2_HOME/bin:$PATH

五、安装git
sudo apt-get install git-core openssh-server openssh-client
sudo apt-get install python-setuptools

六、设置到git server的免密码登录
sudo adduser ci
su ci
#创建ssh keypair
ssh-keygen
cd /home/ci/.ssh/
cp id_rsa.pub authorized_keys
chmod 600 authorized_keys
#将authorized_keys 拷贝到git server的ci用户的相应目录下
scp authorized_keys root@192.168.18.85:/home/ci/.ssh/
su - ci
ssh 192.168.18.85   //登录成功


七、安装jenkin (适用于 ubuntu)
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -


#如果上述命令返回gpg: no valid OpenPGP data found. 用如下命令继续
wget --no-check-certificate -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -

sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt-get update
sudo apt-get install jenkins

八、jenkins 管理员账户
http://192.168.80.132:8080/
vanwe
gh3$4xzc

安装 git—plugin maven-plugin 等插件
vim /etc/default/docker
#如果没有权限加入如下行, 否则jenkins在制作docker镜像时无操作unix socket权限
DOCKER_OPTS=' -G jenkins'
#将jenkins 加入到docker组
sudo usermod -a -Gdocker jenkins

#切换到jenkins用户 
sudo su -s /bin/bash jenkins
docker ps 

#如果仍然没有权限,reboot

#jenkins 中增加shell命令行
cd src
mvn package docker:build


#运行jenkins
//docker run --cidfile="gps-master.cid" -d -p80:80 -t ubuntu/vgps


#添加如下脚本(这个脚本已经放到源代码目录)
cidfile="gps-master.cid"
if [ -f $cidfile ]; then
  read contain_id < $cidfile
  echo stop container... container_id="$contain_id"
  docker stop $contain_id
  rm -rf $cidfile
fi
docker run --cidfile="gps-master.cid" -d -p80:80 -t ubuntu/vgps


#jenkins 中增加shell命令行
cd src
bash docker_cmd.bash




九、安装docker环境
su -  //切换到root
cd /opt/
apt-get install apt-transport-https software-properties-common ca-certificates
apt-get install curl
curl -fsSL https://yum.dockerproject.org/gpg | sudo apt-key add -


#如果上述命令返回gpg: no valid OpenPGP data found. 用如下命令继续
wget --no-check-certificate -q -O - http://yum.dockerproject.org/gpg | sudo apt-key add -




apt-key fingerprint 58118E89F3A912897C070ADBF76221572C52609D
sudo apt-get install software-properties-common
add-apt-repository "deb https://apt.dockerproject.org/repo/ ubuntu-$(lsb_release -cs) main"


#如果上一行证书失败,使用下面命令
add-apt-repository "deb http://apt.dockerproject.org/repo/ ubuntu-$(lsb_release -cs) main"


apt-get update
apt-get -y install docker-engine

十、安装默认的docker版本 (版本号:1.12.6)
$ sudo apt-get update
$ sudo apt-get install docker


===================================================================================================
关于Jenkins卸载的具体步骤:


1.sudo apt-get --purge remove jenkins -------将安装Jenkins时所产生的目录全部删除包括配置文件等。
2.sudo apt-get --purge remove jenkins -------再次运行下载Jenkins的命名时,将显示Jenkins已经删除,但是安装Jenkins时同时安装的其他依赖包还存在,这时就可以显示出这些所依赖的包。
3.sudo apt-get --purge remove ca-certificates-Java -----将依赖包进行删除。(ca-certificates-java依赖包)
4.sudo apt-get --purge remove (其他依赖包)。
这时,再运行sudo apt-get install jenkins 命令安装Jenkins时就跟系统从来没有安装过Jenkins一样。


===================================================================================================
openssl 创建证书
openssl req -new -keyout ..\key.pem -nodes -x509 -days 365 -out ..\cert.pem




==============================
为docker创建proxy
vim /etc/systemd/system/docker.service.d/http-proxy.conf
#配置文件如下:
[Service]
Environment="HTTP_PROXY=http://192.168.18.81:9009"
Environment="HTTPS_PROXY=http://192.168.18.81:443/"
Environment="NO_PROXY=localhost,127.0.0.1,localaddress,.localdomain.com"


systemctl show docker --property Environment
systemctl restart docker
systemctl daemon-reload
==========================================

====================================================================================================
/etc/init.d/stunnel4 start


=======================================================
ubuntu 导入证书
/usr/local/share/ca-certificates


1. 配置证书
dpkg-reconfigure ca-certificates
2. 更新证书
update-ca-certificates
=======================================================
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/678355
推荐阅读
相关标签
  

闽ICP备14008679号