In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
In line with the principle that it is easy to take a big step, the original intention of the platform design is to call open source products and definitely not to do it on its own, so that the platform can only be used as an integrated dispatching center, without considering the specific function implementation logic.
The use of Jenkins can be traced back to a company I knew a long time ago, when Zhang Xiaofeng, the technical director at that time, taught me about the continuous integration engine Hudson, later Jenkins. In the past, the company used to do agile development with Jenkins and Maven,Ant, but I just played tricks and used some of the most basic functions to release updates to the system.
Traditional operation and maintenance release
SVN move out code-locally packed into tar package (rar package)-sftp uploaded to the server
Jenkins build release project-SVN relocation code-distribute directly to the server through the SFTP plug-in
Advantages: rough and simple
Disadvantages:
Efficiency: it is no problem to release a single server online, and the efficiency of multi-server distribution is reduced. If the network is a unified entry login (that is, when the fortress machine is a single entry), the release work will become extremely difficult.
Security risk: the password of the SSH account of the second release mode must be stored on Jenkins, although not in plain text, but. Also faced with 22 ports of this server to be open to Jenkins, security is a problem.
Adopt the system scheme: YUM
My idea at that time: the company was a third-level insurance unit. When I made the private network rules, I strongly recommended that the login scope of SSH should be limited, and the unified entry could greatly reduce the possibility of being * springboard * *, so I thought of using YUM update method:
Release: after the code is moved out of SVN, it is packed into a RPM package (FPM is strongly recommended)
Update: through the YUM feature, the updated package keeps the version number + 1 each time, such as test-519-1.x86_64. The server only needs to execute the following 2 commands at a time.
Bash yum clean all yum install test
Batch operation: through Saltstack to notify each server to carry out Yum action.
Fallback: it is even easier. The rough point can be directly mv test-518-1.x86_64 test-520-1.x86_64 on the YUM server. Of course, the Sven point is also the API for callback Jenkins, using TAG to roll back.
Specific logic and implementation
So let's first solve the problem of typing RPM packages and updating YUM sources (my Jenkins is the YUM source of our private network):
Configure Jenkins
First of all, we need to open batch tasks (batch processing, which is actually a script) in Jenkins, instead of using Jenkins's own Baidu.
Click Add post-build action- to select Invoke batch tasks
Fill in the script in Batch tasks
Bashmkdir-p / home/release/$JOB_NAME & &\ fpm-s dir-t rpm-n $JOB_NAME-v $BUILD_NUMBER-prefix / home/www/bbs-C / var/lib/jenkins/workspace/$JOB_NAME-p / home/release/$JOB_NAME. / & &\ createrepo-- update / home/release/$JOB_NAME/ & &\ curl-d "job_id=$JOB_NAME" http://salt master IP/cmdb/salt_jenkins_post/
The general meaning of this Jenkins script is:
Create / home/release/$JOB_NAME directory
Then type the code of / var/lib/jenkins/workspace/$JOB_NAME (Jenkins project workspace) into a RPM package named $JOB_NAME and version number $JOB_NAME, which is stored in the / home/release/$JOB_NAME directory and unzipped to the / home/www/bbs directory.
Then createrepo-- update / home/release/$JOB_NAME/ notifies the update to update the YUM source.
Finally, call back my Salt interface (the function of this API is to check which publishing hosts correspond to this project, and then execute yum install commands on these hosts, whether it is brainless ~)
Saltstack Interface (saltjenkinspost)
Since my platform is the same as Salt master (mainly convenient), I don't need to call API and directly call some commands such as yum install that have been encapsulated by the local Saltstack.
Upgradeavailable verifies that the Yum source is updated
Install installation
Modrepo creates a yum source
Getrepo verifies that the Yum source exists
Intro executes some commands after the update
After each step of the interface processing, I will verify whether the returned host is the same as the project host preset in the database. Only one of the returned hosts will proceed to the next step (for example, the interface returns the results executed by only one server through salt, and the project in the database is two servers. I will think there is something wrong with this release and interrupt it.) this is also to prevent some hosts from updating successfully and some hosts not updating successfully. What needs to be done after leading to a poor online user experience (which has been successfully transferred from Shenxin to the load balancer API) is to publish in grayscale, remove one from the load and then update the other, and then add the load again after the update.
Import jsonfrom django.http import HttpResponsefrom django.views.decorators.csrf import csrf_exempttry: import salt.clientexcept: passfrom cmdb.models import * class Salt_jenkins: def _ _ init__ (self, host_list Job): self.client = salt.client.LocalClient () self.host_list = host_list self.type = type self.job = job def upgradeavailable (self): "check whether the target host group project has a new version update on yum, and return the host that can be updated" ret = self.client.cmd ('% s% self.host_list, 'pkg.upgrade_available' " ['% s% self.job], expr_form='list' Ret='return_redis') true_hostlist = [] for host in ret.keys (): if ret ['% s'% host]: true_hostlist.append (host) else: pass return true_hostlist def install (self): "" YUM installation project RPM package "" ret= self. Client.cmd ('% s% self.host_list) 'pkg.install', ['% s% self.job], expr_form='list' Ret='return_redis') true_hostlist = [] for host in ret.keys (): if ret ['% s'% host]! = {}: install_ret = ret ['% s'% host] ['% s'% self.job] if install_ret! ='': true_hostlist.append (host) ) else: pass else: pass return true_hostlist def modrepo (self): "create project YUM source" ret = self.client.cmd ('% slots% self.host_list ") 'pkg.mod_repo', [' repo=%s'% self.job,'baseurl= http://172.18.11.98/release/%s'% self.job,'enabled=1','gpgcheck=0','name=%s'% self.job,'priority=10'], expr_form='list' Ret='return_redis') true_hostlist = [] for host in ret.keys (): if type (ret ['% s'% host]) = = dict: true_hostlist.append (host) else: pass return true_hostlist def getrepo (self): "" verify whether the project YUM source exists "" Ret = self.client.cmd ('% slots% self.host_list 'pkg.get_repo', ['repo=%s'% self.job], expr_form='list' Ret='return_redis') true_hostlist = [] for host in ret.keys (): if ret ['% s'% host]! = {}: true_hostlist.append (host) else: pass return true_hostlist def intro (self): "" execute commands within svn_intro "" Command = Svn.objects.get (svn_name = self.job). Svn_intro ret = self.client.cmd ('% slots% self.host_list 'cmd.run', ['%% command], expr_form='list',ret='return_redis') return ret@csrf_exempt def salt_jenkins_post (request): if request.method = 'POST': ip = request.META.get ("REMOTE_ADDR") None) if ip = '172.18.11.98: job = request.POST.get (' job_id') job_hosts = Svn.objects.get (svn_name=job). Svn_hosts if job = 'cms_template.youth.cn' or job = =' cms_assets.youth.cn': pass else: "" "initialize Salt_jenkins" salt_jenkins = Salt_jenkins (job_hosts Job) "" Target host checks whether the Yum source exists "if sorted (salt_jenkins.getrepo ()) = = sorted (str (job_hosts) .split (')" ): pass else: "" create a YUM source "" salt_jenkins.modrepo () "destination host checks whether the Yum source is updated" if sorted (salt_jenkins.upgradeavailable ()) = = sorted (str (job_hosts) .split (') " ): if sorted (salt_jenkins.install ()) = = sorted (str (job_hosts) .split (' ): "salt_jenkins.intro () return HttpResponse ('install success')" salt_jenkins.install () "Target host executes commands" Else: return HttpResponse ('install fail') else: return HttpResponse (' upgradeavailable fail') else: return HttpResponse ('ip deny') else: return HttpResponse ('get deny')
Later, we will introduce the status return of the release, that is, the MasterEvent of Saltstack and the innovative release of the project through Jenkins combined with Saltstack.
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.