资源规划

组件 bigdata-node1 bigdata-node2 bigdata-node3
OS sles-11-sp3 sles-11-sp3 sles-11-sp3

环境准备

已安装:

box下载:
https://app.vagrantup.com/jjfalling/boxes/sles11sp3/versions/1.0.1/providers/virtualbox.box
账户口令:(vagrant/vagrant,root/password)

方式1:完全搭建

虚拟机安装

(1)安装Vagrant插件

将 ${VAGRRANT_HOME}\embedded\gems 所有文件中的“https://rubygems.org”替换为“https://gems.ruby-china.com”,以加快Vagrant插件下载速度。

  1. vagrant plugin list
  2. # 集群主机名管理插件
  3. vagrant plugin install vagrant-hostmanager
  4. # guest addtions
  5. vagrant plugin install vagrant-vbguest
  6. # 目录共享插件
  7. vagrant plugin install vagrant-bindfs

(2)导入基本操作系统镜像

  1. # 查看box列表
  2. vagrant box list
  3. # 新增box
  4. cd /cygdrive/i/learn_resource/tools/vagrant/box/SLES
  5. vagrant box add sles11sp3 Vagrant-SLES-11-SP3.VirtualBox-jjfalling.box
  6. vagrant box remove sles11sp3

(3)编写VagrantFile

  1. cd /cygdrive/e/vagrant/mybox
  2. mkdir pro01_urn02 && cd pro01_urn02
  3. vi Vagrantfile

内容如下:

  1. # -*- mode: ruby -*-
  2. # vi: set ft=ruby :
  3. Vagrant.require_version ">= 1.6.0"
  4. boxes = [
  5. {
  6. :name => "bigdata-node1",
  7. :eth1 => "192.168.0.101",
  8. :mem => "6144",
  9. :cpu => "2"
  10. },
  11. {
  12. :name => "bigdata-node2",
  13. :eth1 => "192.168.0.102",
  14. :mem => "4096",
  15. :cpu => "1"
  16. },
  17. {
  18. :name => "bigdata-node3",
  19. :eth1 => "192.168.0.103",
  20. :mem => "4096",
  21. :cpu => "1"
  22. }
  23. ]
  24. Vagrant.configure(2) do |config|
  25. config.vm.box = "sles11sp3"
  26. # 第一次安装时请注释以下三行配置,配置ssh密码验证(sshd_config)后再打开
  27. # config.ssh.username = 'vagrant'
  28. # config.ssh.password = 'vagrant'
  29. # config.ssh.insert_key = true
  30. # ssh config end
  31. config.vm.box_check_update = false
  32. if Vagrant.has_plugin?("vagrant-vbguest")
  33. config.vbguest.auto_update = false
  34. end
  35. # 禁用系统默认的共享目录
  36. config.vm.synced_folder '.', '/vagrant', disabled: true
  37. boxes.each do |opts|
  38. config.vm.define opts[:name] do |config|
  39. config.vm.hostname = opts[:name]
  40. config.vm.provider "virtualbox" do |v|
  41. v.customize ["modifyvm", :id, "--name", opts[:name]]
  42. v.customize ["modifyvm", :id, "--memory", opts[:mem]]
  43. v.customize ["modifyvm", :id, "--cpus", opts[:cpu]]
  44. end
  45. config.vm.network :private_network, ip: opts[:eth1]
  46. end
  47. end
  48. config.vm.synced_folder "./share", "/mnt/app-data", type: "nfs"
  49. config.bindfs.bind_folder "/mnt/app-data","/share",force_user:"vagrant",force_group:"vagrant",o:"nonempty"
  50. end

(4)初始化虚拟机

  1. # 假设VagrantFile存放目录:E:\vagrant\mybox\pro01_urn02
  2. # 进入Cygwin终端
  3. cd /cygdrive/e/vagrant/mybox/pro01_urn02
  4. # 创建共享目录,并将其设置为windows共享目录(推荐添加everyone读写权限)
  5. mkdir share
  6. echo 'test' > share/test.txt
  7. vagrant up
  8. vagrant up bigdata-node1
  9. vagrant up bigdata-node2
  10. vagrant up bigdata-node3
  11. # 登录虚拟机
  12. vagrant ssh
  13. vagrant ssh bigdata-node1
  14. vagrant ssh bigdata-node2
  15. vagrant ssh bigdata-node3
  16. # 查看虚拟机运行状态
  17. vagrant status

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

  1. # 示例(Cygwin客户端)
  2. cd /cygdrive/e/vagrant/mybox/pro01_urn02
  3. vagrant up && vagrant ssh
  4. # 使用root用户更新系统组件
  5. sudo su
  6. # 更换zypper源
  7. zypper addrepo -f http://mirrors.aliyun.com/opensuse/update/leap/42.1/oss openSUSE-42.1-Update-Oss
  8. zypper addrepo -f http://mirrors.aliyun.com/opensuse/update/leap/42.1/non-oss/ openSUSE-42.1-Update-Non-Oss
  9. zypper addrepo -f http://mirrors.aliyun.com/packman/openSUSE_Leap_42.1/ aliyun-packman
  10. zypper update
  11. zypper install -y gcc gcc-devel gcc-c++ gcc-c++-devel make kernel kernel-devel
  12. zypper install kernel-headers kernel-devel gcc make -y
  13. # 退出root用户
  14. exit
  15. # 退出vagrant用户,退出ssh
  16. exit
  17. vagrant halt # 关闭虚拟机
  18. # 配置VBoxGuestAdditions.iso镜像(VirtualBox界面操作就,添加“虚拟光驱”,${VirtualBox安装目录}\VBoxGuestAdditions.iso)
  19. vagrant up
  20. # 若Vagrant启动没有自动加载VBoxGuestAdditions,则进行手动安装
  21. vagrant ssh
  22. sudo mkdir -p /media/cdrom
  23. sudo mount -t auto /dev/sr0 /media/cdrom/
  24. sudo mount -t auto /dev/cdrom2 /media/cdrom/
  25. cd /media/cdrom/
  26. sudo sh VBoxLinuxAdditions.run
  27. exit
  28. 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. # SUSE11
  2. # 关闭防火墙
  3. service SuSEfirewall2_setup stopservice SuSEfirewall2_init stop
  4. # 取消开机启动防火墙
  5. chkconfig SuSEfirewall2_init offchkconfig SuSEfirewall2_setup off
  6. # 启动防火墙
  7. service SuSEfirewall2_setup startservice SuSEfirewall2_init start
  8. # 取消开机启动防火墙
  9. chkconfig SuSEfirewall2_init onchkconfig SuSEfirewall2_setup on
  10. # suse12
  11. # 关闭防火墙
  12. systemctl stop SuSEfirewall2.service
  13. # 取消开机启动防火墙
  14. systemctl disable SuSEfirewall2.service
  15. # 开启防火墙
  16. systemctl enable SuSEfirewall2.service
  17. # 开机启动防火墙
  18. systemctl start SuSEfirewall2.service
  19. # 禁用Selinux(默认不会开启 SELinux)

软件上传目录

软件统一放置于~/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/SLES
  2. vagrant box add sles11sp3 Vagrant-SLES-11-SP3.VirtualBox-base.box