vagrant+virtual box install centos7 cluster


====== Use vagrant+virtual box ====== Single machine
1. Install Vagrant and
  visit Vagrant official website: [https://www.vagrantup.com/], download the corresponding version
  
2. Download and install virtual box and
  visit VirtualBox Official website: [https://www.virtualbox.org/], download the corresponding version
  
2, add the virtualbox.box file to the mirror managed by vagrant
  1), download the mirror file virtualbox.box file in the network disk, which is available on the official website Download
  2), save to a certain directory of the disk, such as [C:\SoftInstalled\Vagrant\virtualbox.box]
  3), add the mirror and name it centos/7, execute the command: [vagrant box add centos/7 C:\ SoftInstalled\Vagrant\virtualbox.box]
  4), vagrant box list, view the local box [centos/7 can be seen at this time]
  
3. Install centos7:
  1), create a centos7 folder, and enter it [the full path of the directory does not have Chinese characters]
  2). Open cmd in this directory and run [vagrant init centos/7]
  3). At this time, Vagrantfile will be generated in the current directory, enter the Vagrantfile file, and modify the information as follows:
    config.vm.box = " centos/7"
    config.vm.network "public_network"
    config.vm.provider "virtualbox" do |vb|
      vb.memory = "2048"
      vb.name= "tiger-centos7"
      vb.cpus= 2
    
4. The centos/7 mirror is available, Start to create a virtual machine according to the Vagrantfile file, and go to the centos7 folder, open the cmd window in this directory, and execute [vagrant up] [open the virtual box to observe, you can find that the centos7 is created successfully]

At this point, use vagrant+virtualbox to build centos7 is complete, and then you can modify the Vagrantfile to configure the virtual machine accordingly.

5. After you operate the virtual machine, you still have to open the cmd window in the centos folder to operate
    vagrant halt gracefully close
    vagrant up and start normally
  
6. Vagrant common commands
  1), vagrant ssh into the centos7 just created
  2), vagrant status view centos7 Status
  3), vagrant halt stop/shut down centos7
  4), vagrant destroy delete centos7
  5), vagrant status view the current virtual machine created by vagrant
  6), script commands can also be written in Vagrantfile, making centos7 more abundant,
  but pay attention to the modification Vagrantfile, in order to make the normal running centos7 take effect, you must use vagrant reload
  
7. Check the virtual machine network card: [ip a] 192.168.3.11/24, the local network needs to be connected: verify whether it can be connected, check the local network address: [ipconfig] ,Pin Network【ping 192.168.3.11】

====== Connect centos7 via Xshell ======

01 Use the default account of centos7 to connect
    and execute vagrant ssh-config in the centos folder.
    Follow: Hostname Port IdentityFile
    IP: 127.0.0.1
    port: 2222
    User name: vagrant
    Password: vagrant
    file: the file pointed to by Identityfile private-key
    
02 Use root account Log in to
    vagrant ssh and enter into the virtual machine
    sudo -i
    vi /etc/ssh/sshd_config
    modify PasswordAuthentication yes
    passwd modify the password, such as abc123
    systemctl restart sshd
    use the account root, the password abc123 to log in
    
    
====== Set up multiple machines === ===
1. Just modify the Vagrantfile file as follows
boxes = [
    {         :name => "manager-node",         :eth1 => "192.168.3.11",         :mem => "1024",



        :cpu => "1"
    },
    {
        :name => "worker01-node",
        :eth1 => "192.168.3.12",
        :mem => "1024",
        :cpu => "1"
    },
    {
        :name => "worker02-node",
        :eth1 => "192.168.3.13",
        :mem => "1024",
        :cpu => "1"
    }
]

Vagrant.configure(2) do |config|

  config.vm.box = "centos/7"
  
   boxes.each do |opts|
      config.vm.define opts[:name] do |config|
        config.vm.hostname = opts[:name]
        config.vm.provider "vmware_fusion" do |v|
          v.vmx["memsize"] = opts[:mem]
          v.vmx["numvcpus"] = opts[:cpu]
        end

        config.vm.provider "virtualbox" do |v|
          v.customize ["modifyvm", :id, "--memory", opts[:mem]]
          v.customize ["modifyvm", :id, "--cpus", opts[:cpu]]
          v.customize ["modifyvm", :id, "--name", opts[:name]]
        end

        config.vm.network :public_network, ip: opts[:eth1]
      end
  end

end

Guess you like

Origin blog.csdn.net/qq_36336332/article/details/103534746