feat(): init

first commit

Signed-off-by: ehlxr <ehlxr.me@gmail.com>
This commit is contained in:
ehlxr 2018-03-29 18:42:14 +08:00
commit ca4b8f52c8
7 changed files with 164 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*.key
*.box
.vagrant

13
README.md Normal file
View File

@ -0,0 +1,13 @@
```sh
➜ vagrant box add -f centos-7.2 centos-7.2.box
➜ cd base
➜ vagrant up # 执行 init.sh 脚本时,最好保证能够 fq
➜ vagrant package --output centos-7.2-ehlxr.box
➜ vagrant box add -f centos-7.2-ehlxr centos-7.2-ehlxr.box
```

64
Vagrantfile vendored Normal file
View File

@ -0,0 +1,64 @@
Vagrant.configure("2") do |config|
# 定义虚拟机数量
vms = Array(1..5)
vms.each do |i|
config.vm.define "vg#{i}" do |cfg|
# 设置虚拟机的 Box
cfg.vm.box = "centos-7.2-ehlxr"
# 不检查 box 更新
cfg.vm.box_check_update = false
# 设置虚拟机的主机名
cfg.vm.hostname="vg#{i}.node"
# cfg.vm.network "forwarded_port", guest: 80, host: 8080
# hostonly
cfg.vm.network "private_network", ip: "192.168.3.10#{i}",:auto_network => true
# bridged
# cfg.vm.network "public_network", bridge: "en0: Wi-Fi (AirPort)"
cfg.vm.provider "virtualbox" do |vb|
# Display the VirtualBox GUI when booting the machine
vb.gui = false
# Customize the amount of memory on the VM:
vb.memory = "1024"
vb.cpus = 1
# 名称指的是在 VirtualBox 中显示的名称
vb.name = "vghost#{i}"
end
# 增加各节点 host 配置插件安装vagrant plugin install vagrant-hosts
cfg.vm.provision :hosts do |provisioner|
vms.each do |x|
provisioner.add_host "192.168.3.10#{x}", ["vg#{x}.node"]
end
end
# 默认 root 登陆
cfg.ssh.username = "root"
cfg.ssh.password = "vagrant"
cfg.ssh.insert_key = "true"
# do NOT check the correct additions version when booting this machine插件安装vagrant plugin install vagrant-vbguest
cfg.vbguest.auto_update = false
cfg.vm.synced_folder "/Users/ehlxr/works/Vagrant", "/vagrant"
# 开机运行命令
cfg.vm.provision "shell", run: "always", inline: <<-SHELL
echo -e "\033[1;33mInit cmd...\033[0m"
echo -e "\033[1;33mConfig ssh...\033[0m"
mkdir -p ~/.ssh && cat /vagrant/config/authorized_keys >> ~/.ssh/authorized_keys
sed -i 's/^#RSAAuthentication.*/RSAAuthentication\ yes/g' /etc/ssh/sshd_config
sed -i 's/^#PubkeyAuthentication.*/PubkeyAuthentication\ yes/g' /etc/ssh/sshd_config
sed -i 's/^PasswordAuthentication.*/PasswordAuthentication\ yes/g' /etc/ssh/sshd_config
SHELL
# 自定义初始化执行脚本
# cfg.vm.provision "shell", path: "config/init.sh"
end
end
end

14
base/Vagrantfile vendored Normal file
View File

@ -0,0 +1,14 @@
Vagrant.configure("2") do |config|
config.vm.box = "centos-7.2"
config.vm.network "private_network", ip: "192.168.3.3"
config.vbguest.auto_update = false
config.vm.synced_folder "/Users/ehlxr/works/Vagrant", "/vagrant"
# 自定义初始化执行脚本
config.vm.provision "shell", path: "../config/init.sh"
# 默认 root 登陆
config.ssh.username = "root"
config.ssh.password = "vagrant"
config.ssh.insert_key = "true"
end

5
config/daemon.json Normal file
View File

@ -0,0 +1,5 @@
{
"registry-mirrors": [
"https://registry.docker-cn.com"
]
}

56
config/init.sh Executable file
View File

@ -0,0 +1,56 @@
#!/bin/bash
set -e
# echo -e "\033[1;33mChange repo to aliyun...\033[0m"
# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
# yum clean all
# yum makecache
echo -e "\033[1;33mUpdating...\033[0m"
# resolve issue "https://github.com/jeff1evesque/drupal-demonstration/issues/532"
curl --remote-name --location https://yum.puppetlabs.com/RPM-GPG-KEY-puppet
rpm --import RPM-GPG-KEY-puppet
yum -y update
echo -e "\033[1;33mInstall Packages...\033[0m"
yum install vim net-tools zsh git -y
echo -e "\033[1;33mInstall oh-my-zsh...\033[0m"
bash -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
echo -e "\033[1;33mInstall oh-my-zsh plugins...\033[0m"
git clone https://github.com/zsh-users/zsh-autosuggestions /root/.oh-my-zsh/custom/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git /root/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-history-substring-search.git /root/.oh-my-zsh/custom/plugins/history-substring-search
echo -e "\033[1;33mConfig oh-my-zsh...\033[0m"
cp -f /vagrant/config/zshrc ~/.zshrc
echo -e "\033[1;33mConfig ssh...\033[0m"
mkdir -p ~/.ssh && cat /vagrant/config/authorized.key >> ~/.ssh/authorized_keys
sed -i 's/^#RSAAuthentication.*/RSAAuthentication\ yes/g' /etc/ssh/sshd_config
sed -i 's/^#PubkeyAuthentication.*/PubkeyAuthentication\ yes/g' /etc/ssh/sshd_config
sed -i 's/^PasswordAuthentication.*/PasswordAuthentication\ yes/g' /etc/ssh/sshd_config
# echo -e "\033[1;33mUpdating kernel...\033[0m"
# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
# yum --enablerepo=elrepo-kernel install kernel-ml-devel kernel-ml -y
# grub2-set-default 0
echo -e "\033[1;33mInstall docker...\033[0m"
wget -qO- https://get.docker.com | sh
# curl -sSL https://get.daocloud.io/docker | sh
echo -e "\033[1;33mConfig docker registry mirrors...\033[0m"
mkdir -p /etc/docker && cp /vagrant/config/daemon.json /etc/docker/
echo -e "\033[1;33mStart and enable Docker...\033[0m"
systemctl enable docker
systemctl start docker
echo -e "\033[1;33mVboxadd setup...\033[0m"
cd /opt/VBoxGuestAdditions-*/init
./vboxadd setup

9
config/zshrc Normal file
View File

@ -0,0 +1,9 @@
export ZSH=~/.oh-my-zsh
ZSH_THEME="robbyrussell"
plugins=(git wd sudo zsh-syntax-highlighting zsh-autosuggestions extract history-substring-search)
source $ZSH/oh-my-zsh.sh
# source ~/.bash_profile