资源规划
组件 | bigdata-node1 | bigdata-node2 | bigdata-node3 |
---|---|---|---|
OS | sles-11-sp3 | sles-11-sp3 | sles-11-sp3 |
环境准备
已安装:
- MobaXterm
- VirtualBox(注意:重装VB后需要重新安装Vagrant)
- Vagrant
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插件下载速度。
vagrant plugin list
# 集群主机名管理插件
vagrant plugin install vagrant-hostmanager
# guest addtions
vagrant plugin install vagrant-vbguest
# 目录共享插件
vagrant plugin install vagrant-bindfs
(2)导入基本操作系统镜像
# 查看box列表
vagrant box list
# 新增box
cd /cygdrive/i/learn_resource/tools/vagrant/box/SLES
vagrant box add sles11sp3 Vagrant-SLES-11-SP3.VirtualBox-jjfalling.box
vagrant box remove sles11sp3
(3)编写VagrantFile
cd /cygdrive/e/vagrant/mybox
mkdir pro01_urn02 && cd pro01_urn02
vi Vagrantfile
内容如下:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.require_version ">= 1.6.0"
boxes = [
{
:name => "bigdata-node1",
:eth1 => "192.168.0.101",
:mem => "6144",
:cpu => "2"
},
{
:name => "bigdata-node2",
:eth1 => "192.168.0.102",
:mem => "4096",
:cpu => "1"
},
{
:name => "bigdata-node3",
:eth1 => "192.168.0.103",
:mem => "4096",
:cpu => "1"
}
]
Vagrant.configure(2) do |config|
config.vm.box = "sles11sp3"
# 第一次安装时请注释以下三行配置,配置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
(4)初始化虚拟机
# 假设VagrantFile存放目录:E:\vagrant\mybox\pro01_urn02
# 进入Cygwin终端
cd /cygdrive/e/vagrant/mybox/pro01_urn02
# 创建共享目录,并将其设置为windows共享目录(推荐添加everyone读写权限)
mkdir share
echo 'test' > share/test.txt
vagrant up
vagrant up bigdata-node1
vagrant up bigdata-node2
vagrant up bigdata-node3
# 登录虚拟机
vagrant ssh
vagrant ssh bigdata-node1
vagrant ssh bigdata-node2
vagrant ssh bigdata-node3
# 查看虚拟机运行状态
vagrant status
Vagrant需要先安装virtualbox guest addtions才能开启Virtualbox目录共享功能。未开启时启动虚拟机将会抛出异常“__unknown filesystem type ‘vboxsf’”。解决方案如下:
# 示例(Cygwin客户端)
cd /cygdrive/e/vagrant/mybox/pro01_urn02
vagrant up && vagrant ssh
# 使用root用户更新系统组件
sudo su
# 更换zypper源
zypper addrepo -f http://mirrors.aliyun.com/opensuse/update/leap/42.1/oss openSUSE-42.1-Update-Oss
zypper addrepo -f http://mirrors.aliyun.com/opensuse/update/leap/42.1/non-oss/ openSUSE-42.1-Update-Non-Oss
zypper addrepo -f http://mirrors.aliyun.com/packman/openSUSE_Leap_42.1/ aliyun-packman
zypper update
zypper install -y gcc gcc-devel gcc-c++ gcc-c++-devel make kernel kernel-devel
zypper install kernel-headers kernel-devel gcc make -y
# 退出root用户
exit
# 退出vagrant用户,退出ssh
exit
vagrant halt # 关闭虚拟机
# 配置VBoxGuestAdditions.iso镜像(VirtualBox界面操作就,添加“虚拟光驱”,${VirtualBox安装目录}\VBoxGuestAdditions.iso)
vagrant up
# 若Vagrant启动没有自动加载VBoxGuestAdditions,则进行手动安装
vagrant ssh
sudo mkdir -p /media/cdrom
sudo mount -t auto /dev/sr0 /media/cdrom/
sudo mount -t auto /dev/cdrom2 /media/cdrom/
cd /media/cdrom/
sudo sh VBoxLinuxAdditions.run
exit
vagrant reload
(5)SSH登录配置
sudo chmod 766 /etc/ssh/sshd_config
sudo vi /etc/ssh/sshd_config
配置如下:
RSAAuthentication yes ## 启用 RSA 认证
PasswordAuthentication yes ## 开启ssh密码登陆
PubkeyAuthentication yes ## 启用公钥私钥配对认证方式
PermitRootLogin yes ## 不限制登录方式
AuthorizedKeysFile .ssh/authorized_keys ## 公钥文件路径(和上面生成的文件同)
系统基本设置
# SUSE11
# 关闭防火墙
service SuSEfirewall2_setup stopservice SuSEfirewall2_init stop
# 取消开机启动防火墙
chkconfig SuSEfirewall2_init offchkconfig SuSEfirewall2_setup off
# 启动防火墙
service SuSEfirewall2_setup startservice SuSEfirewall2_init start
# 取消开机启动防火墙
chkconfig SuSEfirewall2_init onchkconfig SuSEfirewall2_setup on
# suse12
# 关闭防火墙
systemctl stop SuSEfirewall2.service
# 取消开机启动防火墙
systemctl disable SuSEfirewall2.service
# 开启防火墙
systemctl enable SuSEfirewall2.service
# 开机启动防火墙
systemctl start SuSEfirewall2.service
# 禁用Selinux(默认不会开启 SELinux)
软件上传目录
软件统一放置于~/software目录下。
sudo mkdir -p /home/vagrant/software
sudo chmod 755 /home/vagrant/software
sudo chown vagrant:vagrant /home/vagrant/software
软件安装目录
软件统一安装于~/modules目录下。
sudo mkdir -p /home/vagrant/modules
sudo chmod 755 /home/vagrant/modules
sudo chown vagrant:vagrant /home/vagrant/modules
Maven仓库目录
Maven仓库配置于~/repository目录下。
sudo mkdir -p /home/vagrant/repository
sudo chmod 755 /home/vagrant/repository
sudo chown vagrant:vagrant /home/vagrant/repository
测试数据文件目录
测试数据文件统一存放于~/datas目录下。
sudo mkdir -p /home/vagrant/datas
sudo chmod 755 /home/vagrant/datas
sudo chown vagrant:vagrant /home/vagrant/datas
方式2:引用初始化虚拟机
cd /cygdrive/i/learn_resource/tools/vagrant/box/SLES
vagrant box add sles11sp3 Vagrant-SLES-11-SP3.VirtualBox-base.box