上山打老虎 发表于 2021-7-4 09:17:36

在CentOS6上使用saltstack源码安装配置mysql

  环境:

salt_master:192.168.100.228
salt_client1:192.168.100.245master client 版本一致
# 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
#  开始安装部署文件:
top.sls文件
# cat top.sls
base:
'salt_client*':
      - mysql
#  目录结构:
# 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
#
# cat init.sls
include:
- mysql.install
- mysql.conf
#  安装mysql的主配置文件:
# cat install.sls
#install 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
#  

  mysql config 文件:
# 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 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
#  配置文件:
# tree files/
files/
├── conf.sh初始化文件
├── my.cnf配置文件
├── mysql-5.5.22.tar.gz安装包
├── mysqld启动脚本
└── mysqllns.sh软连接
0 directories, 5 files
#
# cat files/conf.sh
#!/bin/bash
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
# cat files/mysqllns.sh
#!/bin/bash
#lns
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/
#  


  
页: [1]
查看完整版本: 在CentOS6上使用saltstack源码安装配置mysql