From ca4b8f52c82d78855cbd861f49ce8e239964f474 Mon Sep 17 00:00:00 2001 From: ehlxr Date: Thu, 29 Mar 2018 18:42:14 +0800 Subject: [PATCH] :sparkles: feat(): init first commit Signed-off-by: ehlxr --- .gitignore | 3 +++ README.md | 13 ++++++++++ Vagrantfile | 64 ++++++++++++++++++++++++++++++++++++++++++++++ base/Vagrantfile | 14 ++++++++++ config/daemon.json | 5 ++++ config/init.sh | 56 ++++++++++++++++++++++++++++++++++++++++ config/zshrc | 9 +++++++ 7 files changed, 164 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 Vagrantfile create mode 100644 base/Vagrantfile create mode 100644 config/daemon.json create mode 100755 config/init.sh create mode 100644 config/zshrc diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2bc52b8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.key +*.box +.vagrant \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..8b1cf24 --- /dev/null +++ b/README.md @@ -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 + +``` \ No newline at end of file diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..9dc1bcd --- /dev/null +++ b/Vagrantfile @@ -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 \ No newline at end of file diff --git a/base/Vagrantfile b/base/Vagrantfile new file mode 100644 index 0000000..4bf4d53 --- /dev/null +++ b/base/Vagrantfile @@ -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 \ No newline at end of file diff --git a/config/daemon.json b/config/daemon.json new file mode 100644 index 0000000..9b451e8 --- /dev/null +++ b/config/daemon.json @@ -0,0 +1,5 @@ +{ + "registry-mirrors": [ + "https://registry.docker-cn.com" + ] +} \ No newline at end of file diff --git a/config/init.sh b/config/init.sh new file mode 100755 index 0000000..1bf0c12 --- /dev/null +++ b/config/init.sh @@ -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 \ No newline at end of file diff --git a/config/zshrc b/config/zshrc new file mode 100644 index 0000000..9a2b795 --- /dev/null +++ b/config/zshrc @@ -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 \ No newline at end of file