In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
I. case environment
II. Deploy Gitlab
1) deploy Gitlab
2) configure secret-free login
3) Test secret-free login
3. Deploy Jenkins
4. Jenkins integrates Gitlab
5. Deploy Nginx
6. Jenkins realizes that the code is online automatically.
7. Jenkins realizes code automatic deployment, fallback and repeated construction.
1. Case environment system IP address hostname running service Centos 7192.168.1.6gitlabgitlabCentos 7192.168.1.7jenkinsjenkinsCentos 7192.168.1.8nginxnginx 2. Deploy Gitlab1) deploy Gitlab [root@gitlab ~] # yum-y install epel-release curl openssh-server openssh-clients postfix cronie policycoreutils-python patch# installation dependencies [root@gitlab ~] # wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-12.3.5-ce.0.el7.x86_64.rpm# there are no special restrictions on the version of gitlab [root@gitlab ~] # yum-y Localinstall gitlab-ce-12.3.5-ce.0.el7.x86_ 64.rpm [root @ gitlab ~] # vim / etc/gitlab/gitlab.rb # easy to use the URL path to access external_url 'http://192.168.1.6'# to download the Chinese patch pack [root@gitlab] # head-1 / opt/gitlab/version-manifest.txt # to view gitlab-ce 12.3 of the version of RPM. 5 [root@gitlab ~] # git clone https://gitlab.com/xhang/gitlab.git-b v12.3.5-zh [root@gitlab ~] # cd gitlab/ [root@gitlab gitlab] # git diff v12.3.5 v12.3.5-zh > / root/v12.3.5-zh.dif [root@gitlab gitlab] # patch-d / opt/gitlab/embedded/service/gitlab-rails-p1
< ../v12.3.5-zh.diff #将刚才的diff文件做为补丁导入到gitlab中#该命令执行过程中,一路回车跳过即可[root@gitlab ~]# gitlab-ctl start # 启动gitlab[root@gitlab ~]# gitlab-ctl reconfigure #重新配置gitlab web页面访问测试It can be seen that the website page of gitlab has been transformed into Chinese!
2) configure secret-free login [root@gitlab ~] # ssh-keygen [root@gitlab ~] # cat ~ / .ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCuWnEReFVhIiODuTO/NzdjuvPMY0tQ89NuYGtMxDJJAXnbChK8dbe0Iu4GNHY9zeSP0OaYJvVV9Nu/qtcZqgg+zKgLohdoI5QKXWcZ1JT/kNpIbnVnUYE0/AYZ8nMbjNiUsSD5BaDy+t9uuRxh+QCOrZDkYZw1EZioDpDoSR1XzrOac69QIag2XUU04rmWkR9/fbfwGzusTzfO2thk3vcZn+DzLqJqYy9ufkZeTGlqJnVC6//caakMtY475NSUKnGT+YoRsStXXI/9CVrpY8cPZ5eiFs34xGZWU1uhsx9UQ50pNeA7iqM6CIKpb4MPtqKDLIb83Bztz1VsfBJRMxer root@gitlab# to generate key pairs locally to facilitate ssh login
3) Test secret-free login
[root@gitlab ~] # git clone git@192.168.1.6:root/web-demo.git# confirms that there is no need to enter the password 3. Deploy Jenkins [root@jenkins ~] # wget https://mirrors-i.tuna.tsinghua.edu.cn/jenkins/redhat/jenkins-2.172-1.1.noarch.rpm[root@jenkins ~] # yum-y localinstall jenkins-2.172-1.1.noarch.rpm# to obtain the Jenkins package And install [root@jenkins ~] # systemctl start jenkins # to start Jenkins
Web page access
Since you just skipped the plug-in installation, you need to install it manually and download the plug-in package provided by yourself. Download link: https://pan.baidu.com/s/16fxH1J0WO6tW1bhPwmd60w
Extraction code: 432n
[root@jenkins ~] # rm-rf / var/lib/jenkins/plugins/ # delete the plug-in directory generated by the installation [root@jenkins ~] # tar zxf jenkins-plugins.tar.gz-C / var/lib/jenkins/# extract the plug-in package to the specified location [root@jenkins ~] # sed-I 's/http:\ /\ / updates.jenkinsci.org\ / download/https:\ /\ / mirrors.tuna.tsinghua. Edu.cn\ / jenkins/g' / var/lib/jenkins/updates/default.json & & sed-I 's/http:\ /\ / www.google.com/https:\ /\ / www.baidu.com/g' / var/lib/jenkins/updates/default.json# the path where jenkins will download the plug-in Change to domestic source [root@jenkins ~] # systemctl restart jenkins # restart Jenkins
Visit the web page again:
When you visit Jenkins again, you can find that it has become Chinese, because the plug-in contains Chinese plug-ins!
4. Jenkins integrates Gitlab [root@jenkins ~] # ssh-keygen # Jenkins service generation key pair [root@jenkins ~] # cat ~ / .ssh/id_rsa.pub # View public key information ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDbcFk7tkBes+S6BIVLxzLVj8X7bThDYscpY6uBeauHp+tPTL6CRVQDOlUcMRsyaX7o+a26iPd+yhJUaB+qT4iW1cVjhEiuKiR2NJSJdnEqccgcXWPJzIe+Owj76ofBtIhKqLGzwnYj6Lj0KmjUhn7tASu1bZ8hWubJ2ZQUottOW8KqjvHIb7q8OsGty9tsLVV3gD1XF1cE1s9rXY7XUFxDwtu1kfiA2XhSyJ3EmTWFlFlvaqzhQDBELWSVBz/4CihAfIp2eW7nx8TPXG0d0j+OwQYcccsarwkjHuc2IYRv4gVAhtRyXj8VQ7+LBsjYjfIMBTw4CFwQSTfZnWaa6Fcf root@jenkins
Store the public key information on gitlab:
[root@jenkins ~] # cat ~ / .ssh/id_rsa# to view the private key information of the Jenkins server, you need to store the private key information on the web page of Jenkins-BEGIN RSA PRIVATE KEY-MIIEpAIBAAKCAQEA23BZO7ZAXrPkugSFS8cy1Y/F+204Q2LHKWOrgXmrh7frT0y+gkVUAzpVHDEbMml+6Pmtuoj3fsoSVGgfqk+IltXFY4RIriokdjSUiXZxKnHIHF1jycyHvjsI++qHwbSISqixs8J2I+i49Cpo1IZ+7QErtW2fIVrmydmUFKLbTlvCqo7xyG+6vDrBrcvbbC1Vd4A9VxdXBNbPa12O11BcQ8LbtZH4gNl4UsidxJk1hZRZb2qs4UAwRC1klQc/+AooQHyKdnlu58fEz1xtHdI/jsEGHHHLGq8JIx7nNiGEb+IFQIbUcl4/FUO/iwbI2I3yDAU8OAhcEEk32Z1mmuhXHwIDAQABAoIBAQDXcb6qeY1JbaWrXLTiaXjnZHklGV6cCmcvo8PHIwXd8md9PAPvMtIBOUxGmY/yNtF7O2fuNHuJ6CuG45P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YMZ/iIRP6KH210ZgZjuJHQOUqeA954epRnbIosgrWz0G7qNjrpoHZkPcWXxmQ==-END RSA PRIVATE KEY-
To install the plug-ins required for jenkins integration with gitlab, download link: https://pan.baidu.com/s/1p_jh8X3ma46SEV_tKLKYbw
Extraction code: zoej
Install the plug-in, as shown below:
Upload the packages I provided in the following order: gitlab-oauth-- > gitlab-plugin-- > windows-slaves-- > ruby-runtime-- > gitlab-hook!
Jenkins source of Tsinghua University: https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json
The gitlab server submits the code to gitlab, and tests to pull the code:
[root@gitlab ~] # cd web-demo/ [root@gitlab web-demo] # git config-- global user.email "you@example.com" [root@gitlab web-demo] # git config-- global user.name "Your Name" [root@gitlab web-demo] # echo "123" > > 123.txt [root@gitlab web-demo] # git add. [root@gitlab web-demo] # git commit-m '123' [root@gitlab web-demo] # git push origin master
Build the Jenkins server:
Built successfully!
5. Deploy Nginx
Use Nginx to simulate the online environment!
[root@nginx ~] # yum install-y gcc gcc- C++ autoconf pcre pcre-devel make automake wget httpd-tools vim tree# is a minimally installed system, so install some necessary software [root@nginx ~] # vim / etc/yum.repos.d/nginx.repo# configure nginx's yum source Nginx official also has corresponding configuration information [nginx] name=nginx_repo baseurl= http://nginx.org/packages/centos/7/$basearch/gpgcheck=0enabled=1# this yum source is installed by default is the latest and stable version of nginx [root@nginx ~] # yum-y install nginx# installation nginx# does not require the version of nginx Just to use the access effect [root@nginx ~] # rm-rf / etc/nginx/conf.d/default.conf # Delete the default profile [root@nginx ~] # vim / etc/nginx/conf.d/server.conf# New profile server {listen 80 Location / {root / code/web; index index.html index.htm }} [root@nginx ~] # mkdir-p / code/web [root@nginx ~] # nginx-t [root@nginx ~] # systemctl start nginx VI. Automatic launch of Jenkins implementation code 1) script for Jenkins service [root@jenkins ~] # mkdir / scripts & & cd / scripts/ [root@jenkins scripts] # vim html_deploy.sh #! / bin/bashDATE=$ (date +% Y-%m-%d-%H-%M-%S) web_server= "192.168.1.8" Sdir=/optDdir=/code#1) enter the project directory Package the content, ${WORKSPACE} is the built-in variable of Jenkins Represents the absolute path to the build directory get_code () {cd ${WORKSPACE} & &\ tar zcf ${Sdir} / web-$ {DATE} .tar.gz. / *} # 2) copy the content to the web web page directory scp_web_server () {for hosts in ${web_server} do scp ${Sdir} / web-$ {DATE} .tar.gz root@$ {hosts}: / opt via scp Ssh root@$ {hosts} "mkdir-p ${Ddir} / web-$ {DATE} & &\ tar zxf ${Sdir} / web-$ {DATE} .tar.gz-C ${Ddir} / web-$ {DATE} rm-rf ${Ddir} / web & &\ ln-s ${Ddir} / web-$ {DATE} ${Ddir} / web "done} deploy () {get_code scp_web_server} deploy [root@jenkins scripts] # chmod + x html_deploy.sh [root@jenkins scripts] # ps-ef | grep jenkins# can see that the jenkins user is jenkinsjenkins 58626 11 11:23? 00:00:39 / etc/alternatives/java-Dcom.sun.akuma.Daemon=daemonized-Djava.awt.headless=true-DJENKINS_HOME= / var/lib/jenkins-jar / usr/lib/jenkinsjenkins.war-- logfile=/var/log/jenkins/jenkins.log-- webroot=/var/cache/jenkins/war-- daemon-- debug=5-- handlerCountMax=100-- handlerCountMaxIdle=20root 61336 2046 0 12:06 pts/0 00:00:00 grep-- color=auto jenkins [root@jenkins scripts] # vim / etc/sysconfig/jenkins JENKINS_USER= "root" # to prevent permission issues Directly change the running user of jenkins to root [root@jenkins scripts] # systemctl restart jenkins# restart the jenkins service [root@jenkins scripts] # ssh-copy-id root@192.168.1.8# configuration Jenkins can log in to the nginx server without secret 2) git server edit the web page code and upload: [root@gitlab web-demo] # echo "lvzhenjiang" > > index.html [root@gitlab web-demo] # git add. [root@gitlab web-demo] # git commit -m "first" [root@gitlab web-demo] # git push origin master
If you are interested, you can build the console output!
Visit nginx for testing!
Confirm that it is the code information just submitted by the gitlab server!
[root@nginx] # ll / code # View the specific process of web page directory implementation # you can see that the real web page directory is the total amount of links in the past 0lrwxrwxrwx 1 root root 29 February 25 19:37 web- > / code/web-2020-02-25-19-37-13drwxr-xr-x 2 root root 39 February 25 19:37 web-2020-02-25-19-37-13
There are still many areas that need to be improved in this way of publishing, such as fallback, and then using the tag way to release!
7. Jenkins realizes code automatic deployment, fallback and repeated construction.
Let the project support tag online, so that we can make a distinction!
1) the git server creates several tag tags and uploads them to gitlab: [root@gitlab ~] # cd web-demo/ [root@gitlab web-demo] # echo "lvzhenjiang-version-v1.1" > index.html [root@gitlab web-demo] # git add. [root@gitlab web-demo] # git commit-m "v1.1" [root@gitlab web-demo] # git push origin master [root@gitlab web-demo] # git tag-a "v1.1"-m "v1 .1 "[root@gitlab web-demo] # git push origin v1.1 [root@gitlab web-demo] # echo" lvzhenjiang-version-v1.2 "> index.html [root@gitlab web-demo] # git add. [root@gitlab web-demo] # git commit-m" v1.2 "[root@gitlab web-demo] # git push origin master [root@gitlab web-demo] # git tag-a" v1.2 "m" v1.2 "[root@gitlab web-demo] # git Push origin v1.2 [root@gitlab web-demo] # echo "lvzhenjiang-version-v1.3" > index.html [root@gitlab web-demo] # git add. [root@gitlab web-demo] # git commit-m "v1.3" [root@gitlab web-demo] # git push origin master [root@gitlab web-demo] # git tag-a "v1.3"-m "v1.3" [root@gitlab web-demo] # git push origin v1.32) Jenkins server installs plug-ins and configures:
To use this method, you need to install the plug-in: Git Parameter.
Installation method: system management-> plug-in management-- > optional plug-in-search Git Parameter-- > direct installation!
After the installation of [root@jenkins ~] # systemctl restart jenkins# is complete, restart Jenkins! [root@jenkins ~] # cd / scripts/ [root@jenkins scripts] # vim html_deploy_tag.sh # Optimization script #! / bin/bashDATE=$ (date +% Y-%m-%d-%H-%M-%S) web_server= "192.168.1.8" Sdir=/optDdir=/codeName=$ {DATE}-${git_version} # ${git_version} is the variable defined in the jenkins interface # 1) enter the project directory Packaging content # ${WORKSPACE} is a built-in variable for Jenkins Represents the absolute path to the build directory get_code () {cd ${WORKSPACE} & &\ tar zcf ${Sdir} / web-$ {Name} .tar.gz. / *} # 2) copy the content to the web web page directory scp_web_server () {for hosts in ${web_server} do scp ${Sdir} / web-$ {Name} .tar.gz root@$ {hosts}: / opt via scp Ssh root@$ {hosts} "mkdir-p ${Ddir} / web-$ {Name} & &\ tar zxf ${Sdir} / web-$ {Name} .tar.gz-C ${Ddir} / web-$ {Name} rm-rf ${Ddir} / web & &\ ln-s ${Ddir} / web-$ {Name} ${Ddir} / web "done} deploy () {get_code scp_web_server} deploy [root@jenkins scripts] # chmod + x html_deploy_tag.sh
Next:
Visit nginx:
[root@nginx] # ll / code # so you can clearly see which version of the total usage 0lrwxrwxrwx 1 root root 34 February 25 20:21 web- > / code/web-2020-02-25-20-21-18-v1.3drwxr-xr-x 2 root root 39 February 25 19:37 web-2020-02-25-19-37-13drwxr-xr-x 2 root root 39 February 25 20:21 web-2020-02-25-20-21-18-v1.3
Deployed here. The problem of fallback is still unsolved! For example: deploying the v1.3 version twice will result in two v1.3 directories!
3) solve the problem of version fallback and repeated construction [root@jenkins scripts] # vim html_deploy_tag_rollback.sh # optimization script Support fallback #! / bin/bashDATE=$ (date +% Y-%m-%d-%H-%M-%S) web_server= "192.168.1.8" Sdir=/optDdir=/codeName=$ {DATE}-${git_version} # ${git_version} is the variable defined in the jenkins interface # 1) enter the project directory and package the content # ${WORKSPACE} is the built-in variable of Jenkins Represents the absolute path to the build directory get_code () {cd ${WORKSPACE} & &\ tar zcf ${Sdir} / web-$ {Name} .tar.gz. / *} # 2) copy the content to the web web page directory scp_web_server () {for hosts in ${web_server} do scp ${Sdir} / web-$ {Name} .tar.gz root@$ {hosts}: / opt via scp Ssh root@$ {hosts} "mkdir-p ${Ddir} / web-$ {Name} & &\ tar zxf ${Sdir} / web-$ {Name} .tar.gz-C ${Ddir} / web-$ {Name} rm-rf ${Ddir} / web & &\ ln-s ${Ddir} / web-$ {Name} ${Ddir} / web "done} rollback () {back_file=$ (ssh root@$ {web_server}" find / code/-maxdepth 1-type d-name "web-*-$ {git_version}") for hosts in ${web_server} do ssh root@$ {hosts} "rm-rf ${Ddir} / web & &\ ln-s ${back_file} ${Ddir} / web" done} deploy () { Get_code scp_web_server} # determine whether this version of commit has been deployed before If there is no deployment, deploy, if there is, prompt that it has been deployed and then exit # if it is a fallback, there is no restriction on if [${deploy_env} = = "deploy"] Then if [${GIT_COMMIT} = = ${GIT_PREVIOUS_SUCCESSFUL_COMMIT}]; then echo "you have deployed this version of ${git_version}" exit 1 else deploy fielif [${deploy_env} = = "rollback"]; then rollbackfi [root@jenkins scripts] # chmod + x html_deploy_tag_rollback.sh
Next, configure:
Test:
Web page:
Perform a fallback operation:
If you are interested, you can build the console output!
Web page:
[root@nginx] # ll / code # you can see that the total amount of directories created only once v1.3 0lrwxrwxrwx 1 root root 34 February 25 20:46 web- > / code/web-2020-02-25-20-21-18-v1.3drwxr-xr-x 2 root root 39 February 25 19:37 web-2020-02-25-19-37-13drwxr-xr-x 2 root root 39 February 25 20:21 web-2020-02- 25-20-21-18-v1.3drwxr-xr-x 2 root root 39 February 25 20:46 web-2020-02-25-20-46-15-v1.1
Repeat build, fallback problem solving!
-this is the end of this article. Thank you for reading-
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.