install.sh 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. #!/bin/sh
  2. workDir=`dirname $0`
  3. workDir=`cd ${workDir};pwd`
  4. source ${workDir}/conf/config/run_config.conf
  5. source ${workDir}/conf/config/install_config.conf
  6. # mysql配置
  7. # mysql 地址,端口
  8. mysqlHost="192.168.xx.xx:3306"
  9. # mysql 数据库名称
  10. mysqlDb="escheduler"
  11. # mysql 用户名
  12. mysqlUserName="xx"
  13. # mysql 密码
  14. mysqlPassword="xx"
  15. # hadoop 配置
  16. # namenode地址,支持HA,需要将core-site.xml和hdfs-site.xml放到conf目录下
  17. namenodeFs="hdfs://mycluster:8020"
  18. # resourcemanager HA配置,如果是单resourcemanager,这里为空即可
  19. yarnHaIps="192.168.xx.xx,192.168.xx.xx"
  20. # 如果是单 resourcemanager,只需要配置一个主机名称,如果是resourcemanager HA,则默认配置就好
  21. singleYarnIp="ark1"
  22. # common 配置
  23. # 程序路径
  24. programPath="/tmp/escheduler"
  25. #下载路径
  26. downloadPath="/tmp/escheduler/download"
  27. # 任务执行路径
  28. execPath="/tmp/escheduler/exec"
  29. # hdfs根路径
  30. hdfsPath="/escheduler"
  31. # 是否启动hdfs,如果启动则为true,不启动设置为false
  32. hdfsStartupSate="true"
  33. # SHELL环境变量路径
  34. shellEnvPath="/opt/.escheduler_env.sh"
  35. # Python换将变量路径
  36. pythonEnvPath="/opt/escheduler_env.py"
  37. # 资源文件的后缀
  38. resSuffixs="txt,log,sh,conf,cfg,py,java,sql,hql,xml"
  39. # 开发状态,如果是true,对于SHELL脚本可以在execPath目录下查看封装后的SHELL脚本,如果是false则执行完成直接删除
  40. devState="true"
  41. # zk 配置
  42. # zk集群
  43. zkQuorum="192.168.xx.xx:2181,192.168.xx.xx:2181,192.168.xx.xx:2181"
  44. # zk根目录
  45. zkRoot="/escheduler"
  46. # 用来记录挂掉机器的zk目录
  47. zkDeadServers="/escheduler/dead-servers"
  48. # masters目录
  49. zkMasters="/escheduler/masters"
  50. # workers目录
  51. zkWorkers="/escheduler/workers"
  52. # zk master分布式锁
  53. mastersLock="/escheduler/lock/masters"
  54. # zk worker分布式锁
  55. workersLock="/escheduler/lock/workers"
  56. # zk master容错分布式锁
  57. mastersFailover="/escheduler/lock/failover/masters"
  58. # zk worker容错分布式锁
  59. workersFailover="/escheduler/lock/failover/masters"
  60. # zk session 超时
  61. zkSessionTimeout="300"
  62. # zk 连接超时
  63. zkConnectionTimeout="300"
  64. # zk 重试间隔
  65. zkRetrySleep="100"
  66. # zk重试最大次数
  67. zkRetryMaxtime="5"
  68. # master 配置
  69. # master执行线程最大数,流程实例的最大并行度
  70. masterExecThreads="100"
  71. # master任务执行线程最大数,每一个流程实例的最大并行度
  72. masterExecTaskNum="20"
  73. # master心跳间隔
  74. masterHeartbeatInterval="10"
  75. # master任务提交重试次数
  76. masterTaskCommitRetryTimes="5"
  77. # master任务提交重试时间间隔
  78. masterTaskCommitInterval="100"
  79. # master最大cpu平均负载,用来判断master是否还有执行能力
  80. masterMaxCupLoadAvg="10"
  81. # master预留内存,用来判断master是否还有执行能力
  82. masterReservedMemory="1"
  83. # worker 配置
  84. # worker执行线程
  85. workerExecThreads="100"
  86. # worker心跳间隔
  87. workerHeartbeatInterval="10"
  88. # worker一次抓取任务数
  89. workerFetchTaskNum="10"
  90. # worker最大cpu平均负载,用来判断master是否还有执行能力
  91. workerMaxCupLoadAvg="10"
  92. # worker预留内存,用来判断master是否还有执行能力
  93. workerReservedMemory="1"
  94. # api 配置
  95. # api 服务端口
  96. apiServerPort="12345"
  97. # api session 超时
  98. apiServerSessionTimeout="7200"
  99. # api 上下文路径
  100. apiServerContextPath="/escheduler/"
  101. # spring 最大文件大小
  102. springMaxFileSize="1024MB"
  103. # spring 最大请求文件大小
  104. springMaxRequestSize="1024MB"
  105. # api 最大post请求大小
  106. apiMaxHttpPostSize="5000000"
  107. # alert配置
  108. # 邮件协议
  109. mailProtocol="SMTP"
  110. # 邮件服务host
  111. mailServerHost="smtp.exmail.qq.com"
  112. # 邮件服务端口
  113. mailServerPort="25"
  114. # 发送人
  115. mailSender="xxxxxxxxxx"
  116. # 发送人密码
  117. mailPassword="xxxxxxxxxx"
  118. # 下载Excel路径
  119. xlsFilePath="/opt/xls"
  120. # conf/config/install_config.conf配置
  121. # 安装路径
  122. installPath="/data1_1T/escheduler"
  123. # 部署用户
  124. deployUser="escheduler"
  125. # 安装hosts
  126. ips="ark0,ark1,ark2,ark3,ark4"
  127. # conf/config/run_config.conf配置
  128. # 运行Master的机器
  129. masters="ark0,ark1"
  130. # 运行Worker的机器
  131. workers="ark2,ark3,ark4"
  132. # 运行Alert的机器
  133. alertServer="ark3"
  134. # 运行Api的机器
  135. apiServers="ark1"
  136. # 1,替换文件
  137. echo "1,替换文件"
  138. sed -i '' "s#spring.datasource.url.*#spring.datasource.url=jdbc:mysql://${mysqlHost}/${mysqlDb}?characterEncoding=UTF-8#g" conf/dao/data_source.properties
  139. sed -i '' "s#spring.datasource.username.*#spring.datasource.username=${mysqlUserName}#g" conf/dao/data_source.properties
  140. sed -i '' "s#spring.datasource.password.*#spring.datasource.password=${mysqlPassword}#g" conf/dao/data_source.properties
  141. sed -i '' "s#org.quartz.dataSource.myDs.URL.*#org.quartz.dataSource.myDs.URL=jdbc:mysql://${mysqlHost}/${mysqlDb}?characterEncoding=UTF-8#g" conf/quartz.properties
  142. sed -i '' "s#org.quartz.dataSource.myDs.user.*#org.quartz.dataSource.myDs.user=${mysqlUserName}#g" conf/quartz.properties
  143. sed -i '' "s#org.quartz.dataSource.myDs.password.*#org.quartz.dataSource.myDs.password=${mysqlPassword}#g" conf/quartz.properties
  144. sed -i '' "s#fs.defaultFS.*#fs.defaultFS = ${namenodeFs}#g" conf/common/hadoop/hadoop.properties
  145. sed -i '' "s#yarn.resourcemanager.ha.rm.ids.*#yarn.resourcemanager.ha.rm.ids=${yarnHaIps}#g" conf/common/hadoop/hadoop.properties
  146. sed -i '' "s#yarn.application.status.address.*#yarn.application.status.address=http://${singleYarnIp}:8088/ws/v1/cluster/apps/%s#g" conf/common/hadoop/hadoop.properties
  147. sed -i '' "s#data.basedir.path.*#data.basedir.path=${programPath}#g" conf/common/common.properties
  148. sed -i '' "s#data.download.basedir.path.*#data.download.basedir.path=${downloadPath}#g" conf/common/common.properties
  149. sed -i '' "s#process.exec.basepath.*#process.exec.basepath=${execPath}#g" conf/common/common.properties
  150. sed -i '' "s#data.store2hdfs.basepath.*#data.store2hdfs.basepath=${hdfsPath}#g" conf/common/common.properties
  151. sed -i '' "s#hdfs.startup.state.*#hdfs.startup.state=${hdfsStartupSate}#g" conf/common/common.properties
  152. sed -i '' "s#escheduler.env.path.*#escheduler.env.path=${shellEnvPath}#g" conf/common/common.properties
  153. sed -i '' "s#escheduler.env.py.*#escheduler.env.py=${pythonEnvPath}#g" conf/common/common.properties
  154. sed -i '' "s#resource.view.suffixs.*#resource.view.suffixs=${resSuffixs}#g" conf/common/common.properties
  155. sed -i '' "s#development.state.*#development.state=${devState}#g" conf/common/common.properties
  156. sed -i '' "s#zookeeper.quorum.*#zookeeper.quorum=${zkQuorum}#g" conf/zookeeper.properties
  157. sed -i '' "s#zookeeper.escheduler.root.*#zookeeper.escheduler.root=${zkRoot}#g" conf/zookeeper.properties
  158. sed -i '' "s#zookeeper.escheduler.dead.servers.*#zookeeper.escheduler.dead.servers=${zkDeadServers}#g" conf/zookeeper.properties
  159. sed -i '' "s#zookeeper.escheduler.masters.*#zookeeper.escheduler.masters=${zkMasters}#g" conf/zookeeper.properties
  160. sed -i '' "s#zookeeper.escheduler.workers.*#zookeeper.escheduler.workers=${zkWorkers}#g" conf/zookeeper.properties
  161. sed -i '' "s#zookeeper.escheduler.lock.masters.*#zookeeper.escheduler.lock.masters=${mastersLock}#g" conf/zookeeper.properties
  162. sed -i '' "s#zookeeper.escheduler.lock.workers.*#zookeeper.escheduler.lock.workers=${workersLock}#g" conf/zookeeper.properties
  163. sed -i '' "s#zookeeper.escheduler.lock.failover.masters.*#zookeeper.escheduler.lock.failover.masters=${mastersFailover}#g" conf/zookeeper.properties
  164. sed -i '' "s#zookeeper.escheduler.lock.failover.workers.*#zookeeper.escheduler.lock.failover.workers=${workersFailover}#g" conf/zookeeper.properties
  165. sed -i '' "s#zookeeper.session.timeout.*#zookeeper.session.timeout=${zkSessionTimeout}#g" conf/zookeeper.properties
  166. sed -i '' "s#zookeeper.connection.timeout.*#zookeeper.connection.timeout=${zkConnectionTimeout}#g" conf/zookeeper.properties
  167. sed -i '' "s#zookeeper.retry.sleep.*#zookeeper.retry.sleep=${zkRetrySleep}#g" conf/zookeeper.properties
  168. sed -i '' "s#zookeeper.retry.maxtime.*#zookeeper.retry.maxtime=${zkRetryMaxtime}#g" conf/zookeeper.properties
  169. sed -i '' "s#master.exec.threads.*#master.exec.threads=${masterExecThreads}#g" conf/master.properties
  170. sed -i '' "s#master.exec.task.number.*#master.exec.task.number=${masterExecTaskNum}#g" conf/master.properties
  171. sed -i '' "s#master.heartbeat.interval.*#master.heartbeat.interval=${masterHeartbeatInterval}#g" conf/master.properties
  172. sed -i '' "s#master.task.commit.retryTimes.*#master.task.commit.retryTimes=${masterTaskCommitRetryTimes}#g" conf/master.properties
  173. sed -i '' "s#master.task.commit.interval.*#master.task.commit.interval=${masterTaskCommitInterval}#g" conf/master.properties
  174. sed -i '' "s#master.max.cpuload.avg.*#master.max.cpuload.avg=${masterMaxCupLoadAvg}#g" conf/master.properties
  175. sed -i '' "s#master.reserved.memory.*#master.reserved.memory=${masterReservedMemory}#g" conf/master.properties
  176. sed -i '' "s#worker.exec.threads.*#worker.exec.threads=${workerExecThreads}#g" conf/worker.properties
  177. sed -i '' "s#worker.heartbeat.interval.*#worker.heartbeat.interval=${workerHeartbeatInterval}#g" conf/worker.properties
  178. sed -i '' "s#worker.fetch.task.num.*#worker.fetch.task.num=${workerFetchTaskNum}#g" conf/worker.properties
  179. sed -i '' "s#worker.max.cpuload.avg.*#worker.max.cpuload.avg=${workerMaxCupLoadAvg}#g" conf/worker.properties
  180. sed -i '' "s#worker.reserved.memory.*#worker.reserved.memory=${workerReservedMemory}#g" conf/worker.properties
  181. sed -i '' "s#server.port.*#server.port=${apiServerPort}#g" conf/application.properties
  182. sed -i '' "s#server.session.timeout.*#server.session.timeout=${apiServerSessionTimeout}#g" conf/application.properties
  183. sed -i '' "s#server.context-path.*#server.context-path=${apiServerContextPath}#g" conf/application.properties
  184. sed -i '' "s#spring.http.multipart.max-file-size.*#spring.http.multipart.max-file-size=${springMaxFileSize}#g" conf/application.properties
  185. sed -i '' "s#spring.http.multipart.max-request-size.*#spring.http.multipart.max-request-size=${springMaxRequestSize}#g" conf/application.properties
  186. sed -i '' "s#server.max-http-post-size.*#server.max-http-post-size=${apiMaxHttpPostSize}#g" conf/application.properties
  187. sed -i '' "s#mail.protocol.*#mail.protocol=${mailProtocol}#g" conf/alert.properties
  188. sed -i '' "s#mail.server.host.*#mail.server.host=${mailServerHost}#g" conf/alert.properties
  189. sed -i '' "s#mail.server.port.*#mail.server.port=${mailServerPort}#g" conf/alert.properties
  190. sed -i '' "s#mail.sender.*#mail.sender=${mailSender}#g" conf/alert.properties
  191. sed -i '' "s#mail.passwd.*#mail.passwd=${mailPassword}#g" conf/alert.properties
  192. sed -i '' "s#xls.file.path.*#xls.file.path=${xlsFilePath}#g" conf/alert.properties
  193. sed -i '' "s#installPath.*#installPath=${installPath}#g" conf/config/install_config.conf
  194. sed -i '' "s#deployUser.*#deployUser=${deployUser}#g" conf/config/install_config.conf
  195. sed -i '' "s#ips.*#ips=${ips}#g" conf/config/install_config.conf
  196. sed -i '' "s#masters.*#masters=${masters}#g" conf/config/run_config.conf
  197. sed -i '' "s#workers.*#workers=${workers}#g" conf/config/run_config.conf
  198. sed -i '' "s#alertServer.*#alertServer=${alertServer}#g" conf/config/run_config.conf
  199. sed -i '' "s#apiServers.*#apiServers=${apiServers}#g" conf/config/run_config.conf
  200. # 2,创建目录
  201. echo "2,创建目录"
  202. if [ ! -d $installPath ];then
  203. sudo mkdir -p $installPath
  204. sudo chown -R $deployUser:$deployUser $installPath
  205. fi
  206. hostsArr=(${ips//,/ })
  207. for host in ${hostsArr[@]}
  208. do
  209. # 如果programPath不存在,则创建
  210. if ! ssh $host test -e $programPath; then
  211. ssh $host "sudo mkdir -p $programPath;sudo chown -R $deployUser:$deployUser $programPath"
  212. fi
  213. # 如果downloadPath不存在,则创建
  214. if ! ssh $host test -e $downloadPath; then
  215. ssh $host "sudo mkdir -p $downloadPath;sudo chown -R $deployUser:$deployUser $downloadPath"
  216. fi
  217. # 如果$execPath不存在,则创建
  218. if ! ssh $host test -e $execPath; then
  219. ssh $host "sudo mkdir -p $execPath; sudo chown -R $deployUser:$deployUser $execPath"
  220. fi
  221. # 如果$xlsFilePath不存在,则创建
  222. if ! ssh $host test -e $xlsFilePath; then
  223. ssh $host "sudo mkdir -p $xlsFilePath; sudo chown -R $deployUser:$deployUser $xlsFilePath"
  224. fi
  225. done
  226. # 3,停止服务
  227. echo "3,停止服务"
  228. sh ${workDir}/script/stop_all.sh
  229. # 4,删除zk节点
  230. echo "4,删除zk节点"
  231. sleep 1
  232. python ${workDir}/script/del_zk_node.py $zkQuorum $zkRoot
  233. # 5,scp资源
  234. echo "5,scp资源"
  235. sh ${workDir}/script/scp_hosts.sh
  236. if [ $? -eq 0 ]
  237. then
  238. echo 'scp拷贝完成'
  239. else
  240. echo 'sc 拷贝失败退出'
  241. exit -1
  242. fi
  243. # 6,启动
  244. echo "6,启动"
  245. sh ${workDir}/script/start_all.sh