environment.sh 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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 check operation System
  18. ## @audience public
  19. ## @stability stable
  20. function check_operationSystem()
  21. {
  22. echo -e "The submarine assembly support \033[32m[centos-release-7-3.1611.el7.centos.x86_64]\033[0m or higher operating system version."
  23. case ${OPERATING_SYSTEM} in
  24. centos)
  25. local operationSystemVersion=`rpm --query centos-release`
  26. echo -e "The current operating system version is \e[31m[${operationSystemVersion}]\e[0m" | tee -a $LOG
  27. ;;
  28. *)
  29. echo -e "\033[31mWARN: The submarine assembly Unsupported [${OPERATING_SYSTEM}] operating system\033[0m"
  30. ;;
  31. esac
  32. }
  33. ## @description update operation System Kernel
  34. ## @audience public
  35. ## @stability stable
  36. function update_operationSystemKernel()
  37. {
  38. echo "If the server is unable to connect to the network, execute the following command yourself:
  39. wget http://vault.centos.org/7.3.1611/os/x86_64/Packages/kernel-headers-3.10.0-514.el7.x86_64.rpm
  40. rpm -ivh kernel-headers-3.10.0-514.el7.x86_64.rpm"
  41. echo -n "Do you want to kernel upgrades?[y|n]"
  42. read myselect
  43. if [[ "$myselect" = "y" || "$myselect" = "Y" ]]
  44. then
  45. echo "Now try to use the yum command for kernel upgrades ..."
  46. yum install kernel-devel-$(uname -r) kernel-headers-$(uname -r)
  47. local kernelVersion=`uname -r`
  48. echo -e "After the upgrade, the operating system kernel version is \e[31m${kernelVersion}\e[0m" | tee -a $LOG
  49. fi
  50. }
  51. ## @description check operation system kernel
  52. ## @audience public
  53. ## @stability stable
  54. function check_operationSystemKernel()
  55. {
  56. case ${OPERATING_SYSTEM} in
  57. centos)
  58. local kernelVersion=`uname -r`
  59. echo -e "Submarine support operating system kernel version is \033[32m 3.10.0-514.el7.x86_64 \033[0m" | tee -a $LOG
  60. echo -e "Current operating system kernel version is \e[31m${kernelVersion}\e[0m" | tee -a $LOG
  61. update_operationSystemKernel
  62. ;;
  63. *)
  64. echo -e "\033[31m WARN: The submarine assembly Unsupported operating system [${OPERATING_SYSTEM}] \033[0m"
  65. ;;
  66. esac
  67. }
  68. ## @description get gcc version
  69. ## @audience public
  70. ## @stability stable
  71. function get_gcc_version()
  72. {
  73. local gccVersion=`gcc --version`
  74. version=${gccVersion%Copyright*}
  75. echo $version
  76. }
  77. ## @description install gcc
  78. ## @audience public
  79. ## @stability stable
  80. function install_gcc()
  81. {
  82. echo -n "Do you want to install gcc?[y|n]"
  83. read myselect
  84. if [[ "$myselect" = "y" || "$myselect" = "Y" ]]; then
  85. echo "Execute the yum install gcc make g++ command"
  86. yum install gcc make g++
  87. local gccVersion=`gcc --version`
  88. echo -e "After the install, the gcc version is \e[31m${gccVersion}\e[0m" | tee -a $LOG
  89. fi
  90. }
  91. ## @description check gcc Version
  92. ## @audience public
  93. ## @stability stable
  94. function check_gccVersion()
  95. {
  96. local gccVersionInfo=`gcc --version`
  97. local gccVersion=${gccVersionInfo%Copyright*}
  98. if [[ "$gccVersion" = "" ]]; then
  99. echo "The gcc was not installed on the system. Automated installation ..."
  100. install_gcc
  101. else
  102. echo -e "Submarine gcc version need \033[34mgcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-11)\033[0m or higher."
  103. echo -e "Current gcc version was \033[34m${gccVersion}\033[0m"
  104. fi
  105. }
  106. ## @description check GPU
  107. ## @audience public
  108. ## @stability stable
  109. function check_GPU()
  110. {
  111. gpuInfo=`lspci | grep -i nvidia`
  112. if [[ "$gpuInfo" = "" ]]; then
  113. echo -e "\033[31mERROR: The system did not detect the GPU graphics card.\033[0m"
  114. else
  115. echo -e "\033[32mINFO: The system detect the GPU graphics card.\033[0m"
  116. fi
  117. }
  118. ## @description check user group
  119. ## @audience public
  120. ## @stability stable
  121. function check_userGroup()
  122. {
  123. echo -e "check hadoop user group ..."
  124. echo -e "Hadoop runs the required user [hdfs, mapred, yarn] and groups [hdfs, mapred, yarn, hadoop] installed by ambari."
  125. echo -e "If you are not using ambari for hadoop installation,
  126. then you can add the user and group by root by executing the following command:
  127. \033[34madduser hdfs
  128. adduser mapred
  129. adduser yarn
  130. addgroup hadoop
  131. usermod -aG hdfs,hadoop hdfs
  132. usermod -aG mapred,hadoop mapred
  133. usermod -aG yarn,hadoop yarn
  134. usermod -aG hdfs,hadoop hadoop
  135. groupadd docker
  136. usermod -aG docker yarn
  137. usermod -aG docker hadoop\033[0m\n"
  138. echo -e "check docker user group ..."
  139. # check user group
  140. DOCKER_USER_GROUP='docker'
  141. egrep "^${DOCKER_USER_GROUP}" /etc/group >& /dev/null
  142. if [[ $? -ne 0 ]]; then
  143. echo -e "user group ${DOCKER_USER_GROUP} does not exist, Please execute the following command:"
  144. echo -e "\033[34mgroupadd $DOCKER_USER_GROUP\033[0m"
  145. fi
  146. # check user
  147. USER_GROUP=(yarn hadoop)
  148. for user in ${USER_GROUP[@]}
  149. do
  150. egrep "^${user}" /etc/passwd >& /dev/null
  151. if [[ $? -ne 0 ]]; then
  152. echo -e "User ${user} does not exist, Please execute the following command:"
  153. echo -e "\033[34madduser ${user}\033[0m"
  154. echo -e "\033[34musermod -aG ${DOCKER_USER_GROUP} ${user}\033[0m"
  155. fi
  156. echo -e "Please execute the following command:"
  157. echo -e "\033[34musermod -aG ${DOCKER_USER_GROUP} ${user}\033[0m"
  158. done
  159. }
  160. ## @description Some preparatory work for nvidia driver installation
  161. ## @audience public
  162. ## @stability stable
  163. function prepare_nvidia_environment()
  164. {
  165. echo "prepare nvidia environment ..."
  166. yum -y update
  167. yum install kernel-devel-$(uname -r) kernel-headers-$(uname -r)
  168. yum -y install epel-release
  169. yum -y install dkms
  170. echo -e "\033[34m ===== Please manually execute the following command =====
  171. # 1. Disable nouveau
  172. # Add the content 'rd.driver.blacklist=nouveau nouveau.modeset=0'
  173. # to the 'GRUB_CMDLINE_LINUX' configuration item in the /etc/default/grub file.
  174. root:> vi /etc/default/grub
  175. vi:> GRUB_CMDLINE_LINUX=\"rd.driver.blacklist=nouveau nouveau.modeset=0 ...\"
  176. # 2. Generate configuration
  177. root:> grub2-mkconfig -o /boot/grub2/grub.cfg
  178. # 3. Open (new) /etc/modprobe.d/blacklist.conf, add content 'blacklist nouveau'
  179. root:> vi /etc/modprobe.d/blacklist.conf
  180. vi:> blacklist nouveau
  181. # 4. Update configuration and reboot
  182. root:> mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r)-nouveau.img
  183. root:> dracut /boot/initramfs-$(uname -r).img $(uname -r)
  184. root:> reboot
  185. \033[0m"
  186. }