节点规划
主机名 | IP地址 |
master |
192.168.238.10 |
node1 |
192.168.238.11 |
node2 |
192.168.238.12 |
node3 |
192.168.238.13 |
准备四台虚拟机,使用CentOS-7-x86_64-DVD-2009.iso镜像
基础准备
1,安装ansible
[root@master root]# yum install epel-release -y ##由于ansible的依赖包较多,推荐使用网络源安装。首先安装携带ansible的网络源,然后安装ansible即可
[root@master root]# yum install ansible -y
2,配置ssh免密登录
[root@master root]# ssh-keygen ##生成密钥,默认回车即可
[root@master root]# ssh-copy-id 192.168.238.11 ##拷贝密钥至主机
[root@master root]# ssh-copy-id 192.168.238.12
[root@master root]# ssh-copy-id 192.168.238.13
3,关闭防火墙和selinux
[root@master root]# systemctl stop firewalld && systemctl disable firewalld
[root@master root]# setenforce 0
[root@master root]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
4,创建ansible的工作目录
[root@master root]# mkdir example
5,修改ansible主机清单
[root@master root]# cd /ect/ansible/hosts
[root@master hosts]#cat hosts
[node]
192.168.238.11 hostname=node1
192.168.238.12 hostname=node2
192.168.238.13 hostname=node3
[node1]
192.168.238.11
[node2]
192.168.238.12
[node3]
192.168.238.13
6,编写ftp源
[root@master root]# mkdir /opt/centos
[root@master root]# mount /dev/sr0 /opt/centos
[root@master root]# echo 'mount /dev/sr0 /opt/centos' >>/etc/rc.local
[root@master root]# chmod 777 /etc/rc.local
[root@master root]# chmod 777 /etc/rc.d/rc.local
[root@master root]# yum install vsftpd -y
[root@master root]# echo 'anon_root=/opt' >> /etc/vsftpd/vsftpd.conf
[root@master root]# systemctl start vsftpd && systemctl enable vsftpd
[root@master root]# cat /root/example/ftp.repo
[centos]
name=centos
baseurl=ftp://192.168.238.10/centos
enabled=1
gpgcheck=0
[yum]
name=yum
baseurl=http://yum.mariadb.org/10.3/centos74-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
enabled=1
gpgcheck=0
编写playbook剧本
[root@ansible example]# cat /root/example/cscc_install.yaml
--- - hosts: node remote_user: root tasks: - name: hostname shell: hostnamectl set-hostname {{hostname|quote}} - name: hosts shell: sed -i '$a 192.168.238.11 node1 \n192.168.238.12 node2 \n192.168.238.13 node3' /etc/hosts - name: selinux shell: setenforce 0 && systemctl stop firewalld - name: local.repo shell: rm -rf /etc/yum.repos.d/* - name: ftp.repo copy: src=ftp.repo dest=/etc/yum.repos.d/ - name:yum yum:name=boost-program-options.x86_64 state=present - name: yum mariadb galera yum: name=MariaDB-server,MariaDB-client,galera state=present - name: serivce service: name=mariadb state=started - name: admin pass shell: mysqladmin -uroot password '000000' - name: grant shell: mysql -uroot -p000000 -e "grant all privileges on *.* to 'root'@'%' identified by '000000';" - name: stop shell: systemctl stop mariadb - name: sed shell: sed -i '/galera/a wsrep_on=ON \nwsrep_provider=/usr/lib64/galera/libgalera_smm.so \nwsrep_cluster_address=gcomm://192.168.238.11,192.168.238.12,192.168.238.13 \nbinlog_format=row \ndefault_storage_engine=InnoDB \ninnodb_autoinc_lock_mode=2 \nwsrep_slave_threads=1 \ninnodb_flush_log_at_trx_commit=0 ' /etc/my.cnf.d/server.cnf - hosts: node1 remote_user: root tasks: - name: galera shell: galera_new_cluster - name: mariadb service: name=mariadb state=started - hosts: node2 remote_user: root tasks: - name: mariadb service: name=mariadb state=started - hosts: node3 remote_user: root tasks: - name: mariadb service: name=mariadb state=started
执行playbook
[root@ansible example]# ansible-playbook cscc_install.yaml
验证
标签:name,192.168,Ansible,集群,yum,master,mariadb,root From: https://www.cnblogs.com/Chen-Yi-jia/p/17795716.html