本地MySQL开发环境搭建
GitHub: GitHub資源.
Vagrant环境搭建
Vagrant单独的环境搭建参照: Vagrant-环境搭建.
Vagrantfile设置
Vagrantfile内容追加①
config.vm.network "forwarded_port", guest: 3306, host: 13306 #mysql端口
config.vm.network "forwarded_port", guest: 6379, host: 16379 #redis端口
Vagrantfile内容追加②
config.vm.provision "shell", inline: <<-SHELL
ln -s -f /dev/null /etc/udev/rules.d/70-persistent-net.rules
sh /vagrant_data/setup/install-ansible.sh
SHELL
设定文件夹做成
cd C:\sample_vagrant
mkdir setup
文件结构,以及文件
setup
├── install-ansible.sh #安装ansible
├── provision-local.sh #ansible的模板文件等定义
├── local_hosts #本地安装的关联设定
├── playbook
│ └── local.yml #阶层定义
│ └── local.retry
│ └── group_vars
│ └── local.yml #Mysql,Redis关联定义
│ └── roles
│ └── db
│ └── files
│ └── ddl.sql
│ └── dml.sql
│ └── handlers
│ └── main.yml
│ └── tasks
│ └── firewalld.yml
│ └── main.yml
│ └── mysql.yml
│ └── ntp.yml
│ └── redis.yml
│ └── selinux.yml
│ └── yum-update.yml
ansible安装
启动VM
vagrant up
ssh连接
vagrant ssh
ansible安装
sudo sh /vagrant_data/setup/install-ansible.sh
ansible确认
ansible --version
由playbook的设定生成mysql
sh /vagrant_data/setup/provision-local.sh "-e {\"import_enable\":true}"
mysql接续确认
password;C:\sample_vagrant\setup\playbook\group_vars\local.yml内设定内容
[vagrant@localhost ~]$ mysql -u test -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.7.24 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
表确认
mysql> select * from sample_db.user;
+----+--------------+------------+
| id | mail_address | deleted_at |
+----+--------------+------------+
| 1 | ab@gmail.com | NULL |
+----+--------------+------------+
1 row in set (0.00 sec)