黑帽联盟
标题:
saltstack自动化安装编译mysql
[打印本页]
作者:
yun
时间:
2019-8-28 16:33
标题:
saltstack自动化安装编译mysql
本帖最后由 yun 于 2019-8-29 13:43 编辑
环境:centos6.7
172.31.225.250 node1.example.com
172.31.225.251 node2.example.com
我们所需要用到的相关文件都在 /srv/salt/prod/files/ 这个目录下面,大家直接下载即可:
mysql.zip
(29.35 MB, 下载次数: 0)
2019-8-29 13:34 上传
点击文件名下载附件
下载积分: 黑币 -1
2019-8-29 13:33 上传
下载附件
(14.45 KB)
master相关配置:(/etc/salt/master)
file_roots:
base:
- /srv/salt/base
dev:
- /srv/salt/dev
prod:
- /srv/salt/prod
pillar_roots:
base:
- /srv/salt/base/pillar
dev:
- /srv/salt/dev/pillar
prod:
- /srv/salt/prod/pillar
复制代码
开始部署lnmp,个人建议一个一个的部署,不要把nginx、php、mysql都部署在一个文件,这样的话,针对minion端,可以针对性的部署相应的服务
1、部署mysql(这里个人是编译安装)
首先下载源码包:
wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.45.tar.gz
初始化安装:
(/srv/salt/prod/init/install.sls)
pkg-init-install:
pkg.installed:
- names:
- gcc
- gcc-c++
- glibc
- make
- automake
- autoconf
- libjpeg-turbo-devel
- libpng
- libpng-devel
- freetype-devel
- libxml2
- libxml2-devel
- zlib
- zlib-devel
- libcurl
- libcurl-devel
- openssl
- openssl-devel
- swig
- cmake
- ncurses-devel
- libmcrypt
- libmcrypt-devel
- libtool-ltdl-devel
- bison
- git
复制代码
mysql安装:
(/srv/salt/prod/mysql.sls)
include:
- init.install
mysql-source:
file.managed:
- name: /usr/local/src/mysql-5.6.45.tar.gz
- source: salt://files/mysql-5.6.45.tar.gz
- user: root
- group: root
- mode: 644
mysql-install:
cmd.run:
- name: cd /usr/local/src && tar xf mysql-5.6.45.tar.gz && cd mysql-5.6.45 && cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DWITH_LIBWRAP=0 -DDEFAULT_COLLATION=utf8_general_ci && make && make install
- unless: test -d /usr/local/mysql
- require:
- pkg: pkg-init-install
- file: mysql-source
user-create:
cmd.run:
- name: groupadd mysql && useradd -r -g mysql mysql -s /sbin/nologin
- unless: id mysql
- require_in:
- cmd: mysql-chown
mysql-chown:
cmd.run:
- name: cd /usr/local/mysql && chown -R mysql:mysql . && echo 0 > user.txt
- unless: test -f /usr/local/mysql/user.txt
- require:
- cmd: mysql-install
- require_in:
- cmd: mysql-init
mysql-init:
cmd.run:
- name: cd /usr/local/mysql && scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
- unless: test -d /usr/local/mysql/data/mysql
- require:
- cmd: user-create
- cmd: mysql-install
mysql-conf:
file.managed:
- name: /etc/my.cnf
- source: salt://files/my.cnf
- user: root
- group: root
- mode: 644
/etc/init.d/mysqld:
file.managed:
- source: salt://files/mysql.server
- user: root
- group: root
- mode: 755
- require:
- cmd: mysql-install
- watch_in:
- service: mysql-service
mysql-chkconfig:
cmd.run:
- name: chkconfig --add mysqld
- unless: chkconfig --list | grep mysqld
- requre:
- file: /etc/init.d/mysqld
mysql-profile:
cmd.run:
- name: echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile && echo 'export PATH' >> /etc/profile && source /etc/profile && echo '0' > /etc/test.txt
- unless: test -f /etc/test.txt
- require:
- cmd: mysql-install
mysql-service:
service.running:
- name: mysqld
- enable: True
- watch:
- file: mysql-conf
复制代码
下面正式安装:
安装之前最好先进行测试安装,检查有没有错误,因为在生产环境下直接执行安装错误,会导致对外服务的相关组件有可能出现问题,所以先进性测试安装
salt '*' state.sls mysql env=prod test=True
复制代码
这里我测试没有问题,就直接安装了
salt '*' state.sls mysql env=prod
复制代码
查看mysql服务,或者查看3306端口起没起来
2019-8-28 16:33 上传
下载附件
(11.71 KB)
2019-8-28 16:33 上传
下载附件
(11.2 KB)
注意:在执行'
salt '*' state.sls mysql env=prod
' 这条命令的时候,最后会一直卡在那里,具体原因如下:
mysql5.6在启动后没有返回一个信号给salt,所以salt会一直卡着。把5.6的启动参数改为跟5.1一样,即可正常启动。
mysql5.1和mysql5.6对比:
2019-8-28 19:33 上传
下载附件
(20.96 KB)
改过之后,再次执行,一切正常
至此就结束了。原创不易,转载请注明原创来处,谢谢!
相关文章:
saltstack自动化编译安装php
saltstack自动化安装部署nginx
欢迎光临 黑帽联盟 (https://bbs.cnblackhat.com/)
Powered by Discuz! X2.5