Ansible部署MySQL编译安装
环境:
系统:centos7 x3
master:192.168.220.133
slave1:192.168.220.136
slave2:192.168.220.137
前期准备:
slave1(192.168.220.136):
[root@slave1~]# hostnamectl set-hostname slave1
[root@slave1~]# echo '192.168.220.136 slave1' >> /etc/hosts
slave1(192.168.220.137):
[root@slave1~]# hostnamectl set-hostname slave2
[root@slave1~]# echo '192.168.220.137 slave2' >> /etc/hosts
master(192.168/220/133):
[root@master ~]# yum -y install wget #下载wget工具
[root@master ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo #下载阿里Base源
[root@master ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo #下载阿里epel源
[root@master~]# echo '192.168.220.136 slave1 \n 192.168.220.137 slave2' >> /etc/hosts
免密登录:
[root@master ~]# ssh-keygen
[root@master ~]# for i in slave1 slave2 >do >ssh-copy-id $i >done
安装Ansible
[root@master ~]# yum install ansible -y
定义Ansible主机清单
-
ansible主配置文件:/etc/ansible/ansible.cfg
-
ansible默认清单文件:/etc/ansible/hosts
编辑清单文件定义主机组
[root@master ~]# vim /etc/ansible/hosts [websrvs] 192.168.220.136 192.168.220.137
从master上拷贝cmake和MySQL(master上提前上传了)
ansible webserv -m copy -a 'src=/root/cmake-2.8.6.tar.gz /root/mysql-5.6.36.tar.gz dest=/root && src=/root/cmake-2.8.6.tar.gz /root/mysql-5.6.36.tar.gz dest=/root/'
解压tar包
ansible webserv -m shell -a 'tar -zxf cmake-2.8.6.tar.gz -C /usr/src && tar -zxf mysql-5.6.36.tar.gz -C /usr/src'
安装环境perl运行组件
ansible webserv -m shell -a 'yum remove mysql -y && yum install -y ncurses-devel gcc gcc-c++ perl perl-devel perl-DBD*'
编辑安装make
nsible webserv -m shell -a 'cd /usr/src/cmake-2.8.6 && ./configure && gmake && gmake install'
编译安装MySQL
ansible webserv -m shell -a 'cd /usr/src/mysql-5.6.36 && cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all && cd /usr/src/mysql-5.6.36 && make && make install'
拷贝配置文件
ansible webserv -m shell -a 'rm -rf /etc/my.cnf && cp /usr/src/mysql-5.6.36/support-files/my-default.cnf /etc/my.cnf && cp /usr/src/mysql-5.6.36/support-files/mysql.server /etc/rc.d/init.d/mysqld && chmod a+x /etc/rc.d/init.d/mysqld'
添加MySQL服务到管理器
ansible webserv -m shell -a 'chkconfig --add mysqld && chkconfig mysql on'
优化MySQL命令路径
ansible webserv -m shell -a 'ln -s /usr/local/mysql/bin/* /usr/local/bin'
初始化MySQL
ansible webserv -m shell -a '/usr/local/mysql/scripts/mysql_install_db --user=mysql --group=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data'
启动MySQL服务
ansible webserv -m shell -a 'systemctl start mysqld'
此时就安装MySQL完成了!!!
本文来自博客园,作者:xiao智,转载请注明原文链接:https://www.cnblogs.com/yuwen01/p/16145844.html