默认启动脚本

  1. # -*- mode: ruby -*-
  2. # vi: set ft=ruby :
  3. # All Vagrant configuration is done below. The "2" in Vagrant.configure
  4. # configures the configuration version (we support older styles for
  5. # backwards compatibility). Please don't change it unless you know what
  6. # you're doing.
  7. Vagrant.configure("2") do |config|
  8. # The most common configuration options are documented and commented below.
  9. # For a complete reference, please see the online documentation at
  10. # https://docs.vagrantup.com.
  11. # Every Vagrant development environment requires a box. You can search for
  12. # boxes at https://vagrantcloud.com/search.
  13. config.vm.box = "generic/centos8"
  14. # Disable automatic box update checking. If you disable this, then
  15. # boxes will only be checked for updates when the user runs
  16. # `vagrant box outdated`. This is not recommended.
  17. # config.vm.box_check_update = false
  18. # Create a forwarded port mapping which allows access to a specific port
  19. # within the machine from a port on the host machine. In the example below,
  20. # accessing "localhost:8080" will access port 80 on the guest machine.
  21. # NOTE: This will enable public access to the opened port
  22. # config.vm.network "forwarded_port", guest: 80, host: 8080
  23. # Create a forwarded port mapping which allows access to a specific port
  24. # within the machine from a port on the host machine and only allow access
  25. # via 127.0.0.1 to disable public access
  26. # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
  27. # Create a private network, which allows host-only access to the machine
  28. # using a specific IP.
  29. # config.vm.network "private_network", ip: "192.168.33.10"
  30. # Create a public network, which generally matched to bridged network.
  31. # Bridged networks make the machine appear as another physical device on
  32. # your network.
  33. # config.vm.network "public_network"
  34. # Share an additional folder to the guest VM. The first argument is
  35. # the path on the host to the actual folder. The second argument is
  36. # the path on the guest to mount the folder. And the optional third
  37. # argument is a set of non-required options.
  38. # config.vm.synced_folder "../data", "/vagrant_data"
  39. # Provider-specific configuration so you can fine-tune various
  40. # backing providers for Vagrant. These expose provider-specific options.
  41. # Example for VirtualBox:
  42. #
  43. # config.vm.provider "virtualbox" do |vb|
  44. # # Display the VirtualBox GUI when booting the machine
  45. # vb.gui = true
  46. #
  47. # # Customize the amount of memory on the VM:
  48. # vb.memory = "1024"
  49. # end
  50. #
  51. # View the documentation for the provider you are using for more
  52. # information on available options.
  53. # Enable provisioning with a shell script. Additional provisioners such as
  54. # Ansible, Chef, Docker, Puppet and Salt are also available. Please see the
  55. # documentation for more information about their specific syntax and use.
  56. # config.vm.provision "shell", inline: <<-SHELL
  57. # apt-get update
  58. # apt-get install -y apache2
  59. # SHELL
  60. end

修改后集群脚本

  1. # -*- mode: ruby -*-
  2. # vi: set ft=ruby :
  3. # All Vagrant configuration is done below. The "2" in Vagrant.configure
  4. # configures the configuration version (we support older styles for
  5. # backwards compatibility). Please don't change it unless you know what
  6. # you're doing.
  7. Vagrant.configure("2") do |config|
  8. (1..2).each do |i|
  9. # 定义节点变量
  10. config.vm.define "node#{i}" do |node|
  11. # box 配置
  12. node.vm.box = "generic/centos8"
  13. # 设置虚拟机的主机名
  14. node.vm.hostname = "node#{i}"
  15. # 设置虚拟机IP
  16. node.vm.network "private_network", ip: "192.168.56.#{50+i}"
  17. # 设置主宿端口映射
  18. if i == 1
  19. node.vm.network "forwarded_port", guest: 3306, host: 3306
  20. node.vm.network "forwarded_port", guest: 8848, host: 8848
  21. node.vm.network "forwarded_port", guest: 9848, host: 9848
  22. node.vm.network "forwarded_port", guest: 9849, host: 9849
  23. node.vm.network "forwarded_port", guest: 6379, host: 6379
  24. else
  25. node.vm.network "forwarded_port", guest: 3306, host: 3307
  26. node.vm.network "forwarded_port", guest: 8848, host: 8849
  27. node.vm.network "forwarded_port", guest: 9848, host: 9858
  28. node.vm.network "forwarded_port", guest: 9849, host: 9850
  29. node.vm.network "forwarded_port", guest: 6379, host: 6380
  30. end
  31. # 设置主机与虚拟机的共享目录
  32. node.vm.synced_folder "d:/ProgramFiles/CentOS/data", "/home/vagrant/share"
  33. # VB 配置
  34. node.vm.provider "virtualbox" do |v|
  35. # 设置虚拟机名称
  36. v.name = "node#{i}"
  37. # 设置虚拟机内存大小
  38. v.memory = 1024
  39. # 设置虚拟机CPU个数
  40. v.cpus = 2
  41. end
  42. end
  43. end
  44. end

设置远程客户端访问

  1. vim /etc/ssh/sshd_config
  2. PasswordAuthentication no -> yes
  3. service sshd restart