Vagrant Centos 7 环境配置

  1. 创建目录
mkdir vagrant 
cd vagrant
mkdir node01
mkdir node02
mkdir node03
  1. 分别在node01、node02和node03目录执行
vagrant init 
  1. 分别修改三个配置文件

node01

Vagrant.configure("2") do |config|
  config.vm.box = "centos/7"
  config.vm.hostname = "node01"
  config.vm.network "private_network", ip: "10.1.100.11"
  # 虚拟机配置
  config.vm.provider "virtualbox" do |vb|
    vb.gui = false
    vb.memory = "1024"
	vb.cpus = 2
  end
  # 初始化安装脚本
  config.vm.provision "shell", inline: <<-SHELL
    yum update
    yum install -y vim wget
	sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/'  /etc/ssh/sshd_config
	systemctl restart sshd	
	# 关闭防火墙
	systemctl stop firewalld.service 
	systemctl disable firewalld.service
	# 关闭selinux
	sed -i 's/enforcing/disabled/' /etc/selinux/config
	# 转发流量到iptables
	cat > /etc/sysctl.d/k8s.conf << EOF 
	net.bridge.bridge-nf-call-ip6tables = 1 
	net.bridge.bridge-nf-call-iptables = 1 
	EOF 
	sysctl --system
	# 开启时间同步
	yum install ntpdate -y 
	ntpdate time.windows.com
	# 时区
	timedatectl set-timezone Asia/Shanghai
	# 安装lrzsz命令
	yum install -y lrzsz
  SHELL
end

node02

Vagrant.configure("2") do |config|
  config.vm.box = "centos/7"
  config.vm.hostname = "node02"
  config.vm.network "private_network", ip: "10.1.100.12"
  # 虚拟机配置
  config.vm.provider "virtualbox" do |vb|
    vb.gui = false
    vb.memory = "1024"
	vb.cpus = 2
  end
  # 初始化安装脚本
  config.vm.provision "shell", inline: <<-SHELL
    yum update
    yum install -y vim wget
	sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/'  /etc/ssh/sshd_config
	systemctl restart sshd	
	# 关闭防火墙
	systemctl stop firewalld.service 
	systemctl disable firewalld.service
	# 关闭selinux
	sed -i 's/enforcing/disabled/' /etc/selinux/config
	# 转发流量到iptables
	cat > /etc/sysctl.d/k8s.conf << EOF 
	net.bridge.bridge-nf-call-ip6tables = 1 
	net.bridge.bridge-nf-call-iptables = 1 
	EOF 
	sysctl --system
	# 开启时间同步
	yum install ntpdate -y 
	ntpdate time.windows.com
	# 时区
	timedatectl set-timezone Asia/Shanghai
	# 安装lrzsz命令
	yum install -y lrzsz
  SHELL
end

node03

Vagrant.configure("2") do |config|
  config.vm.box = "centos/7"
  config.vm.hostname = "node03"
  config.vm.network "private_network", ip: "10.1.100.13"
  # 虚拟机配置
  config.vm.provider "virtualbox" do |vb|
    vb.gui = false
    vb.memory = "1024"
	vb.cpus = 2
  end
  # 初始化安装脚本
  config.vm.provision "shell", inline: <<-SHELL
    yum update
    yum install -y vim wget
	sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/'  /etc/ssh/sshd_config
	systemctl restart sshd	
	# 关闭防火墙
	systemctl stop firewalld.service 
	systemctl disable firewalld.service
	# 关闭selinux
	sed -i 's/enforcing/disabled/' /etc/selinux/config
	# 转发流量到iptables
	cat > /etc/sysctl.d/k8s.conf << EOF
	net.bridge.bridge-nf-call-ip6tables = 1 
	net.bridge.bridge-nf-call-iptables = 1 
	EOF 
	sysctl --system
	# 开启时间同步
	yum install ntpdate -y 
	ntpdate time.windows.com
	# 时区
	timedatectl set-timezone Asia/Shanghai
	# 安装lrzsz命令
	yum install -y lrzsz
  SHELL
end
  1. 分别在三个目录下执行

默认密码:vagrant

vagrant up
  1. 通过shell工具连接到三个虚拟机并修改密码为root
  2. 修改host映射

三个节点都需要修改

10.1.100.11 node01
10.1.100.12 node02
10.1.100.13 node03

7.生成ssh密钥

ssh-keygen -t rsa
  1. 分发到各个节点

三个节点都需要执行

ssh-copy-id node01
ssh-copy-id node02
ssh-copy-id node03
  1. 分别执行
ssh node01
ssh node02
ssh node03
  1. 安装jdk
tar -zxvf jdk-8u391-linux-x64.tar.gz
  1. 分发到其他节点
scp -r jdk1.8.0_391/ root@node02:/opt/
scp -r jdk1.8.0_391/ root@node03:/opt/
  1. 配置环境变量

修改/etc/profile

export JAVA_HOME=/opt/jdk1.8.0_391
export PATH=$PATH:$JAVA_HOME/bin
  1. 生效
source /etc/profile
  1. 查看是否生效
java -version

你可能感兴趣的:(vagrant,centos)