资源规划
组件 | bigdata-node1 | bigdata-node2 | bigdata-node3 |
---|---|---|---|
OS | centos-7.6 | centos-7.6 | centos-7.6 |
环境准备
- 已安装
- Vagrant官网box下载
- CentOS官网box下载
- http://cloud.centos.org/centos/7/vagrant/x86_64/images/
- http://cloud.centos.org/centos/8/vagrant/x86_64/images/
方式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/CentOS
vagrant box add centos7.6 Vagrant-CentOS-7.6-x86_64.VirtualBox.box
3. 编写VagrantFile
```ruby-- mode: ruby --
vi: set ft=ruby :
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
<a name="IcDQi"></a>
### 4. 初始化虚拟机
```powershell
# 假设VagrantFile存放目录:E:\vagrant\mybox\bigdata
# 进入Cygwin终端
cd /cygdrive/e/vagrant/mybox/bigdata
# 创建共享目录,并将其设置为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/bigdata
vagrant up && vagrant ssh
# 使用root用户更新系统组件(配置yum源过程省略)
sudo su
rm -f /var/run/yum.pid # 当出现"Another app is currently holding the yum lock; waiting for it to exit..."时执行
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 ## 公钥文件路径(和上面生成的文件同)
系统设置
1. 基本配置
# 停止防火墙
sudo systemctl stop firewalld
# 禁用防火墙
sudo systemctl disable firewalld
# 查看防火墙状态
sudo systemctl status firewalld
# 禁用Selinux(注意重启liunx系统后才生效)
sudo vi /etc/selinux/config
SELINUX=disabled
# 关闭Swap
sudo vi /etc/fstab
# 注释掉swap相关命令行
echo vm.swappiness=0 >> /etc/sysctl.conf
# 临时生效(重启后永久生效)
sysctl -w vm.swappiness=0
sysctl -p
free -g
2. 集群主机配置
# 设置主机名(集群所有节点)
sudo vi /etc/hosts
配置如下:
# 127.0.0.1 localhost
# 注意:务必注释# 127.0.1.1 ${HOST_NAME}
# 本机内网IP建议配置与第一行(多个域名情况下)
192.168.0.101 bigdata-node1
192.168.0.102 bigdata-node2
192.168.0.103 bigdata-node3
软件上传目录
软件统一放置于~/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/CentOS
vagrant box add centos7.6 Vagrant-CentOS-7.6-x86_64.VirtualBox-base.box