set_host_network.sh 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/bin/bash
  2. # Licensed to the Apache Software Foundation (ASF) under one or more
  3. # contributor license agreements. See the NOTICE file distributed with
  4. # this work for additional information rega4rding copyright ownership.
  5. # The ASF licenses this file to You under the Apache License, Version 2.0
  6. # (the "License"); you may not use this file except in compliance with
  7. # the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. # This script is used to add a Host/VM to the Docker network
  17. # for example, an Ambari-agent within a VM (not in a Docker container)
  18. # run this script with root
  19. # $1 <Weave internal IP of the VM>
  20. # $2 <Weave DNS IP of the VM>
  21. # $3 <Subnet mask of Weave network>
  22. # $4 <The host name of this VM inside the Weave network>
  23. # $5 <The domain name of this VM inside the Weave network>, which is supposed to be end with "weave.local"
  24. # $6 <External IP address of Ambari server>
  25. if [ $# -lt 6 ]; then
  26. echo "usage: ./set_ambari_server_network.sh <Weave internal IP> <Weave DNS IP> <Mask> <Weave host name> <Weave domain name> <Ambari server IP>"
  27. echo "example: ./set_ambari_server_network.sh 192.168.254.1 192.168.254.2 16 yourname-group-c-service-server-1 yourname-group-c-service-server-1.weave.local 104.196.91.170"
  28. exit 1
  29. fi
  30. weave_internal_ip=$1
  31. weave_dns_ip=$2
  32. mask=$3
  33. weave_host_name=$4
  34. weave_domain_name=$5
  35. ambari_server_ip=$6
  36. # install weave
  37. chmod 755 ../Linux/CentOS7/weave_install.sh
  38. ../Linux/CentOS7/weave_install.sh
  39. # install docker
  40. chmod 755 ../Linux/CentOS7/docker_install.sh
  41. ../Linux/CentOS7/docker_install.sh
  42. # reset weave
  43. weave reset
  44. # launch weave
  45. weave launch $ambari_server_ip
  46. # launch Weave DNS
  47. weave launch-dns ${weave_dns_ip}/${mask}
  48. # expose IP and a new domain name.
  49. # MUST use one expose command to set both ip and domain name, OR the domain name will not be bind to this weave internal IP
  50. weave expose ${weave_internal_ip}/${mask} -h $weave_domain_name
  51. # set domain name resolution
  52. python dns_edit.py $weave_dns_ip
  53. # add Weave local IP, host name, domain name mapping
  54. content="$(cat /etc/hosts)"
  55. echo "${weave_internal_ip} ${weave_domain_name} ${weave_host_name}" > /etc/hosts
  56. echo "$content" >> /etc/hosts