本地沙箱创建详情

完成沙箱环境初始化剧本所执行的具体步骤与输出结果

在本地拉起沙箱时所执行的Makefile快捷命令,以及其输出结果。

拉起本地沙箱

  1. # 下载本项目代码
  2. cd /tmp && git clone git@github.com:Vonng/pigsty.git && cd pigsty
  3. make up # 拉起vagrant虚拟机
  4. make ssh # 配置虚拟机ssh访问 【单次,下次启动无需再次执行】
  5. sudo make dns # 写入Pigsty静态DNS域名 【sudo输入密码,可选,单次】
  6. make download # 下载最新离线软件包 【可选,可显著加速初始化】
  7. make upload # 将离线软件包上传至元节点
  8. make init # 初始化Pigsty
  9. make mon-view # 打开Pigsty监控首页(默认用户密码:admin:admin)

clean

清理所有的沙箱痕迹(如果有)

  1. $ make clean
  2. cd vagrant && vagrant destroy -f
  3. ==> node-3: Forcing shutdown of VM...
  4. ==> node-3: Destroying VM and associated drives...
  5. ==> node-2: Forcing shutdown of VM...
  6. ==> node-2: Destroying VM and associated drives...
  7. ==> node-1: Forcing shutdown of VM...
  8. ==> node-1: Destroying VM and associated drives...
  9. ==> meta: Forcing shutdown of VM...
  10. ==> meta: Destroying VM and associated drives...

up4

执行make up4将调用vagrant up命令,根据Vagrantfile中的定义,使用Virtualbox创建四台虚拟机。

请注意第一次执行vagrant up时,软件会自动从官网下载 CentOS/7 的虚拟机镜像。如果您的网络状况不佳(例如没有FQ代理),则可能需要等待相当长的一段时间。 您也可以选择自己创建虚拟机,并根据 部署 一章的说明进行Pigsty部署(不建议)。

