简介:
SaltStack是 一个服务器基础架构集中化管理平台,具备配置管理、远程执行、监控等功能,一般可以理解为简化版的puppet和加强版的func。SaltStack基 于Python语言实现,结合轻量级消息队列(ZeroMQ)与Python第三方模块(Pyzmq、PyCrypto、Pyjinjia2、 python-msgpack和PyYAML等)构建。
最近工作比较闲,所以继续学习saltstack,今天就用源码来安装MysqL数据库,学saltstack还是得多实践,废话不多说,上干货。
实验环境:
Master:www.master.com10.0.4.52Centos6.5 Slave:www.slave.com10.0.4.53Centos6.5
开始部署:
#cattop.sls base: '*': -init.install -MysqL.install
目录结构:
#treeinit/ init/ └──install.sls#主要安装MysqL数据库需要的依赖库。 #treeMysqL/#文件内容下面会给出。 MysqL/ ├──init.sh ├──install.sls ├──my.cnf#MysqL的主配置文件,自己根据要求来配置。 ├──MysqL-5.6.14.tar.gz └──MysqLd#MysqL的启动脚本,即是/etc/init.d/MysqLd。 0directories,5files
初始化配置文件:
#catinit/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
#catMysqL/install.sls include: -init.install MysqL-source-install: file.managed: -name:/usr/local/src/MysqL-5.6.14.tar.gz -source:salt://MysqL/MysqL-5.6.14.tar.gz -user:root -group:root -mode:755 cmd.run: -name:cd/usr/local/src/&&tarxfMysqL-5.6.14.tar.gz&&cdMysqL-5.6.14&&cmake-DCMAKE_INSTALL_PREFIX=/usr/local/webserver/MysqL5.6/-DMysqL_DATADIR=/usr/local/webserver/MysqL5.6/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&&makeinstall -require: -file:MysqL-source-install -unless:test-d/usr/local/webserver/MysqL5.6 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/webserver/MysqL5.6/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--addMysqLd -unless:chkconfig--list|grepMysqLd -require: -file:MysqL-service service.running: -name:MysqLd -require: -cmd:MysqL-service
MysqL初始化脚本:
#catMysqL/init.sh #!/bin/bash groupaddMysqL#saltstack也可以创建MysqL用户和组,这里就直接让它引用这个脚本。 useradd-r-gMysqLMysqL ln-s/usr/local/webserver/MysqL5.6/bin/MysqL/usr/bin/ cd/usr/local/webserver/MysqL5.6/scripts/&&./MysqL_install_db--basedir=/usr/local/webserver/MysqL5.6/--datadir=/usr/local/webserver/MysqL5.6/data/ rm-rf/etc/my.cnf cp-a/usr/local/webserver/MysqL5.6/support-files/my-default.cnf/usr/local/webserver/MysqL5.6/my.cnf chownMysqL:MysqL/usr/local/webserver/MysqL5.6/-R
好激动,要执行安装了
#salt'www.slave.com'state.highstate#强烈建议执行这命令之前先执行salt'www.slave.com'state.highstatetest=True来测试实验是否成功。 .......................................................... ---------- ID:MysqL-service Function:cmd.run Name:chkconfig--addMysqLd Result:True Comment:unlessexecutionsucceeded Started:11:01:55.890689 Duration:519.892ms Changes: ---------- ID:MysqL-service Function:service.running Name:MysqLd Result:True Comment:StartedServiceMysqLd Started:11:01:56.414994 Duration:2598.256ms Changes: ---------- MysqLd: True Summary ------------- Succeeded:32(changed=5) Failed:0 ------------- Totalstatesrun:32
minion端查看:
#netstat-anlp|grepMysqLd tcp00:::3306:::*LISTEN29890/MysqLd unix2[ACC]STREAMLISTENING89763829890/MysqLd/var/lib/MysqL/MysqL.sock
从上面看出MysqL已经在minion端安装成功了,之前各种报错,各种调试。总算成功了。还是那句话,多动手。