hadoop.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #!/usr/bin/env bash
  2. # Licensed to the Apache Software Foundation (ASF) under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. The ASF licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. ## @description install yarn
  18. ## @audience public
  19. ## @stability stable
  20. function install_yarn()
  21. {
  22. install_yarn_container_executor
  23. install_yarn_config
  24. }
  25. ## @description uninstall yarn
  26. ## @audience public
  27. ## @stability stable
  28. function uninstall_yarn()
  29. {
  30. rm -rf /etc/yarn/sbin/Linux-amd64-64/*
  31. rm -rf /etc/yarn/sbin/etc/hadoop/*
  32. }
  33. ## @description download yarn container executor
  34. ## @audience public
  35. ## @stability stable
  36. function download_yarn_container_executor()
  37. {
  38. # my download http server
  39. if [[ -n "$DOWNLOAD_HTTP" ]]; then
  40. MY_YARN_CONTAINER_EXECUTOR_PATH="${DOWNLOAD_HTTP}/downloads/hadoop/container-executor"
  41. else
  42. MY_YARN_CONTAINER_EXECUTOR_PATH=${YARN_CONTAINER_EXECUTOR_PATH}
  43. fi
  44. if [ ! -d "${DOWNLOAD_DIR}/hadoop" ]; then
  45. mkdir -p ${DOWNLOAD_DIR}/hadoop
  46. fi
  47. if [[ -f "${DOWNLOAD_DIR}/hadoop/container-executor" ]]; then
  48. echo "${DOWNLOAD_DIR}/hadoop/container-executor is exist."
  49. else
  50. if [[ -n "$DOWNLOAD_HTTP" ]]; then
  51. echo "download ${MY_YARN_CONTAINER_EXECUTOR_PATH} ..."
  52. wget -P ${DOWNLOAD_DIR}/hadoop ${MY_YARN_CONTAINER_EXECUTOR_PATH}
  53. else
  54. echo "copy ${MY_YARN_CONTAINER_EXECUTOR_PATH} ..."
  55. cp ${MY_YARN_CONTAINER_EXECUTOR_PATH} ${DOWNLOAD_DIR}/hadoop/
  56. fi
  57. fi
  58. }
  59. ## @description install yarn container executor
  60. ## @audience public
  61. ## @stability stable
  62. function install_yarn_container_executor()
  63. {
  64. echo "install yarn container executor file ..."
  65. download_yarn_container_executor
  66. if [ ! -d "/etc/yarn/sbin/Linux-amd64-64" ]; then
  67. mkdir -p /etc/yarn/sbin/Linux-amd64-64
  68. fi
  69. if [ -f "/etc/yarn/sbin/Linux-amd64-64/container-executor" ]; then
  70. rm /etc/yarn/sbin/Linux-amd64-64/container-executor
  71. fi
  72. cp -f ${DOWNLOAD_DIR}/hadoop/container-executor /etc/yarn/sbin/Linux-amd64-64
  73. sudo chmod 6755 /etc/yarn/sbin/Linux-amd64-64
  74. sudo chown :yarn /etc/yarn/sbin/Linux-amd64-64/container-executor
  75. sudo chmod 6050 /etc/yarn/sbin/Linux-amd64-64/container-executor
  76. }
  77. ## @description install yarn config
  78. ## @audience public
  79. ## @stability stable
  80. function install_yarn_config()
  81. {
  82. echo "install yarn config file ..."
  83. cp -R ${PACKAGE_DIR}/hadoop ${INSTALL_TEMP_DIR}/
  84. find="/"
  85. replace="\/"
  86. escape_yarn_nodemanager_local_dirs=${YARN_NODEMANAGER_LOCAL_DIRS//$find/$replace}
  87. escape_yarn_nodemanager_log_dirs=${YARN_NODEMANAGER_LOG_DIRS//$find/$replace}
  88. escape_yarn_hierarchy=${YARN_HIERARCHY//$find/$replace}
  89. sed -i "s/YARN_NODEMANAGER_LOCAL_DIRS_REPLACE/${escape_yarn_nodemanager_local_dirs}/g" $INSTALL_TEMP_DIR/hadoop/container-executor.cfg >>$LOG
  90. sed -i "s/YARN_NODEMANAGER_LOG_DIRS_REPLACE/${escape_yarn_nodemanager_log_dirs}/g" $INSTALL_TEMP_DIR/hadoop/container-executor.cfg >>$LOG
  91. sed -i "s/DOCKER_REGISTRY_REPLACE/${DOCKER_REGISTRY}/g" $INSTALL_TEMP_DIR/hadoop/container-executor.cfg >>$LOG
  92. sed -i "s/CALICO_NETWORK_NAME_REPLACE/${CALICO_NETWORK_NAME}/g" $INSTALL_TEMP_DIR/hadoop/container-executor.cfg >>$LOG
  93. sed -i "s/YARN_HIERARCHY_REPLACE/${escape_yarn_hierarchy}/g" $INSTALL_TEMP_DIR/hadoop/container-executor.cfg >>$LOG
  94. # Delete the ASF license comment in the container-executor.cfg file, otherwise it will cause a cfg format error.
  95. sed -i '1,16d' $INSTALL_TEMP_DIR/hadoop/container-executor.cfg
  96. if [ ! -d "/etc/yarn/sbin/etc/hadoop" ]; then
  97. mkdir -p /etc/yarn/sbin/etc/hadoop
  98. fi
  99. cp -f $INSTALL_TEMP_DIR/hadoop/container-executor.cfg /etc/yarn/sbin/etc/hadoop/
  100. }