使用 make new4 将执行 make del4; make up4 一次性完成幂等的4节点虚拟机销毁与重新创建工作。

  1. $ make up4
  2. cd vagrant && vagrant up
  3. Bringing machine 'meta' up with 'virtualbox' provider...
  4. Bringing machine 'node-1' up with 'virtualbox' provider...
  5. Bringing machine 'node-2' up with 'virtualbox' provider...
  6. Bringing machine 'node-3' up with 'virtualbox' provider...
  7. ==> meta: Cloning VM...
  8. ==> meta: Matching MAC address for NAT networking...
  9. ==> meta: Setting the name of the VM: vagrant_meta_1653467035614_99943
  10. ==> meta: Clearing any previously set network interfaces...
  11. ==> meta: Preparing network interfaces based on configuration...
  12. meta: Adapter 1: nat
  13. meta: Adapter 2: hostonly
  14. ==> meta: Forwarding ports...
  15. meta: 22 (guest) => 2222 (host) (adapter 1)
  16. ==> meta: Running 'pre-boot' VM customizations...
  17. ==> meta: Booting VM...
  18. ==> meta: Waiting for machine to boot. This may take a few minutes...
  19. meta: SSH address: 127.0.0.1:2222
  20. meta: SSH username: vagrant
  21. meta: SSH auth method: private key
  22. meta: Warning: Connection reset. Retrying...
  23. meta: Warning: Remote connection disconnect. Retrying...
  24. meta: Warning: Connection reset. Retrying...
  25. meta: Warning: Remote connection disconnect. Retrying...
  26. meta: Warning: Connection reset. Retrying...
  27. ==> meta: Machine booted and ready!
  28. ==> meta: Checking for guest additions in VM...
  29. meta: No guest additions were detected on the base box for this VM! Guest
  30. meta: additions are required for forwarded ports, shared folders, host only
  31. meta: networking, and more. If SSH fails on this machine, please install
  32. meta: the guest additions and repackage the box to continue.
  33. meta:
  34. meta: This is not an error message; everything may continue to work properly,
  35. meta: in which case you may ignore this message.
  36. ==> meta: Setting hostname...
  37. ==> meta: Configuring and enabling network interfaces...
  38. ==> meta: Rsyncing folder: /Volumes/Data/pigsty/vagrant/ => /vagrant
  39. ==> meta: Running provisioner: shell...
  40. meta: Running: /var/folders/nb/nvvpjqvx55z7j1kzt9g7slfw0000gn/T/vagrant-shell20220525-46785-oyqlbp.sh
  41. meta: [INFO] write ssh config to /home/vagrant/.ssh
  42. ==> node-1: Cloning VM...
  43. ==> node-1: Matching MAC address for NAT networking...
  44. ==> node-1: Setting the name of the VM: vagrant_node-1_1653467085870_71907
  45. ==> node-1: Fixed port collision for 22 => 2222. Now on port 2200.
  46. ==> node-1: Clearing any previously set network interfaces...
  47. ==> node-1: Preparing network interfaces based on configuration...
  48. node-1: Adapter 1: nat
  49. node-1: Adapter 2: hostonly
  50. ==> node-1: Forwarding ports...
  51. node-1: 22 (guest) => 2200 (host) (adapter 1)
  52. ==> node-1: Running 'pre-boot' VM customizations...
  53. ==> node-1: Booting VM...
  54. ==> node-1: Waiting for machine to boot. This may take a few minutes...
  55. node-1: SSH address: 127.0.0.1:2200
  56. node-1: SSH username: vagrant
  57. node-1: SSH auth method: private key
  58. node-1: Warning: Connection reset. Retrying...
  59. node-1: Warning: Remote connection disconnect. Retrying...
  60. node-1: Warning: Remote connection disconnect. Retrying...
  61. node-1: Warning: Connection reset. Retrying...
  62. node-1: Warning: Remote connection disconnect. Retrying...
  63. node-1: Warning: Connection reset. Retrying...
  64. ==> node-1: Machine booted and ready!
  65. ==> node-1: Checking for guest additions in VM...
  66. node-1: No guest additions were detected on the base box for this VM! Guest
  67. node-1: additions are required for forwarded ports, shared folders, host only
  68. node-1: networking, and more. If SSH fails on this machine, please install
  69. node-1: the guest additions and repackage the box to continue.
  70. node-1:
  71. node-1: This is not an error message; everything may continue to work properly,
  72. node-1: in which case you may ignore this message.
  73. ==> node-1: Setting hostname...
  74. ==> node-1: Configuring and enabling network interfaces...
  75. ==> node-1: Rsyncing folder: /Volumes/Data/pigsty/vagrant/ => /vagrant
  76. ==> node-1: Running provisioner: shell...
  77. node-1: Running: /var/folders/nb/nvvpjqvx55z7j1kzt9g7slfw0000gn/T/vagrant-shell20220525-46785-1yv4tae.sh
  78. node-1: [INFO] write ssh config to /home/vagrant/.ssh
  79. ==> node-2: Cloning VM...
  80. ==> node-2: Matching MAC address for NAT networking...
  81. ==> node-2: Setting the name of the VM: vagrant_node-2_1653467132919_42678
  82. ==> node-2: Fixed port collision for 22 => 2222. Now on port 2201.
  83. ==> node-2: Clearing any previously set network interfaces...
  84. ==> node-2: Preparing network interfaces based on configuration...
  85. node-2: Adapter 1: nat
  86. node-2: Adapter 2: hostonly
  87. ==> node-2: Forwarding ports...
  88. node-2: 22 (guest) => 2201 (host) (adapter 1)
  89. ==> node-2: Running 'pre-boot' VM customizations...
  90. ==> node-2: Booting VM...
  91. ==> node-2: Waiting for machine to boot. This may take a few minutes...
  92. node-2: SSH address: 127.0.0.1:2201
  93. node-2: SSH username: vagrant
  94. node-2: SSH auth method: private key
  95. node-2: Warning: Connection reset. Retrying...
  96. node-2: Warning: Remote connection disconnect. Retrying...
  97. node-2: Warning: Connection reset. Retrying...
  98. node-2: Warning: Remote connection disconnect. Retrying...
  99. node-2: Warning: Connection reset. Retrying...
  100. node-2: Warning: Remote connection disconnect. Retrying...
  101. ==> node-2: Machine booted and ready!
  102. ==> node-2: Checking for guest additions in VM...
  103. node-2: No guest additions were detected on the base box for this VM! Guest
  104. node-2: additions are required for forwarded ports, shared folders, host only
  105. node-2: networking, and more. If SSH fails on this machine, please install
  106. node-2: the guest additions and repackage the box to continue.
  107. node-2:
  108. node-2: This is not an error message; everything may continue to work properly,
  109. node-2: in which case you may ignore this message.
  110. ==> node-2: Setting hostname...
  111. ==> node-2: Configuring and enabling network interfaces...
  112. ==> node-2: Rsyncing folder: /Volumes/Data/pigsty/vagrant/ => /vagrant
  113. ==> node-2: Running provisioner: shell...
  114. node-2: Running: /var/folders/nb/nvvpjqvx55z7j1kzt9g7slfw0000gn/T/vagrant-shell20220525-46785-zgwsig.sh
  115. node-2: [INFO] write ssh config to /home/vagrant/.ssh
  116. ==> node-3: Cloning VM...
  117. ==> node-3: Matching MAC address for NAT networking...
  118. ==> node-3: Setting the name of the VM: vagrant_node-3_1653467179461_75182
  119. ==> node-3: Fixed port collision for 22 => 2222. Now on port 2202.
  120. ==> node-3: Clearing any previously set network interfaces...
  121. ==> node-3: Preparing network interfaces based on configuration...
  122. node-3: Adapter 1: nat
  123. node-3: Adapter 2: hostonly
  124. ==> node-3: Forwarding ports...
  125. node-3: 22 (guest) => 2202 (host) (adapter 1)
  126. ==> node-3: Running 'pre-boot' VM customizations...
  127. ==> node-3: Booting VM...
  128. ==> node-3: Waiting for machine to boot. This may take a few minutes...
  129. node-3: SSH address: 127.0.0.1:2202
  130. node-3: SSH username: vagrant
  131. node-3: SSH auth method: private key
  132. node-3: Warning: Connection reset. Retrying...
  133. node-3: Warning: Remote connection disconnect. Retrying...
  134. node-3: Warning: Remote connection disconnect. Retrying...
  135. node-3: Warning: Connection reset. Retrying...
  136. node-3: Warning: Remote connection disconnect. Retrying...
  137. node-3: Warning: Connection reset. Retrying...
  138. ==> node-3: Machine booted and ready!
  139. ==> node-3: Checking for guest additions in VM...
  140. node-3: No guest additions were detected on the base box for this VM! Guest
  141. node-3: additions are required for forwarded ports, shared folders, host only
  142. node-3: networking, and more. If SSH fails on this machine, please install
  143. node-3: the guest additions and repackage the box to continue.
  144. node-3:
  145. node-3: This is not an error message; everything may continue to work properly,
  146. node-3: in which case you may ignore this message.
  147. ==> node-3: Setting hostname...
  148. ==> node-3: Configuring and enabling network interfaces...
  149. ==> node-3: Rsyncing folder: /Volumes/Data/pigsty/vagrant/ => /vagrant
  150. ==> node-3: Running provisioner: shell...
  151. node-3: Running: /var/folders/nb/nvvpjqvx55z7j1kzt9g7slfw0000gn/T/vagrant-shell20220525-46785-11saraj.sh
  152. node-3: [INFO] write ssh config to /home/vagrant/.ssh

