Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Initialization script

2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

#! / usr/bin/env python

Coding: utf-8--

Import glob, os,shutil,zipfile,socket,datetime,time,sys

Def check_dir (filedir):

If os.path.exists (filedir):

Pass

Else:

The print 'ERROR:::%s directory does not exist, please detect'% filedir

Exit (1)

Def list_file (filedir):

FilesRead = r'%s'%filedir

List = glob.glob (filesRead)

Filelist = []

For i in list:

Filelist.append (I)

Return filelist

Class HS:

Def init (self,yy_ip,db_ip):

Self.yy_ip = yy_ip

Self.db_ip = db_ip

Self.redispw = '5136BA64F8D63BFB'

# self.Date = time.strftime ('% ymuri% mmurc% danjinjie time.localtime (time.time ()

Self.RootPath ='/ root/deployment'

Self.DockerPath = self.RootPath +'/ docker/docker-ce/docker-ce'

Self.SoftwarePath = self.RootPath +'/ software'

Self.SoftwareOraclePath = self.RootPath +'/ oracle'

Self.TmpFile ='/ tmp/hs_intall_tmp.txt'

Check_dir (self.RootPath) shell = "root soft nofile 65535\ nroot hard nofile 65535\ n * soft nofile 65535\ n * hard nofile 65535\ n" self.check_file_bak_writefile ("/ etc/security/limits.conf", shell) def file_write (self,filename,shell): file_obj = open (filename,'a+') file_obj.write (shell) file_obj.close () def check_file_bak_shell (self,file1 Shell): if os.path.exists ('% s.bak'%file1): print 'INFO:::%s.bak backup exists No more backup'% (file1) else: os.system ('cp% s% s.bakeries% (file1,file1)) print 'INFO:::%s has been backed up with the file name:% s.bakelite% (file1,file1) os.system (shell) def check_file_bak_writefile (self,file1,shell): if os.path.exists ('% s.bakelite% (file1)): print 'INFO:::%s.bak backup exists No more backup'% (file1) else: os.system ('cp% s% s.bakeries% (file1,file1)) print 'INFO:::%s backup completed The file name is% s.bakelite% (file1,file1) self.file_write (file1,shell) def grep_image (self,depname): lines = os.popen ("docker images | grep'% s'>% s"% (depname,self.TmpFile)) .read () .strip () check_dir (self.TmpFile) with open (self.TmpFile) as f: for line in f: REPOSITORY,TAG,IMAGEID,CREAT1,CREAT2,CREAT3,SIZE = map (str) Line.split () Image=REPOSITORY+':'+TAG return Image def install_docker (self): check_dir (self.DockerPath) os.chdir (self.DockerPath) print 'INFO:::yum docker start' os.system ('yum install-y. / * > / dev/null 2 > & 1') # os.system (' yum install-y. / *') print 'INFO:::yum docker is over' os.chdir (self.RootPath+'/docker') check_dir ('daemon.json') os.system (' mkdir-p / etc/docker/ & &\ cp daemon.json / etc/docker/') check_dir ('/ usr/lib/systemd/system/docker.service') shell = r "sed-I'/ ExecStart/i\ ExecStartPost=\ / bin\ / bash\ / root\ / onDockerStart.sh' / usr/lib/systemd/system/docker.service" self.check_ File_bak_shell ("/ usr/lib/systemd/system/docker.service" Shell) os.system ('\ cp onDockerStart.sh / root/ & & chmod + x / root/onDockerStart.sh & & systemctl daemon-reload') self.check_file_bak_shell ('/ root/.bashrc' 'cat / root/deployment/docker/bash_docker.sh > > / root/.bashrc') os.system (' service docker start') print 'INFO:::docker installed' def init_yy (self): try: os.system ('docker network create-- subnet=172.21.0.0/16 huoshu 2 > / dev/null') except: pass finally: print' INFO:::huoshu segment set up'AA = list_file ('% s/*.tar'%self.SoftwarePath) print 'INFO::: starts load image mirroring' for i in AA: os.system ('docker load

< %s'%i) check_dir(self.SoftwarePath+'/drgsburster') check_dir(self.SoftwarePath+'/front') print 'INFO:::配置drgsburster文件夹' os.system('\cp -r %s/drgsburster /opt'%self.SoftwarePath) print 'INFO:::配置front文件夹' os.system('mkdir -p /opt/apps/ && \cp -r %s/front /opt/apps/'%self.SoftwarePath)def init_db(self): AA = list_file('%s/*.tar'%self.SoftwareOraclePath) print 'INFO:::开始load image镜像' for i in AA: os.system('docker load < %s'%i) AA = list_file('%s/*.tar.gz'%self.SoftwareOraclePath) for i in AA: print 'INFO:::开始拷贝%s数据文件至/home'%i os.system('\cp %s /home/'%i) print 'INFO:::开始解压oracle数据文件' os.system('rm -rf /home/oracle') os.system('cd /home/ && tar -zxvf %s >

/ dev/null 2 > & 1'% I) def start_yy (self): NginxImage = self.grep_image ('nginx') print' INFO:::docker run launch:% s'%NginxImage os.system ('docker stop nginx 2 > / dev/null & & docker rm nginx 2 > / dev/null') os.system ("docker run-d-restart=always-net huoshu-ip=172.21.0.2\"

-p 80-120 80-120-v / opt/apps/front:/opt/apps\

-name nginx-v / opt/apps/front/nginx.conf.d:/etc/nginx/conf.d\

-v / var/log/nginx:/var/log/nginx\

S "NginxImage)

RedisImage = self.grep_image ('redis') print 'INFO:::docker run launch:% s'%RedisImage os.system (' docker stop redis 2 > / dev/null & & docker rm redis 2 > / dev/null') os.system ("docker run-d-restart=always\"

-- net huoshu-- ip=172.21.0.3-p 6379\

-- name redis\

-v / var/log/redis:/var/log/redis\

S "RedisImage)

Redis4Image = self.grep_image ('redis4') print' INFO:::docker run launch:% s'%Redis4Image os.system ('docker stop redis4 2 > / dev/null & & docker rm redis4 2 > / dev/null') os.system ("docker run-d-restart=always\"

-- net huoshu-- ip=172.21.1.17-p 7379Viru 7379\

-- name redis4\

-v / var/log/redis4:/var/log/redis\

S "RedisImage)

HdcImage = self.grep_image ('hdc-manager') print' INFO:::docker run launch:% s'%HdcImage os.system ('docker stop hdc-manager 2 > / dev/null & & docker rm hdc-manager 2 > / dev/null') os.system ("docker run-d-restart=always-name hdc-manager\"

-- net huoshu-- ip=172.21.1.2-p 8180 purl 8080\

-v / var/log/hdc-manager:/usr/local/apache-tomcat-8.5.4/logs\

-e ORACLE_ADDR=%s:1521:orcl\

-e LANG='en_US.UTF-8'\

-e HDC_ADDR=%s\

-e REDISPWD=%s\

-e PINPOINT=NO\

S "% (self.db_ip,self.yy_ip,self.redispw,HdcImage))

EtlImage = self.grep_image ('etlloader') print' INFO:::docker run launch:% s'%EtlImage os.system ('docker stop etlloader 2 > / dev/null & & docker rm etlloader 2 > / dev/null') os.system ("docker run-d-restart=always-name etlloader\"

-- net huoshu-- ip 172.21.1.4-p 8380VR 8080\

-e ORACLE_ADDR=%s:1521:orcl\

-e LANG='en_US.UTF-8'\

-e HDC_ADDR=%s\

-e REDISPWD=%s\

-e PINPOINT=NO\

-v / var/log/etlloader:/opt/etlloader/consolelog\

S "% (self.db_ip,self.yy_ip,self.redispw,EtlImage))

CasImage = self.grep_image ('cas') print' INFO:::docker run launch:% s'%CasImage os.system ('docker stop cas 2 > / dev/null & & docker rm cas 2 > / dev/null') os.system ("docker run-d-restart=always-name cas\"

-- net huoshu-- ip=172.21.1.6-p 8480

-v / var/log/cas:/usr/local/apache-tomcat-8.5.4/logs\

-e ORACLE_ADDR=%s:1521:orcl\

-e LANG='en_US.UTF-8'\

-e DBUSER=portal\

-e DBPWD=portal\

-e REDISPWD=%s\

S "% (self.db_ip,self.redispw,CasImage))

DrgSmsImage = self.grep_image ('drgsms') print' INFO:::docker run launch:% s'%DrgSmsImage os.system ('docker stop drgsms 2 > / dev/null & & docker rm drgsms 2 > / dev/null') os.system ("docker run-d-restart=always-name drgsms\"

-- net huoshu-- ip 172.21.1.21-p 8996purl 9996\

-e ORACLE_ADDR=%s:1521:orcl\

-e LANG='en_US.UTF-8'\

-e HDC_ADDR=%s\

-e REDISPWD=%s\

-e PINPOINT=NO\

-v / var/log/drgsms:/opt/drgsms/log\

S "% (self.db_ip,self.yy_ip,self.redispw,DrgSmsImage))

DrgbursterImage = self.grep_image ('drgburster') print' INFO:::docker run launch:% s'%DrgbursterImage os.system ('docker stop drgburster 2 > / dev/null & & docker rm drgburster 2 > / dev/null') os.system ("docker run-d-restart=always-name drgburster\"

-- net huoshu-- ip 172.21.1.31-p 10668 purl 10668\

-e LANG='en_US.UTF-8'\

-v / opt/drgsburster:/opt/drgsburster\

-v / var/log/drgburster/:/opt/drgburster/log\

S "DrgbursterImage)

Def start_db (self): OracleImage = self.grep_image ('oracle') print' INFO:::docker run launch:% s'%OracleImage os.system ('docker stop oracle 2 > / dev/null & & docker rm oracle 2 > / dev/null') os.system ("docker run-d-privileged-restart=always\"

-- shm-size 2147483648\

-- name oracle\

-p 1521VR 1521\

-v / home/oracle:/opt/oracle\

S "OracleImage)

Print 'INFO::: Open Database'

Os.system ('/ root/onDockerStart.sh > / dev/null 2 > & 1')

Print 'INFO::: database startup complete'

Def start_db_one_server (self): OracleImage = self.grep_image ('oracle') print' INFO:::docker run launch:% s'%OracleImage os.system ('docker stop oracle 2 > / dev/null & & docker rm oracle 2 > / dev/null') os.system ("docker run-d-privileged-restart=always\"

-- net huoshu-- ip=172.21.0.4\

-- shm-size 2147483648\

-- name oracle\

-p 1521VR 1521\

-v / home/oracle:/opt/oracle\

S "OracleImage)

Print 'INFO::: Open Database'

Os.system ('/ root/onDockerStart.sh > / dev/null 2 > & 1')

Print 'INFO::: database startup complete'

Def clear (self): print 'INFO::: closes and deletes all mirrors' os.system ('docker kill $(docker ps-Q) > / dev/null 2 > & 1; docker rm $(docker ps-a-Q) > / dev/null 2 > & 1 ') print' INFO::: cleans up the file 'list_dir = [' / var/log/nginx','/var/log/redis','/var/log/redis4','/var/log/hdc-manager','/var/log/etlloader'\

,'/ var/log/cas','/var/log/drgsms','/var/log/drgburster','/opt/apps/','/root/onDockerStart.sh','/home/oracle','/home/oracle.*.tar.gz']

For i in list_dir:

Os.system ('rm-rf% slots% I)

Print 'INFO::: restore docker boot'

If check_dir ('/ usr/lib/systemd/system/docker.service.bak'):

Pass

Else:

Os.system ('\ cp / usr/lib/systemd/system/docker.service.bak / usr/lib/systemd/system/docker.service')

Os.system ('systemctl daemon-reload')

If name = 'main':

If len (sys.argv) = = 4:

Yy_ip = sys.argv [1]

Db_ip = sys.argv [2]

Dep = sys.argv [3]

Hs = HS (yy_ip,db_ip)

If dep = 'install_yy':

Hs.install_docker ()

Hs.init_yy ()

Hs.start_yy ()

Elif dep = 'install_db':

Hs.install_docker ()

Hs.init_db ()

If db_ip = = yy_ip:

Hs.start_db_one_server ()

Else:

Hs.start_db ()

Elif dep = 'clear': hs.clear () else: print' Usage: (. / dep.py application ip database ip install_yy or install_db or clear) 'else: print' Usage: (. / dep.py application ip database ip install_yy or install_db or clear) 'exit (1)

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report