首页 > 代码库 > (八)saltstack项目实战_安装mysql

(八)saltstack项目实战_安装mysql


1.1安装mysql

2.2查看salt-master、salt-minion配置文件

[root@node1 ~]# 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

[root@node2 ~]# grep -Ev ‘^#|^$‘ /etc/salt/minion

master: 172.168.200.210

id: node2

log_file: /data/logs/salt/minion

2.3 查看salt mysql目录结构


[root@node1 ~]# cd /data/etc/salt

[root@node1 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文件


[root@node1 salt]# cat top.sls

base:

  ‘*‘:

    - mysql.init

[root@node1 salt]# cd mysql/

[root@node1 mysql]# cat init.sls

include:

  - mysql.install

  - mysql.conf

[root@node1 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

   

[root@node1 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配置文件


[root@node1 ~]# cd /data/etc/salt/mysql/files/

[root@node1 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启动脚本添加下面路径

[root@node1 files]# cat mysqld

#!/bin/sh


 

basedir=/usr/local/mysql-5.6/

datadir=/usr/local/mysql-5.6/data/


2.7 模拟执行salt

1

[root@node1 salt]# salt ‘node2‘ state.highstate  test=True    -> 无报错即可



[root@node1 salt]# salt ‘node2‘ state.highstate   ->开始安装mysql


本文出自 “比尔linux运维笔记” 博客,请务必保留此出处http://chenshoubiao.blog.51cto.com/6159058/1884498

(八)saltstack项目实战_安装mysql