jenkins+Gitlab安装及初步使用

安装包下载地址:
https://packages.gitlab.com/gitlab/gitlab gitlab-ce
rpm 包国内下载地址: https://mirrors.tuna.tsinghua.edu.cn/gitlab gitlab-ce/yum/
ubuntu
国内 下载地址 :https://mirrors.tuna.tsinghua.edu.cn/gitlab gitlab-ce/ubuntu/pool/

#:下载gitlab并安装

root@ubuntu:/usr/local/src# ll
total 652876
drwxr-xr-x  2 root root      4096 Sep 26 21:48 ./
drwxr-xr-x 10 root root      4096 Sep 18 23:01 ../
-rw-r--r--  1 root root 668531950 Sep 26 21:48 gitlab-ce_11.11.5-ce.0_amd64.deb
root@ubuntu:/usr/local/src# dpkg -i gitlab-ce_11.11.5-ce.0_amd64.deb 

#:配置gitlab

root@ubuntu:/usr/local/src# vim /etc/gitlab/gitlab.rb
external_url 'http://192.168.6.101'    #:gitlab服务器地址
### Email Settings    #:配置邮件服务器
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "316428921@qq.com"
gitlab_rails['smtp_password'] = "ebbwqkjprqilcaec"
gitlab_rails['smtp_domain'] = "qq.com"
gitlab_rails['smtp_authentication'] = :login
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_from'] = "316428921@qq.com"
user["git_user_email"] = "316428921@qq.com"

#:初始化服务(每次修改配置文件后,都要执行此命令)

root@ubuntu:/usr/local/src# gitlab-ctl reconfigure

#:验证启动

root@ubuntu:/usr/local/src# gitlab-ctl status

#:登录giltlab设置密码(至少8位)

 

 

#:登录(默认用户为root)

 

 

#: 关闭账号注册功能

 

#:登录进去,关闭此选项

 

 

#:在找一台主机安装jenkinns

https://mirrors.tuna.tsinghua.edu.cn/jenkins/debiandebian-stable/ #ubuntu 安装包

#:配置Java环境JDK

root@ubuntu:/usr/local/src# ls
jdk-8u212-linux-x64.tar.gz
root@ubuntu:/usr/local/src# tar xf jdk-8u212-linux-x64.tar.gz
root@ubuntu:/usr/local/src# ln -sv jdk1.8.0_212/ /usr/local/jdk    
root@ubuntu:/usr/local/src# ln -sv /usr/local/src/jdk1.8.0_212/bin/java /usr/bin/

#:配置环境变量
root@ubuntu:/usr/local/src# vim /etc/profile
JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar
 root@ubuntu:/usr/local/src# source /etc/profile

#:测试
root@ubuntu:/usr/local/src# java -version
root@ubuntu:/usr/local/src# /usr/bin/java -version

#:配置安装Jenkins(因为jenkins启动需要daemon包,所以先要安装daemon,安装daemon后,会自动安装jenkins)
root@ubuntu:/usr/local/src# apt install daemon

#:自改jenkins配置文件
root@ubuntu:/usr/local/src# vim /etc/default/jenkins
JENKINS_USER=root
JENKINS_GROUP=root #:因默认启动用户为jenkins,后期会有很多权限问题,这里先改成root
MAXOPENFILES=65536 #:打开最大文件数,最好改大点

#:启动服务
root@ubuntu:/usr/local/src# systemctl restart jenkins

#:访问

 

 #:如果jenkins访问以离线,将以下文件中的更新检查改成清华大学的地址,然后重启jenkins

      https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update update-center.json

 

 

 

 #:因装插件很慢,所以可以下载插件,直接解压到指定目录(插件要和jenkins同一版本)

       下载地址:http://updates.jenkinsjenkins-ci.org/download/plugins/

#:先停服务
root@ubuntu:/var/lib/jenkins/plugins# systemctl stop jenkins

#:将插件下载到此目录
root@ubuntu:/usr/local/src# cd /var/lib/jenkins/plugins/

#:解压
root@ubuntu:/var/lib/jenkins/plugins# tar xf jenkins-2.176.3-plugins.tar.gz

#:启动服务

root@ubuntu:/var/lib/jenkins/plugins# systemctl start jenkins

#:在web端重新登录-------然后点击恢复

#;创建管理员账户

 

 

 

#:在gitlab的web端创建组

 

 #:创建用户

 

 #:退出登录,为新建用户设置密码

 

 

#:创建一个项目

 

 

#:将添加的用户添加到组

 

 

 

 

 

#:创建好以后往下拉,用创建的用户登录 ,在jenkins的机器上根据提示配置一下

 

 #:在jenkins的机器上配置

root@ubuntu:/var/lib/jenkins/plugins# git config --global user.name "xiaoming"
root@ubuntu:/var/lib/jenkins/plugins# git config --global user.email "316428921@qq.com"

#:在web端创建一个文件

 

 

 

 #:然后在项目中找到这个,复制命令clone下来

 

 

 #:在jenkins的主机上clone

root@ubuntu:/opt# git clone http://192.168.6.101/linux37/web1.git
Cloning into 'web1'...
Username for 'http://192.168.6.101': xiaoming      #:输入账号
Password for 'http://xiaoming@192.168.6.101':     #:输入密码
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
root@ubuntu:/opt# ll
total 12
drwxr-xr-x  3 root root 4096 Sep 27 13:13 ./
drwxr-xr-x 23 root root 4096 Sep 18 23:07 ../
drwxr-xr-x  3 root root 4096 Sep 27 13:13 web1/

 

 

 

#:设置利用jenkins在gitlab上clone代码

 

 

#:配置jenkins从gitlab自动clone

 

 

 

 #:在Gitlab中配置证书

 

 #:在jenkins生成公钥

root@ubuntu:/opt/web1# ssh-keygen

 

 #:公钥复制好后,就可以在jenkins服务器利用Git clone 了

root@ubuntu:/opt# git clone git@192.168.6.101:linux37/web1.git
Cloning into 'web1'...
The authenticity of host '192.168.6.101 (192.168.6.101)' can't be established.
ECDSA key fingerprint is SHA256:G7VcWONVkIT36fUwTXUwUxJUCLHs79RiDcz1tm0U6Hs.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.6.101' (ECDSA) to the list of known hosts.
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.

 

 

 

#:准备正式克隆一个网页

#:在准备一台主机,安装NGINX

root@ubuntu:/usr/local/src# wget http://nginx.org/download/nginx-1.16.1.tar.gz
root@ubuntu:/usr/local/src/nginx-1.16.1# ./configure --prefix=/apps/nginx
root@ubuntu:/usr/local/src/nginx-1.16.1# make && make install

#:编辑配置文件,修改location
root@ubuntu:/usr/local/src/nginx-1.16.1# vim /apps/nginx/conf/nginx.conf
        location /linux37 {
            root /data/web1;
            index index.html index.htm;
        }

#;创建目录
root@ubuntu:/usr/local/src/nginx-1.16.1# mkdir /data/web1/linux37 -p

#:在jenkins服务器做免秘钥登录
root@ubuntu:/opt# ssh-copy-id 192.168.6.103

#:测试(必须测试,否则需要输入yes)
root@ubuntu:/opt# ssh 192.168.7.103

#:在gitlab上准备项目文件

 

 

 

 #:在jenkins服务器部署

 

 

 

posted @ 2019-09-27 15:35  Linus小跟班  阅读(1248)  评论(0编辑  收藏  举报