使用saltstack来源码安装mysql

环境:

salt_master:    192.168.100.228
salt_client1:    192.168.100.245

master client 版本一致
[root@salt_server base]# salt --versions-report
       Salt: 0.17.5
     Python: 2.6.6 (r266:84292, Jun 18 2012, 14:18:47)
     Jinja2: unknown
   M2Crypto: 0.20.2
 msgpack-python: 0.1.13
   msgpack-pure: Not Installed
   pycrypto: 2.0.1
     PyYAML: 3.10
      PyZMQ: 2.2.0.1
        ZMQ: 3.2.3
[root@salt_server base]# 

开始安装部署文件:

top.sls文件
[root@salt_server base]# cat top.sls 
base:
  'salt_client*':
      - mysql
[root@salt_server base]#

目录结构:

[root@salt_server base]# tree mysql/
mysql/
├── conf.sls
├── files
│   ├── conf.sh
│   ├── my.cnf
│   ├── mysql-5.5.22.tar.gz
│   ├── mysqld
│   └── mysqllns.sh
├── init.sls
└── install.sls

1 directory, 8 files
[root@salt_server base]# 

####主配置文件
[root@salt_server mysql]# cat init.sls 
include:
  - mysql.install
  - mysql.conf
[root@salt_server mysql]# 

安装mysql install配置文件:

[root@salt_server mysql]# cat install.sls 
#nstall source mysql
mysql_source:
  file.managed:
    - name: /home/mysql-5.5.22.tar.gz
    - unless: test -e /home/mysql-5.5.22.tar.gz
    - source: salt://mysql/files/mysql-5.5.22.tar.gz

#tar source mysql
extract_mysql:
  cmd.run:
    - cwd: /home
    - names:
        - tar xf mysql-5.5.22.tar.gz
        - chown root:root /home/mysql-5.5.22 -R
    - unless: test -d /home/mysql-5.5.22
    - 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 pkg.install
mysql_pkg:
  pkg.installed:
    - pkgs:
      - gcc
      - gcc-c++
      - autoconf
      - automake
      - openssl
      - openssl-devel
      - zlib
      - zlib-devel
      - ncurses-devel
      - libtool-ltdl-devel
      - cmake

#mysql source install
mysql_commpile:
  cmd.run:
    - cwd: /home/mysql-5.5.22
    - names:
        - cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DDEFAULT_CHARSET=utf8  -DDEFAULT_COLLATTON=utf8_cuicode_ci   -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_EMBEDDED_SERVER=1  -DENABLED_LOCAL_INFILE=1 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_DEBUG=0
        - make
        - make install
    - require:
        - cmd.run: extract_mysql
        - pkg: mysql_pkg
    - unless: test -d /usr/local/mysql

[root@salt_server mysql]# 

安装mysql config 文件:

[root@salt_server mysql]# cat conf.sls 
include:
  - mysql.install
## mysql for config
mysql_cnf:
  file.managed:
    - name: /etc/my.cnf
    - user: root
    - mode: 755
    - source: salt://mysql/files/my.cnf

# mysql init 
salt://mysql/files/conf.sh:
  cmd.script:
      - env:
          - BATCH: 'yes'
      - require:
          - cmd.run: mysql_commpile
          - pkg: mysql_pkg 
# mysql lns 
salt://mysql/files/mysqllns.sh:
  cmd.script:
        - env:
             - BATCH: 'yes'
         - require:
          - cmd.run: mysql_commpile
         - pkg: mysql_pkg

# mysql server
mysql_service:
   file.managed:
     - name: /etc/init.d/mysqld
     - user: root
     - mode: 755
     - source: salt://mysql/files/mysqld
   cmd.run:
     - names:
         - /sbin/chkconfig --add mysqld
         - /sbin/chkconfig --level 35 mysqld on
     - unless: /sbin/chkconfig --list mysqld
   service.running:
     - name: mysqld
     - enable: True
     - reload: True
[root@salt_server mysql]# 

files配置文件说明:

[root@salt_server mysql]# tree files/
files/
├── conf.sh                        初始化文件
├── my.cnf                        配置文件
├── mysql-5.5.22.tar.gz            安装包
├── mysqld                        启动脚本
└── mysqllns.sh                    软连接

0 directories, 5 files
[root@salt_server mysql]# 

安装mysql 初始化文件:

[root@salt_server mysql]# cat files/conf.sh 
#!/bin/bash
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

mysql 软连接等相关配置

[root@salt_server mysql]# cat files/mysqllns.sh 
#!/bin/bash
ln -sv /usr/local/mysql/bin/mysql /usr/bin 
ln -sv /usr/local/mysql/bin/mysqladmin /usr/bin/
ln -sv /usr/local/mysql/bin/mysqldump /usr/bin/
#mysq competence
/bin/chown -R mysql.mysql /usr/local/mysql/ && /bin/chown -R mysql.mysql /usr/local/mysql/data/
[root@salt_server mysql]# 

测试:

salt 'salt_client1' state.highstate test=true

实施:

salt 'salt_client1' state.highstate
OpsNotes wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!
坚持原创技术分享,您的支持将鼓励我继续创作!