使用playbook实现一键部署mysql数据库
环境
主机名 | 安装服务 | wan | lan |
---|---|---|---|
db01 | mariadb | 10.0.0.51 | 172.16.1.51 |
流程分析
1.安装ansible 2.优化ansible 3.推送公钥 4.开启防火墙 5.开启80 443 873 nfs等端口和服务白名单 6.关闭selinux 7.创建同一的用户 1.安装数据库 2.启动数据库 3.创建数据库用户 4.创建数据库
主机清单
[ ~]# vim /etc/ansible/hosts [db_group] db01 ansible_ssh_host=172.16.1.51 asible_ssh_user=root ansible_ssh_port=22
导出数据库数据
1.备份db01上的数据库 mysqldump -uroot -p‘1‘ -A wp > /root/wp.sql 2.将web01上备份的数据库拷贝至m01服务器上 scp wp.sql :/root/ansible/lb/
yml
- hosts: all tasks: - name: install mariadb yum: name: mariadb-server state: present when: ansible_fqdn is match ‘lb*‘ - name: start mariadb-server systemd: name: mariadb-server state: started enabled: yes when: ansible_fqdn is match ‘lb*‘ - name: grant mysql user mysql_user: #login_host: "localhost" #login_user: "root" #login_password: "123" login_port: "3306" name: "ty" password: "123" host: "%" priv: "*.*:ALL,GRANT" state: "present" when: ansible_fqdn is match ‘lb*‘ - name: create a database mysql_db: #login_host: "127.0.0.1" #login_user: "root" #login_password: "123" login_port: "3306" name: "wp" encoding: "utf8" state: "present" when: ansible_fqdn is match ‘lb*‘ - name: copy wp.sql copy: src: "/root/ansible/lb/wp.sql" dest: "/root/" when: ansible_fqdn is match ‘lb*‘ - name: import a database mysql_db: login_host: "127.0.0.1" login_user: "root" login_port: "3306" name: "wp" target: "/root/wp.sql" state: "import" when: ansible_fqdn is match ‘lb*‘
执行
1.执行base.yml [ ~]# ansible-playbook ansible/base.yml 2.执行rsync.yml [ ~]# ansible-playbook ansible/nfs/nfs.yml -i /root/ansible/lb/hosts
相关推荐
云中舞步 2020-11-12
杨德龙 2020-11-11
JohnYork 2020-10-16
wangzhaotongalex 2020-09-22
xiaoseyihe 2020-11-16
不要皱眉 2020-10-14
Crazyshark 2020-11-13
K先生 2020-11-10
momode 2020-09-11
思君夜未眠 2020-09-04
点滴技术生活 2020-08-21
MaggieRose 2020-08-19
kevinweijc 2020-08-18
wintershii 2020-08-17
vapaad 2020-08-17
wera00 2020-08-17
移动开发与培训 2020-08-16
ReunionIsland 2020-08-16
JimyFengqi 2020-08-16