• CentOS 7使用Saltstack源码安装MySQL 5.7.32


    简介:

      SaltStack是一个服务器基础架构集中化管理平台,具备配置管理、远程执行、监控等功能,一般可以理解为简化版的puppet和加强版的func。SaltStack基 于Python语言实现,结合轻量级消息队列(ZeroMQ)与Python第三方模块(Pyzmq、PyCrypto、Pyjinjia2、 python-msgpack和PyYAML等)构建。

     

    实验环境:

    Master: www.master.com 10.0.4.52   CentOS 7.5
    Slave:  www.slave.com  10.0.4.53   CentOS 7.5
     

    开始部署:

    # cat top.sls 
    base:
      '*':
        - init.install
        - mysql.install
     

    目录结构:

    # tree init/
    init/
    └── install.sls                #主要安装mysql数据库需要的依赖库。
    # tree mysql/                  #文件内容下面会给出。
    mysql/
    ├── init.sh
    ├── install.sls
    ├── my.cnf                  #mysql的主配置文件,自己根据要求来配置。
    ├── mysql-5.7.32.tar.gz
    └── mysqld                   #mysql的启动脚本,即是/etc/init.d/mysqld。
    0 directories, 5 files
     

    初始化配置文件:

    # cat init/install.sls 
    pkg-init:  
      pkg.installed:
        - names:
          - gcc
          - gcc-c++
          - glibc
          - make
          - autoconf
          - libjpeg-turbo
          - libjpeg-turbo-devel
          - libpng
          - libpng-devel
          - freetype
          - freetype-devel
          - libxml2
          - libxml2-devel
          - zlib
          - zlib-devel
          - libcurl
          - libcurl-devel
          - openssl
          - openssl-devel
          - swig
          - cmake
          - ncurses
          - ncurses-devel
          - libtool-ltdl-devel
     

    安装mysql主配置文件:

    # cat mysql/install.sls
    include:
      - init.install
    
    mysql-source-install:
      file.managed:
        - name: /usr/local/src/mysql-5.7.32.tar.gz
        - source: salt://mysql/mysql-5.7.32.tar.gz
        - user: root
        - group: root
        - mode: 755
      cmd.run:
        - name: cd /usr/local/src/ && tar -zvxf mysql-5.7.32.tar.gz && cd mysql-5.7.32 && cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ -DMYSQL_DATADIR=/usr/local/mysql/data -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci && make -j 4 && make install
        - require:
          - file: mysql-source-install
        - unless: test -d /usr/local/mysql
    
    mysql-init:
      file.managed:
        - name: /usr/local/src/init.sh
        - source: salt://mysql/init.sh
        - user: root
        - group: root
        - mode: 755
      cmd.script:
        - name: /usr/local/src/init.sh
        - require:
          - cmd: mysql-source-install
    
    mysql-config:
      file.managed:
        - name: /usr/local/mysql/my.cnf
        - source: salt://mysql/my.cnf
        - user: root
        - group: root
        - mode: 644
        - require:
          - file: mysql-init
    
    mysql-service:
      file.managed:
        - name: /etc/init.d/mysqld
        - source: salt://mysql/mysqld
        - user: root
        - group: root
        - mode: 755
      cmd.run:
        - name: chkconfig --add mysqld
        - unless: chkconfig --list |grep mysqld
        - require:
          - file: mysql-service
      service.running:
        - name: mysqld
        - require:
          - cmd: mysql-service
     

    MySQL初始化脚本:

    # cat mysql/init.sh 
    #!/bin/bash
    groupadd mysql
    useradd -r -g -s /bin/nologin mysql mysql
    ln -s /usr/local/mysql/bin/mysql /usr/bin/
    cd /usr/local/mysql/scripts && ./mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
    rm -rf /etc/my.cnf
    cp -a /usr/local/mysql/support-files/my-default.cnf /usr/local/mysql/my.cnf
    chown -R mysql:mysql /usr/local/webserver/mysql
     

    执行安装

    # salt '10.0.4.53' state.highstate #强烈建议执行这命令之前先执行salt '10.0.4.53' state.highstate test=True来测试实验是否成功。 
    ..........................................................
    ----------
    ID: mysql-service Function: cmd.run Name: chkconfig --add mysqld
    Result: True Comment: unless execution succeeded
    Started: 11:01:55.890689
    Duration: 519.892 ms Changes:
    ----------
    ID: mysql-service Function: service.running Name: mysqld
    Result: True Comment: Started Service mysqld
    Started: 11:01:56.414994
    Duration: 2598.256 ms Changes:
    ----------
    mysqld: True Summary
    -------------
    Succeeded: 32 (changed=5)
    Failed: 0
    -------------
    Total states run: 32
     

    minion端查看:

    # netstat -anlp |grep mysqld
    tcp        0      0 :::3306                     :::*                        LISTEN      29890/mysqld        
    unix  2      [ ACC ]     STREAM     LISTENING     897638 29890/mysqld        /var/lib/mysql/mysql.sock

    MySQL已经在minion端安装成功。

  • 相关阅读:
    解决配置Windows Update失败问题
    Rabbit MQ 消息确认和持久化机制
    Spring Boot事务管理(上)
    Spring Boot事务管理(中)
    Spring Boot事务管理(下)
    接口和抽象类的区别
    MySQL索引优化
    Spring 注解之@RestController与@Controller的区别
    Spring Boot核心注解@SpringBootApplication
    Java抽象类与接口的区别
  • 原文地址:https://www.cnblogs.com/OrcinusOrca/p/14767067.html
Copyright © 2020-2023  润新知