主机环境:
master 192.168.199.130 rhel7.2
minion 192.168.199.66 rhel6.5
防火墙关闭,Selinux关闭
以下配置都在master端进行
1. 编写编译安装cmake的配置文件
由于mysql5.5以上的版本改用cmake编译了,所以要装cmake(rhel6.5镜像中的cmake安装包版本太低,需要单独编译安装,版本不能低于2.8.10)。
wget http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz -O /srv/salt/mysql/files/cmake-2.8.10.2.tar.gz
[root@lockey151 mysql]# cat cmake.sls
cmake-install:
file.managed:
- name: /mnt/cmake-2.8.10.2.tar.gz
- source: salt://mysql/files/cmake-2.8.10.2.tar.gz
cmd.run:
- name: cd /mnt && tar -xzvf cmake-2.8.10.2.tar.gz && cd /mnt/cmake-2.8.10.2 && ./configure && make && make install
- creates: /mnt/cmake-2.8.10.2
2. 编写mysql安装所需依赖包安装配置文件:
[root@lockey151 salt]# cat pkg/lnmp-pre.sls
pkg-init:
pkg.installed:
- pkgs:
- gcc-c++
- pcre-devel
- ncurses-devel
- bison
3. mysql运行用户配置文件创建
[root@lockey151 salt]# cat user/mysql.sls
mysql:
group.present:
- gid: 27
user.present:
- uid: 27
- gid: 27
- shell: /sbin/nologin
- home: /usr/local/haproxy
- createhome: false
4. 编写mysql安装正式配置文件:
[root@lockey151 mysql]# cat install.sls
include:
- pkg.lnmp-pre
- mysql.cmake
nginx-source-install:
file.managed:
- name: /mnt/mysql-boost-5.7.19.tar.gz
- source: salt://mysql/files/mysql-boost-5.7.19.tar.gz
cmd.run:
- name: cd /mnt && tar zxf mysql-boost-5.7.19.tar.gz && cd mysql-5.7.19 && /usr/local/bin/cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DWITH_BOOST=./boost/boost_1_59_0 -DSYSCONFDIR=/etc -DENABLED_LOCAL_INFILE=1 -DEXTRA_CHARSETS=all -DEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci && make && make install && cd /usr/local/mysql && mkdir data && chown -R mysql:mysql .
- creates: /usr/local/mysql
5. 设置服务状态以及配置推送
[root@lockey151 salt]# cat mysql/service.sls
include:
- mysql.install
- user.mysql
/etc/my.cnf:
file.managed:
- source: salt://mysql/files/my.cnf
- mode: 644
/etc/init.d/mysqld :
file.managed:
- source: salt://mysql/files/mysqld
- mode: 755
mysql-service:
service.running:
- name: mysql
- enable: true
- reload: true
- require:
- file: /etc/init.d/mysqld
- watch:
- file: /etc/my.cnf
配置完成之后目录结构如下:
6.测试配置并执行推送
[root@lockey151 salt]# salt lockey41 state.sls mysql.install
在minion端观察进展
成功后master端返回的状态:
初始化数据库
提示错误:
[ERROR] COLLATION 'utf8_general_ci' is not valid for CHARACTER SET 'latin1'
解决方法:
在配置文件my.cnf中添加字符设定:
character_set_server=utf8