saltstack项目实战_安装mysql
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了saltstack项目实战_安装mysql相关的知识,希望对你有一定的参考价值。
1.1安装mysql
2.2查看salt-master、salt-minion配置文件
[[email protected] ~]# grep -Ev ‘^#|^$‘ /etc/salt/master
interface: 0.0.0.0
file_roots:
base:
- /data/etc/salt
prod:
- /data/etc/salt/prod
log_file: /data/logs/salt/master
[[email protected] ~]# grep -Ev ‘^#|^$‘ /etc/salt/minion
master: 172.168.200.210
id: node2
log_file: /data/logs/salt/minion
2.3 查看salt mysql目录结构
[[email protected] ~]# cd /data/etc/salt
[[email protected] salt]# tree mysql/
mysql/
|-- conf.sls -> mysql salt配置文件
|-- files
| |-- my.cnf -> mysql配置文件
| |-- mysql-5.6.32.tar.gz -> mysql软件包
| `-- mysqld -> mysql启动脚本
|-- init.sls -> salt初始化文件
`-- install.sls -> mysql install文件
2.4 编写 mysql sls文件
[[email protected] salt]# cat top.sls
base:
‘*‘:
- mysql.init
[[email protected] salt]# cd mysql/
[[email protected] mysql]# cat init.sls
include:
- mysql.install
- mysql.conf
[[email protected] mysql]# cat install.sls
#mysql pkg.install
mysql_pkg:
pkg.installed:
- names:
- gcc
- gcc-c++
- autoconf
- automake
- openssl
- openssl-devel
- zlib
- zlib-devel
- ncurses-devel
- libtool-ltdl-devel
- cmake
#install source mysql
mysql_source:
file.managed:
- name: /usr/local/src/mysql-5.6.32.tar.gz
- unless: test -e /usr/local/src/mysql-5.6.32.tar.gz
- source: salt://mysql/files/mysql-5.6.32.tar.gz
#tar source mysql
extract_mysql:
cmd.run:
- cwd: /usr/local/src
- names:
- tar zxf mysql-5.6.32.tar.gz
- chown -R root:root /usr/local/src/mysql-5.6.32
- unless: tests -d /usr/local/src/mysql-5.6.32
- require:
- file: mysql_source
#useradd for mysql
mysql_user:
user.present:
- name: mysql
- uid: 1024
- createhome: False
- gid_from_name: True
- shell: /sbin/nologin
#mysql source install
mysql_commpile:
cmd.run:
- name: cd /usr/local/src/mysql-5.6.32 && cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.6 -DMYSQL_DATADIR=/usr/local/mysql-5.6/data -DMYSQL_UNIX_ADDR=/usr/local/mysql-5.6/data/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DENABLED_LOCAL_INFILE=ON -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH-BLACKHOLE_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DWITHOUT_PARTITION_STORAGE_ENGING=1 -DWITH_FAST_MUTEXES=1 -DWITH_ZLIB=bundled -DENABLED_LOCAL_INFIL=1 -DWITH_READLINE=1 -DWITH_EMBEDDED_SERVER=1 -DWITH_DEBUG=0 && make && make install && /usr/local/mysql-5.6/scripts/mysql_install_db --basedir=/usr/local/mysql-5.6/ --datadir=/usr/local/mysql-5.6/data/ --user=mysql
- require:
- cmd: extract_mysql
- pkg: mysql_pkg
- unless: test -d /usr/local/mysql-5.6
#mysql initialize
#mysql_initialize:
# cmd.run:
# - cwd: /usr/local/mysql-5.6/scripts/
# - names:
# - ./mysql_install_db --basedir=/usr/local/mysql-5.6/ --datadir=/usr/local/mysql-5.6/data/ --user=mysql
[[email protected] mysql]# cat conf.sls
include:
- mysql.install
#mysql for config
mysql_cnf:
file.managed:
- name: /usr/local/mysql-5.6/my.cnf
- user: root
- mode: 755
- source: salt://mysql/files/my.cnf
#myql server
mysql_service:
file.managed:
- name: /etc/init.d/mysqld
- source: salt://mysql/files/mysqld
- user: root
- mode: 755
cmd.run:
- names:
- /sbin/chkconfig --add mysqld
- /sbin/chkconfig --level 35 mysqld on
- unless: /sbin/chkconfig --list mysqld
2.5 mysql配置文件
[[email protected] ~]# cd /data/etc/salt/mysql/files/
[[email protected] files]# cat my.cnf
[mysqld]
socket=/usr/local/mysql-5.6/data/mysql.sock
datadir=/usr/local/mysql-5.6/data
symbolic-links=0
log-error=/var/log/mysql_error.log
pid-file=/usr/local/mysql-5.6/data/mysqld.pid
slow-query-log-file = /var/log/mysql_slow_querys.log
skip-name-resolve
skip-grant-tables
2.6 mysql启动脚本添加下面路径
[[email protected] files]# cat mysqld
#!/bin/sh
basedir=/usr/local/mysql-5.6/
datadir=/usr/local/mysql-5.6/data/
2.7 模拟执行salt
1
[[email protected] salt]# salt ‘node2‘ state.highstate test=True -> 无报错即可
[[email protected] salt]# salt ‘node2‘ state.highstate ->开始安装mysql
本文出自 “比尔linux运维笔记” 博客,请务必保留此出处http://chenshoubiao.blog.51cto.com/6159058/1884498
以上是关于saltstack项目实战_安装mysql的主要内容,如果未能解决你的问题,请参考以下文章