salt一键部署mysql

 

mysql-adduser:
 cmd.run:
  - name: 'groupadd mysql && useradd -r -g mysql mysql'

mysql-file:
  file.managed:
   - source: salt://mysql/mysql-5.5.46-linux2.6-x86_64.tar.gz
   - name: /usr/local/mysql-5.5.46-linux2.6-x86_64.tar.gz
   - user: root
   - group: root

mysql-install:
  cmd.run:
   - name: 'cd /usr/local && tar -xf mysql-5.5.46-linux2.6-x86_64.tar.gz && ln -s mysql-5.5.46-linux2.6-x86_64 mysql && chown -R mysql:mysql mysql*'
   - unless: 'test -d /usr/local/mysql-5.5.46-linux2.6-x86_64'
   - require:
     - file: mysql-file
	 
mysql-init:
  cmd.run:
   - name: 'cd /usr/local/mysql && scripts/mysql_install_db --user=mysql'
   - require:
     - cmd: mysql-install
	 
mysql-cp:
  cmd.run:
   - name: 'cd /usr/local/mysql && cp support-files/my-medium.cnf /etc/my.cnf && cp support-files/mysql.server  /etc/init.d/mysql.server'
   - require:
     - cmd: mysql-init
	 
mysql-rmtgz:
  file.absent:
    - name: /usr/local/mysql-5.5.46-linux2.6-x86_64.tar.gz
	- require:
     - cmd: mysql-cp
	 
/etc/profile:
  file.append:
    - text:
      - export MYSQL_HOME=/usr/local/mysql
      - export PATH=$MYSQL_HOME/bin:$PATH
	- require:
     - file: mysql-rmtgz
	 
source-profile:
   cmd.run:
    - name: 'source /etc/profile'
	- require:
      - file: /etc/profile

  

posted @ 2017-05-17 09:48  wyl9527  阅读(355)  评论(0编辑  收藏  举报