平时使用的 vagrant 集群配置实践。一个配置文件管理一个集群,嗯,相对于以前想玩一个集群需要搞 三个机器,想想之前,都是泪。这里要区分 vagrant box 配置,和虚拟机配置,3 台集群的虚拟机都是用同一版本 box 镜像。
核心配置说明:
config.vm.define :node1 do |node1|
# 配置主机名
node1.vm.hostname = "node1"
# 配置私有 IP
node1.vm.network "private_network", ip: "192.168.56.121"
# 配置虚拟机提供者配置,我用的 virtualbox
node1.vm.provider "virtualbox" do |v|
# 配置在 virtualbox 中显示名字,不配置默认是 vagrant 自动生成的 id,
# vagrant-globalstatus 可以查看 id
v.name = "node1-121"
# 配置内存大小
v.memory = "1024"
# 配置 CPU 核数
v.cpus = "2"
end
end
config.vm.define :node2 do |node2|
node2.vm.hostname = "node2"
node2.vm.network :private_network, ip: "192.168.56.122"
node2.vm.provider "virtualbox" do |v|
v.name = "node2-122"
v.memory = "1024"
v.cpus = "2"
end
end
config.vm.define :node3 do |node3|
node3.vm.hostname = "node3"
node3.vm.network "private_network", ip: "192.168.56.123"
node3.vm.provider "virtualbox" do |v|
v.name = "node3-123"
v.memory = "1024"
v.cpus = "2"
end
end
配置好之后 vagrant up 启动集群。启动成功后, vagrant ssh node1 即可登录集群服务器 1。
完整详细参考配置如下:
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "mycentos7"
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# config.vm.network "forwarded_port", guest: 80, host: 8080
# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network "private_network", ip: "192.168.56.155"
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"
# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
config.vm.define :web do |web|
web.vm.hostname = "web"
web.vm.network "private_network", ip: "192.168.33.10"
config.vm.synced_folder "../php", "/usr/share/nginx/html"
config.vm.synced_folder "nginx-conf", "/etc/nginx/conf.d"
web.vm.network "forwarded_port", guest: 80, host: 80
web.vm.provider "virtualbox" do |v|
v.name = "web"
v.memory = "2048"
v.cpus = "1"
end
end
config.vm.define :db1 do |db1|
db1.vm.hostname = "db1"
db1.vm.network :private_network, ip: "192.168.33.11"
config.vm.synced_folder "../php", "/usr/share/nginx/html"
config.vm.synced_folder "nginx-conf", "/etc/nginx/conf.d"
db1.vm.network "forwarded_port", guest: 8081, host: 8081
db1.vm.provider "virtualbox" do |v|
v.name = "db1"
v.memory = "1024"
v.cpus = "1"
end
end
config.vm.define :db2 do |db2|
db2.vm.hostname = "db2"
db2.vm.network :private_network, ip: "192.168.33.12"
config.vm.synced_folder "../php", "/usr/share/nginx/html"
config.vm.synced_folder "nginx-conf", "/etc/nginx/conf.d"
db2.vm.network "forwarded_port", guest: 8082, host: 8082
db2.vm.provider "virtualbox" do |v|
v.name = "db2"
v.memory = "1024"
v.cpus = "1"
end
end
config.vm.define :db3 do |db3|
db3.vm.hostname = "db3"
db3.vm.network :private_network, ip: "192.168.33.13"
config.vm.synced_folder "../php", "/usr/share/nginx/html"
config.vm.synced_folder "nginx-conf", "/etc/nginx/conf.d"
db3.vm.network "forwarded_port", guest: 8083, host: 8083
db3.vm.provider "virtualbox" do |v|
v.name = "db3"
v.memory = "1024"
v.cpus = "1"
end
end
#
# View the documentation for the provider you are using for more
# information on available options.
# Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
# such as FTP and Heroku are also available. See the documentation at
# https://docs.vagrantup.com/v2/push/atlas.html for more information.
# config.push.define "atlas" do |push|
# push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
# end
# Enable provisioning with a shell script. Additional provisioners such as
# Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
# documentation for more information about their specific syntax and use.
# config.vm.provision "shell", inline: <<-SHELL
# apt-get update
# apt-get upgrade
# SHELL
end
参考:https://favoorr.github.io/2017/01/06/vagrant-multiple-servers-cluster-config-best-practices/
搜索
标签
study
ab
amap
apache
apahe
awk
aws
bat
centos
CFS
chrome
cmd
cnpm
composer
consul
crontab
css
curl
cygwin
devops
di
docker
docker,docker-compose
ethereum
excel
fiddler
fluentd
framework
front-end
git
gitgui
github
glide
go
golang
gorm
grafana
gzip
ioc
item2
iterm2
javascript
jenkins
jsonp
kafka
laradock
laravel
larval
linux
liunux
log
mac
mac, wi-fi
macos
magento
mariaDB
minikube
mongoDB
msp
mysql
netbeans
nginx
nodejs
nohup
npm
nsq
php
php-fpm
php7
phpstorm
php扩展
Protobuf
python
redis
scp
server
shell
soap
socket
socket5
sql
sre
ssdb
ssh
ssl
study
sublime
swift
system
td-agent
uml
v2ray
vagrant
vagrnat
vim
vpn
vue
vue.js
webpack
webrtc
websocket
webtatic
windows
windows7
word
wps
xdebug
yarn
yii2
yum
zookeeper
世界国家
互联网
以太坊
分类
前端
小程序
打印机
排序算法
搞笑
权限
粤语
缓存
网络
虚拟机
视频
设计模式
项目管理
热门文章
友情链接