centos7.3 使用salt部署mysql服务(yum安装方式)
部署环境:
master:CentOS Linux release 7.3.1611 192.168.25.135
minion:CentOS Linux release 7.3.1611 192.168.25.132
假定现在salt服务端和客户端已经安装完成。
master端配置,准备相关路径:
存放yum源相关
mkdir /srv/salt/yum/
存放mysql相关
mkdir /srv/salt/mysql
首先要先卸载掉系统自带的mysql服务,然后更新yum源,yum源跟新下载链接:
地址为 http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
下载yum源rpm包并安装:
rpm - ivh mysql-community-release-el7-5.noarch.rpm
查看yum源是否有mysql-*.repo
-rw-r--r--. 1 root root 1209 1月 29 2014 mysql-community.repo
-rw-r--r--. 1 root root 1060 1月 29 2014 mysql-community-source.repo
yum clean all
将mysql的repo文件拷贝到/srv/salt/yum/目录下
cp /etc/yum.repos.d/mysql* /srv/salt/yum/
将mysql配置文件复制到/srv/salt/mysql
cp /etc/my.cnf /srv/salt/mysql/my.cnf
准备top.sls 文件
# cat top.sls
base:
'*':
- mysql.mysql
- yum.yum
编写yum.sls文件
/etc/yum.repos.d/mysql-community.repo:
file.managed:
- source: salt://yum/mysql-community.repo
- user: root
- group: root
- mode: 644
/etc/yum.repos.d/mysql-community-source.repo:
file.managed:
- source: salt://yum/mysql-community-source.repo
- user: root
- group: root
- mode: 644
编写mysql.sls文件
# cat mysql/mysql.sls
mysql-server:
pkg.installed:
- name: mysql-community-server //注意centos7 系统的mysql包名
- require_in:
- file: mysql-server
file.managed:
- name: /etc/my.cnf
- source: salt://mysql/my.cnf
- user: root
- group: root
- mode: 640
service.running:
- name: mysqld
因为salt执行的是后是无序的,我们期望的是先执行yum.sls 在执行mysql.sls,这样mysql才能安装,所以需要现执行yum,在执行mysql
执行完成后在minion端能看到mysql*.repo文件
salt '*' state.highstate
被管理端验证,如果mysql能正常登陆,就说明配置成功。