利用saltstack批量安装php
作者信息:http://www.codegreen.cn
作者博客http://www.codegreen.cn
实验环境:
环境规划
主机名:node1.enzhi.com IP地址:192.168.2.159 角色:salt-master
主机名:node2.enzhi.com IP地址:192.168.2.198 角色:salt-minion
配置好时间同步及hosts文件实现主机名方式解析地址
安装salt-master:[root@node1~]#yum-yinstallsalt-master#配置salt-master[root@node1~]#cd/etc/salt/[root@node1salt]#vimmaster#Theaddressoftheinterfacetobindto:interface:0.0.0.0#取消此行注释,监听在任意地址user:root#取消此行注释,以root身份去运行saltfile_roots:#找到file_roots配置salt.state模块的文件位置base:-/etc/salt/states#保存退出#启动salt-master[root@node1salt]#/etc/init.d/salt-masterstart安装salt-minion:
[root@node2~]#yum-yinstallsalt-minion[root@node2~]#cd/etc/salt/[root@node2salt]#vimminion#Setthelocationofthesaltmasterserver.Ifthemasterservercannotbe#resolved,thentheminionwillfailtostart.master:192.168.2.159#将salt改为salt-master端的IP地址#保存退出#启动salt-minion[root@node2salt]#/etc/init.d/salt-minionstartsalt-master创建states目录:
[root@node1salt]#mkdir/etc/salt/states创建phppkg.sls安装php所依赖的软件包
[root@node1salt]#cd/etc/salt/states/[root@node1states]#mkdirinit[root@node1states]#cdinit/[root@node1init]#viphppkg.slsphp5installed:#自定义一个ID名称pkg.installed:#使用pkg模块的installed方法,开头两个空格-names:#-names声明有多个软件包每个软件包的名称写在下面,开头四个空格-openssl-devel#开头6个空格下面其它的一样-libmcrypt-libmcrypt-devel-bzip2-bzip2-devel-php-mssql-zlib-libxml-libjpeg-freetype-libpng-gd-curl-libiconv-zlib-devel-libxml2-devel-libjpeg-devel-freetype-devel-libpng-devel-gd-devel-curl-devel-libxslt-devel-freetds-freetds-devel创建phpinstall.sls安装php并提供源码包
[root@node1init]#cd../[root@node1states]#mkdirphp5[root@node1states]#cdphp5/[root@node1php5]#vimphpinstall.slsinclude:-init.phppkg#使用include方法将phppkg.sls包含进来,作用就是先执行init下的phppkg.sls将依赖包安装上#注意:minion端/home/wangenzhi/tools这个目录要事先存在否则复制不过去phpinstalled:#自定义一个IDfile.managed:#使用file模块的managed方法-name:/home/wangenzhi/tools/php-5.6.21.tar.xz#指定salt-minion端要被管理的文件,如果文件不存在就执行下面source的方法将文件复制过去-source:salt://files/php-5.6.21.tar.xz-user:root#指定文件复制过去后的属主-group:root-mode:644cmd.run:#使用cmd模块的run方法。可以执行任何命令-name:cd/home/wangenzhi/tools/&&tarxfphp-5.6.21.tar.xz&&cdphp-5.6.21/&&./configure--prefix=/usr/local/php--with-mysql=mysqlnd--with-mysqli=mysqlnd--with-openssl--enable-mbstring--with-freetype-dir--with-jpeg-dir--with-png-dir--with-zlib--with-libxml-dir=/usr--enable-xml--enable-sockets--enable-zip--enable-soap--enable-short-tags--enable-safe-mode--enable-bcmath--enable-shmop--enable-sysvsem--enable-inline-optimization--enable-fpm--with-mcrypt--with-config-file-path=/etc--with-config-file-scan-dir=/etc/php.d--with-bz2--with-gd--enable-gd-native-ttf--enable-maintainer-zts&&make&&makeinstall-unless:test-d/usr/local/php/#unless:结果为True则不执行-name后面的命令,为false则执行创建phpconfig.sls为php提供配置文件并启动服务
[root@node1php5]#cd/etc/salt/states/php5/[root@node1php5]#vimphpconfig.sls#如果phpinstall执行成功则执行phpconfig.slsinclude:-php5.phpinstall#为minion端提供php.ini配置文件phpini:file.managed:-name:/etc/php.ini-source:salt://files/php.ini-user:root-group:root-mode:644#为minion端提供php-fpm.conf配置文件phpfpmconf:file.managed:-name:/usr/local/php/etc/php-fpm.conf-source:salt://files/php-fpm.conf-user:root-group:root-mode:644#为minion端提供php-fpm启动脚本php-fpm:file.managed:-name:/etc/rc.d/init.d/php-fpm-source:salt://files/php-fpm-user:root-group:root-mode:755cmd.run:#并添加为系统服务-name:chkconfig--addphp-fpm&&chkconfigphp-fpmon-unless:chkconfig--list|grepphp-fpm#启动php-fpm服务php-service:cmd.run:-name:/etc/init.d/php-fpmrestart-request:phpini#-request意思是如果上面的phpini执行成功了则执行-name后面的命令去重启php-fpm执行测试:
#注意:执行过程中可能会出现某个依赖包yum找不到的情况[root@node1php5]#salt'node2.enzhi.com'state.slsphp5.phpconfignode2.enzhi.com:----------ID:php5installedFunction:pkg.installedName:freetype-develResult:TrueComment:Packagefreetype-develisalreadyinstalled.Started:17:40:51.398777Duration:866.709msChanges:----------ID:php5installedFunction:pkg.installedName:freetds-develResult:TrueComment:Packagefreetds-develisalreadyinstalled.Started:17:40:52.265671Duration:0.596msChanges:----------ID:php5installedFunction:pkg.installedName:libxmlResult:FalseComment:Thefollowingpackage(s)werenotfound,andnopossiblematcheswerefoundinthepackagedb:libxmlStarted:17:40:52.266356Duration:4081.753msChanges:----------ID:php5installedFunction:pkg.installedName:gdResult:TrueComment:Packagegdisalreadyinstalled.Started:17:40:56.348335Duration:0.776msChanges:----------ID:php5installedFunction:pkg.installedName:curlResult:TrueComment:Packagecurlisalreadyinstalled.Started:17:40:56.349210Duration:0.423msChanges:----------ID:php5installedFunction:pkg.installedName:bzip2Result:TrueComment:Packagebzip2isalreadyinstalled.Started:17:40:56.349721Duration:0.429msChanges:----------ID:php5installedFunction:pkg.installedName:bzip2-develResult:TrueComment:Packagebzip2-develisalreadyinstalled.Started:17:40:56.350236Duration:0.451msChanges:----------ID:php5installedFunction:pkg.installedName:openssl-develResult:TrueComment:Packageopenssl-develisalreadyinstalled.Started:17:40:56.350774Duration:0.423msChanges:----------ID:php5installedFunction:pkg.installedName:libpngResult:TrueComment:Packagelibpngisalreadyinstalled.Started:17:40:56.351277Duration:0.422msChanges:----------ID:php5installedFunction:pkg.installedName:freetdsResult:TrueComment:Packagefreetdsisalreadyinstalled.Started:17:40:56.351788Duration:0.418msChanges:----------ID:php5installedFunction:pkg.installedName:libmcrypt-develResult:TrueComment:Packagelibmcrypt-develisalreadyinstalled.Started:17:40:56.352298Duration:0.449msChanges:----------ID:php5installedFunction:pkg.installedName:freetypeResult:TrueComment:Packagefreetypeisalreadyinstalled.Started:17:40:56.352828Duration:0.629msChanges:----------ID:php5installedFunction:pkg.installedName:gd-develResult:TrueComment:Packagegd-develisalreadyinstalled.Started:17:40:56.353584Duration:0.423msChanges:----------ID:php5installedFunction:pkg.installedName:libxslt-develResult:TrueComment:Packagelibxslt-develisalreadyinstalled.Started:17:40:56.354170Duration:0.442msChanges:----------ID:php5installedFunction:pkg.installedName:curl-develResult:FalseComment:Package'curl-devel'notfound(possiblematches:libcurl-devel,libcurl-devel.i686)Started:17:40:56.354712Duration:3452.342msChanges:----------ID:php5installedFunction:pkg.installedName:zlib-develResult:TrueComment:Packagezlib-develisalreadyinstalled.Started:17:40:59.807254Duration:0.687msChanges:----------ID:php5installedFunction:pkg.installedName:libjpeg-develResult:FalseComment:Package'libjpeg-devel'notfound(possiblematches:libjpeg-turbo-devel,libjpeg-turbo-devel.i686)Started:17:40:59.808032Duration:816.712msChanges:----------ID:php5installedFunction:pkg.installedName:libjpegResult:FalseComment:Package'libjpeg'notfound(possiblematches:libjpeg-turbo,libjpeg-turbo.i686)Started:17:41:00.624993Duration:1262.685msChanges:----------ID:php5installedFunction:pkg.installedName:libxml2-develResult:TrueComment:Packagelibxml2-develisalreadyinstalled.Started:17:41:01.887927Duration:0.662msChanges:----------ID:php5installedFunction:pkg.installedName:zlibResult:TrueComment:Packagezlibisalreadyinstalled.Started:17:41:01.888682Duration:0.532msChanges:----------ID:php5installedFunction:pkg.installedName:libiconvResult:FalseComment:Thefollowingpackage(s)werenotfound,andnopossiblematcheswerefoundinthepackagedb:libiconvStarted:17:41:01.889304Duration:945.379msChanges:----------ID:php5installedFunction:pkg.installedName:libmcryptResult:TrueComment:Packagelibmcryptisalreadyinstalled.Started:17:41:02.834894Duration:0.755msChanges:----------ID:php5installedFunction:pkg.installedName:php-mssqlResult:TrueComment:Packagephp-mssqlisalreadyinstalled.Started:17:41:02.835757Duration:0.437msChanges:----------ID:php5installedFunction:pkg.installedName:libpng-develResult:TrueComment:Packagelibpng-develisalreadyinstalled.Started:17:41:02.836280Duration:0.425msChanges:----------ID:phpinstalledFunction:file.managedName:/home/wangenzhi/tools/php-5.6.21.tar.xzResult:TrueComment:File/home/wangenzhi/tools/php-5.6.21.tar.xzisinthecorrectstateStarted:17:41:02.839835Duration:72.475msChanges:----------ID:phpinstalledFunction:cmd.runName:cd/home/wangenzhi/tools/&&tarxfphp-5.6.21.tar.xz&&cdphp-5.6.21/&&./configure--prefix=/usr/local/php--with-mysql=mysqlnd--with-mysqli=mysqlnd--with-openssl--enable-mbstring--with-freetype-dir--with-jpeg-dir--with-png-dir--with-zlib--with-libxml-dir=/usr--enable-xml--enable-sockets--enable-zip--enable-soap--enable-short-tags--enable-safe-mode--enable-bcmath--enable-shmop--enable-sysvsem--enable-inline-optimization--enable-fpm--with-mcrypt--with-config-file-path=/etc--with-config-file-scan-dir=/etc/php.d--with-bz2--with-gd--enable-gd-native-ttf--enable-maintainer-zts&&make&&makeinstallResult:TrueComment:unlessexecutionsucceededStarted:17:41:02.913239Duration:7.166msChanges:----------ID:phpiniFunction:file.managedName:/etc/php.iniResult:TrueComment:File/etc/php.iniupdatedStarted:17:41:02.921572Duration:27.204msChanges:----------diff:---+++@@-5,10+5,6@@;;;;;;;;;;;;;;;;;;;;PHP'sinitializationfile,generallycalledphp.ini,isresponsiblefor;configuringmanyoftheaspectsofPHP'sbehavior.-;hehe-;hehe-;haha-;hehe;PHPattemptstofindandloadthisconfigurationfromanumberoflocations.;Thefollowingisasummaryofitssearchorder:----------ID:phpfpmconfFunction:file.managedName:/usr/local/php/etc/php-fpm.confResult:TrueComment:File/usr/local/php/etc/php-fpm.confisinthecorrectstateStarted:17:41:02.948910Duration:3.481msChanges:----------ID:php-fpmFunction:file.managedName:/etc/rc.d/init.d/php-fpmResult:TrueComment:File/etc/rc.d/init.d/php-fpmisinthecorrectstateStarted:17:41:02.952524Duration:4.373msChanges:----------ID:php-fpmFunction:cmd.runName:chkconfig--addphp-fpm&&chkconfigphp-fpmonResult:TrueComment:unlessexecutionsucceededStarted:17:41:02.957028Duration:25.414msChanges:----------ID:php-serviceFunction:cmd.runName:/etc/init.d/php-fpmrestartResult:TrueComment:Command"/etc/init.d/php-fpmrestart"runStarted:17:41:02.982731Duration:1075.021msChanges:----------pid:73614retcode:0stderr:stdout:Gracefullyshuttingdownphp-fpm.done#可以看到重启php-fpmStartingphp-fpmdoneSummary-------------Succeeded:26(changed=2)Failed:5-------------Totalstatesrun:31#在minion端查看php-fpm端口是否在监听[root@node2~]#ss-tnlLISTEN016384127.0.0.1:9000
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。