资源规划
组件 | cfp-acrm-cdh-1 | cfp-acrm-cdh-2 | cfp-acrm-cdh-3 |
---|---|---|---|
OS | redhat-6.8 | redhat-6.8 | redhat-6.8 |
环境准备
已安装:
box下载:
https://app.vagrantup.com/iamseth/boxes/rhel-6.8-x86_64/versions/1.0.0/providers/virtualbox.box
方式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/RHEL
vagrant box add redhat6.8 Vagrant-RedHat-6.8-x86_64.VirtualBox.box
(3)编写VagrantFile
注意内存分配,CM主机需要分配8G以上。
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.require_version ">= 1.6.0"
boxes = [
{
:name => "cfp-acrm-cdh-1",
:eth1 => "192.168.0.101",
:mem => "8192",
:cpu => "1"
},
{
:name => "cfp-acrm-cdh-2",
:eth1 => "192.168.0.102",
:mem => "2048",
:cpu => "1"
},
{
:name => "cfp-acrm-cdh-3",
:eth1 => "192.168.0.103",
:mem => "2048",
:cpu => "1"
}
]
Vagrant.configure(2) do |config|
config.vm.box = "redhat6.8"
# 第一次安装时请注释以下三行配置,配置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\cib
# 进入Cygwin终端
cd /cygdrive/e/vagrant/mybox/cib
# 创建共享目录,并将其设置为windows共享目录(推荐添加everyone读写权限)
mkdir share
echo 'test' > share/test.txt
vagrant up
# 登录虚拟机
vagrant ssh
# 查看虚拟机运行状态
vagrant status
Vagrant需要先安装virtualbox guest addtions才能开启Virtualbox目录共享功能。未开启时启动虚拟机将会抛出异常“__unknown filesystem type ‘vboxsf’”。解决方案如下:
# 示例(Cygwin客户端)
cd /cygdrive/e/vagrant/mybox/cib
vagrant up && vagrant ssh
# 使用root用户更新系统组件(配置yum源过程省略)
sudo su
# 更换yum源,将原有源删除或备份到别的目下下
cd /etc/yum.repos.d/
wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
vi CentOS6-Base-163.repo
# 编辑文件,把文件里面的$releasever全部替换为版本号:6(注意,不是6.5!)最后保存!
:%s/$releasever/6/g
# 清除原有缓存,重建缓存
yum clean all
yum makecache
yum update
yum install -y gcc gcc-devel gcc-c++ gcc-c++-devel make kernel kernel-devel
# 退出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/cdrom /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 ## 公钥文件路径(和上面生成的文件同)
系统基本设置
# linux6上iptables关闭后ip6tables会起来,所以最好一并关掉
# 停止防火墙
service iptables stop
# 禁用防火墙
chkconfig iptables off
# 停止防火墙
service ip6tables stop
# 禁用防火墙
chkconfig ip6tables off
setenforce 0
getenforce
# 查看防火墙状态(全部为off即可)
chkconfig iptables --list
# 禁用Selinux(注意重启liunx系统后才生效)
sudo vi /etc/selinux/config
SELINUX=disabled
软件上传目录
软件统一放置于~/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/RHEL
vagrant box add redhat6.8 Vagrant-RedHat-6.8-x86_64.VirtualBox-base.box