资源规划

组件 bigdata-node1 bigdata-node2 bigdata-node3
OS centos-7.6 centos-7.6 centos-7.6

环境准备

Vagrant.require_version “>= 1.6.0”

boxes = [ { :name => “bigdata-node1”, :eth1 => “192.168.0.101”, :mem => “4096”, :cpu => “1” }, { :name => “bigdata-node2”, :eth1 => “192.168.0.102”, :mem => “2048”, :cpu => “1” }, { :name => “bigdata-node3”, :eth1 => “192.168.0.103”, :mem => “2048”, :cpu => “1” } ]

Vagrant.configure(2) do |config|

config.vm.box = “centos7.6”

第一次安装时请注释以下三行配置,配置ssh密码验证(sshd_config)后再打开

config.ssh.username = ‘vagrant’ config.ssh.password = ‘vagrant’ config.ssh.insert_key = true

ssh config end

config.vm.box_check_update = false if Vagrant.has_plugin?(“vagrant-vbguest”) config.vbguest.auto_update = false end

禁用系统默认的共享目录

config.vm.synced_folder ‘.’, ‘/vagrant’, disabled: true

boxes.each do |opts| config.vm.define opts[:name] do |config| config.vm.hostname = opts[:name] config.vm.provider “virtualbox” do |v| v.customize [“modifyvm”, :id, “—name”, opts[:name]] v.customize [“modifyvm”, :id, “—memory”, opts[:mem]] v.customize [“modifyvm”, :id, “—cpus”, opts[:cpu]] end config.vm.network :private_network, ip: opts[:eth1] end end config.vm.synced_folder “./share”, “/mnt/app-data”, type: “nfs” config.bindfs.bind_folder “/mnt/app-data”,”/share”,force_user:”vagrant”,force_group:”vagrant”,o:”nonempty” end

  1. <a name="IcDQi"></a>
  2. ### 4. 初始化虚拟机
  3. ```powershell
  4. # 假设VagrantFile存放目录:E:\vagrant\mybox\bigdata
  5. # 进入Cygwin终端
  6. cd /cygdrive/e/vagrant/mybox/bigdata
  7. # 创建共享目录,并将其设置为windows共享目录(推荐添加everyone读写权限)
  8. mkdir share
  9. echo 'test' > share/test.txt
  10. vagrant up
  11. # 独立安装启动
  12. vagrant up bigdata-node1
  13. vagrant up bigdata-node2
  14. vagrant up bigdata-node3
  15. # 登录虚拟机
  16. vagrant ssh
  17. # 独立登录
  18. vagrant ssh bigdata-node1
  19. vagrant ssh bigdata-node2
  20. vagrant ssh bigdata-node3
  21. # 查看虚拟机运行状态
  22. vagrant status

Vagrant需要先安装virtualbox guest addtions才能开启Virtualbox目录共享功能。未开启时启动虚拟机将会抛出异常“__unknown filesystem type ‘vboxsf’”。解决方案如下:

  1. # 示例(Cygwin客户端)
  2. cd /cygdrive/e/vagrant/mybox/bigdata
  3. vagrant up && vagrant ssh
  4. # 使用root用户更新系统组件(配置yum源过程省略)
  5. sudo su
  6. rm -f /var/run/yum.pid # 当出现"Another app is currently holding the yum lock; waiting for it to exit..."时执行
  7. yum update
  8. yum install -y gcc gcc-devel gcc-c++ gcc-c++-devel make kernel kernel-devel
  9. # 退出root用户
  10. exit
  11. # 退出vagrant用户,退出ssh
  12. exit
  13. vagrant halt # 关闭虚拟机
  14. # 配置VBoxGuestAdditions.iso镜像(VirtualBox界面操作就,添加“虚拟光驱”,${VirtualBox安装目录}\VBoxGuestAdditions.iso)
  15. vagrant up
  16. # 若Vagrant启动没有自动加载VBoxGuestAdditions,则进行手动安装
  17. vagrant ssh
  18. sudo mkdir -p /media/cdrom
  19. sudo mount -t auto /dev/cdrom /media/cdrom/
  20. cd /media/cdrom/
  21. sudo sh VBoxLinuxAdditions.run
  22. exit
  23. vagrant reload

5. SSH登录配置

  1. sudo chmod 766 /etc/ssh/sshd_config
  2. sudo vi /etc/ssh/sshd_config

配置如下:

  1. RSAAuthentication yes ## 启用 RSA 认证
  2. PasswordAuthentication yes ## 开启ssh密码登陆
  3. PubkeyAuthentication yes ## 启用公钥私钥配对认证方式
  4. PermitRootLogin yes ## 不限制登录方式
  5. AuthorizedKeysFile .ssh/authorized_keys ## 公钥文件路径(和上面生成的文件同)

设置完之后记得重启SSH服务,才能使刚才设置有效。

系统设置

1. 基本配置

  1. # 停止防火墙
  2. sudo systemctl stop firewalld
  3. # 禁用防火墙
  4. sudo systemctl disable firewalld
  5. # 查看防火墙状态
  6. sudo systemctl status firewalld
  7. # 禁用Selinux(注意重启liunx系统后才生效)
  8. sudo vi /etc/selinux/config
  9. SELINUX=disabled
  10. # 关闭Swap
  11. sudo vi /etc/fstab
  12. # 注释掉swap相关命令行
  13. echo vm.swappiness=0 >> /etc/sysctl.conf
  14. # 临时生效(重启后永久生效)
  15. sysctl -w vm.swappiness=0
  16. sysctl -p
  17. free -g

2. 集群主机配置

  1. # 设置主机名(集群所有节点)
  2. sudo vi /etc/hosts

配置如下:

  1. # 127.0.0.1 localhost
  2. # 注意:务必注释# 127.0.1.1 ${HOST_NAME}
  3. # 本机内网IP建议配置与第一行(多个域名情况下)
  4. 192.168.0.101 bigdata-node1
  5. 192.168.0.102 bigdata-node2
  6. 192.168.0.103 bigdata-node3

软件上传目录

软件统一放置于~/software目录下。

  1. sudo mkdir -p /home/vagrant/software
  2. sudo chmod 755 /home/vagrant/software
  3. sudo chown vagrant:vagrant /home/vagrant/software

软件安装目录

软件统一安装于~/modules目录下。

  1. sudo mkdir -p /home/vagrant/modules
  2. sudo chmod 755 /home/vagrant/modules
  3. sudo chown vagrant:vagrant /home/vagrant/modules

Maven仓库目录

Maven仓库配置于~/repository目录下。

  1. sudo mkdir -p /home/vagrant/repository
  2. sudo chmod 755 /home/vagrant/repository
  3. sudo chown vagrant:vagrant /home/vagrant/repository

测试数据文件目录

测试数据文件统一存放于~/datas目录下。

  1. sudo mkdir -p /home/vagrant/datas
  2. sudo chmod 755 /home/vagrant/datas
  3. sudo chown vagrant:vagrant /home/vagrant/datas

方式2:引用初始化虚拟机

  1. cd /cygdrive/i/learn_resource/tools/vagrant/box/CentOS
  2. vagrant box add centos7.6 Vagrant-CentOS-7.6-x86_64.VirtualBox-base.box