ssh

新拉起的虚拟机默认用户为vagrant,需要配置本机到虚拟机的免密ssh访问。 执行make ssh命令将调用vagrant的ssh-config命令,将pigsty虚拟机节点的ssh配置文件写入~/.ssh/pigsty_config

通常该命令只需要在首次启动沙箱时执行一次,后续重新拉起的虚拟机通常会保有相同的SSH配置。

执行完毕后,用户才可以使用类似ssh node-1的方式通过SSH别名连接至沙箱内的虚拟机节点。

  1. $ make ssh
  2. cd vagrant && vagrant ssh-config > ~/.ssh/pigsty_config 2>/dev/null; true
  3. if ! grep --quiet "pigsty_config" ~/.ssh/config ; then (echo 'Include ~/.ssh/pigsty_config' && cat ~/.ssh/config) > ~/.ssh/config.tmp; mv ~/.ssh/config.tmp ~/.ssh/config && chmod 0600 ~/.ssh/config; fi
  4. if ! grep --quiet "StrictHostKeyChecking=no" ~/.ssh/config ; then (echo 'StrictHostKeyChecking=no' && cat ~/.ssh/config) > ~/.ssh/config.tmp; mv ~/.ssh/config.tmp ~/.ssh/config && chmod 0600 ~/.ssh/config; fi

dns

此命令将Pigsty沙箱虚拟机的静态DNS配置写入/etc/hosts,通常该命令只需要在首次启动沙箱时执行一次。

执行完毕后,用户才可以从本地浏览器使用域名访问 http://g.pigsty 等WebUI。

注意DNS命令需要SUDO权限执行,需要输入密码,因为/etc/hosts文件需要特权方可修改。

  1. $ sudo make dns
  2. Password: #<在此输入用户密码>
  3. if ! grep --quiet "pigsty dns records" /etc/hosts ; then cat files/dns >> /etc/hosts; fi

最后修改 2022-05-27: init commit (1e3e284)