您好,登錄后才能下訂單哦!
作者信息: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文件實現主機名方式解析地址
[root@node1 ~]# yum -y install salt-master # 配置salt-master [root@node1 ~]# cd /etc/salt/ [root@node1 salt]# vim master # The address of the interface to bind to: interface: 0.0.0.0 #取消此行注釋,監聽在任意地址 user: root #取消此行注釋,以root身份去運行salt file_roots: #找到file_roots配置salt.state模塊的文件位置 base: - /etc/salt/states #保存退出 #啟動salt-master [root@node1 salt]# /etc/init.d/salt-master start
[root@node2 ~]# yum -y install salt-minion [root@node2 ~]# cd /etc/salt/ [root@node2 salt]# vim minion # Set the location of the salt master server. If the master server cannot be # resolved, then the minion will fail to start. master: 192.168.2.159 #將salt改為salt-master端的IP地址 #保存退出 #啟動salt-minion [root@node2 salt]# /etc/init.d/salt-minion start
[root@node1 salt]# mkdir /etc/salt/states
[root@node1 salt]# cd /etc/salt/states/ [root@node1 states]# mkdir init [root@node1 states]# cd init/ [root@node1 init]# vi phppkg.sls php5installed: #自定義一個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
[root@node1 init]# cd ../ [root@node1 states]# mkdir php5 [root@node1 states]# cd php5/ [root@node1 php5]# vim phpinstall.sls include: - init.phppkg #使用include方法將phppkg.sls包含進來,作用就是先執行init下的phppkg.sls將依賴包安裝上 #注意:minion端/home/wangenzhi/tools這個目錄要事先存在否則復制不過去 phpinstalled: #自定義一個ID file.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: 644 cmd.run: #使用cmd模塊的run方法。可以執行任何命令 - name: cd /home/wangenzhi/tools/ && tar xf php-5.6.21.tar.xz && cd php-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 && make install - unless: test -d /usr/local/php/ # unless: 結果為True則不執行-name后面的命令,為false則執行
[root@node1 php5]# cd /etc/salt/states/php5/ [root@node1 php5]# vim phpconfig.sls #如果phpinstall執行成功則執行phpconfig.sls include: - 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: 755 cmd.run: #并添加為系統服務 - name: chkconfig --add php-fpm && chkconfig php-fpm on - unless: chkconfig --list | grep php-fpm #啟動php-fpm服務 php-service: cmd.run: - name: /etc/init.d/php-fpm restart - request: phpini # - request 意思是如果上面的phpini執行成功了則執行- name后面的命令去重啟php-fpm
#注意:執行過程中可能會出現某個依賴包yum找不到的情況 [root@node1 php5]# salt 'node2.enzhi.com' state.sls php5.phpconfig node2.enzhi.com: ---------- ID: php5installed Function: pkg.installed Name: freetype-devel Result: True Comment: Package freetype-devel is already installed. Started: 17:40:51.398777 Duration: 866.709 ms Changes: ---------- ID: php5installed Function: pkg.installed Name: freetds-devel Result: True Comment: Package freetds-devel is already installed. Started: 17:40:52.265671 Duration: 0.596 ms Changes: ---------- ID: php5installed Function: pkg.installed Name: libxml Result: False Comment: The following package(s) were not found, and no possible matches were found in the package db: libxml Started: 17:40:52.266356 Duration: 4081.753 ms Changes: ---------- ID: php5installed Function: pkg.installed Name: gd Result: True Comment: Package gd is already installed. Started: 17:40:56.348335 Duration: 0.776 ms Changes: ---------- ID: php5installed Function: pkg.installed Name: curl Result: True Comment: Package curl is already installed. Started: 17:40:56.349210 Duration: 0.423 ms Changes: ---------- ID: php5installed Function: pkg.installed Name: bzip2 Result: True Comment: Package bzip2 is already installed. Started: 17:40:56.349721 Duration: 0.429 ms Changes: ---------- ID: php5installed Function: pkg.installed Name: bzip2-devel Result: True Comment: Package bzip2-devel is already installed. Started: 17:40:56.350236 Duration: 0.451 ms Changes: ---------- ID: php5installed Function: pkg.installed Name: openssl-devel Result: True Comment: Package openssl-devel is already installed. Started: 17:40:56.350774 Duration: 0.423 ms Changes: ---------- ID: php5installed Function: pkg.installed Name: libpng Result: True Comment: Package libpng is already installed. Started: 17:40:56.351277 Duration: 0.422 ms Changes: ---------- ID: php5installed Function: pkg.installed Name: freetds Result: True Comment: Package freetds is already installed. Started: 17:40:56.351788 Duration: 0.418 ms Changes: ---------- ID: php5installed Function: pkg.installed Name: libmcrypt-devel Result: True Comment: Package libmcrypt-devel is already installed. Started: 17:40:56.352298 Duration: 0.449 ms Changes: ---------- ID: php5installed Function: pkg.installed Name: freetype Result: True Comment: Package freetype is already installed. Started: 17:40:56.352828 Duration: 0.629 ms Changes: ---------- ID: php5installed Function: pkg.installed Name: gd-devel Result: True Comment: Package gd-devel is already installed. Started: 17:40:56.353584 Duration: 0.423 ms Changes: ---------- ID: php5installed Function: pkg.installed Name: libxslt-devel Result: True Comment: Package libxslt-devel is already installed. Started: 17:40:56.354170 Duration: 0.442 ms Changes: ---------- ID: php5installed Function: pkg.installed Name: curl-devel Result: False Comment: Package 'curl-devel' not found (possible matches: libcurl-devel, libcurl-devel.i686) Started: 17:40:56.354712 Duration: 3452.342 ms Changes: ---------- ID: php5installed Function: pkg.installed Name: zlib-devel Result: True Comment: Package zlib-devel is already installed. Started: 17:40:59.807254 Duration: 0.687 ms Changes: ---------- ID: php5installed Function: pkg.installed Name: libjpeg-devel Result: False Comment: Package 'libjpeg-devel' not found (possible matches: libjpeg-turbo-devel, libjpeg-turbo-devel.i686) Started: 17:40:59.808032 Duration: 816.712 ms Changes: ---------- ID: php5installed Function: pkg.installed Name: libjpeg Result: False Comment: Package 'libjpeg' not found (possible matches: libjpeg-turbo, libjpeg-turbo.i686) Started: 17:41:00.624993 Duration: 1262.685 ms Changes: ---------- ID: php5installed Function: pkg.installed Name: libxml2-devel Result: True Comment: Package libxml2-devel is already installed. Started: 17:41:01.887927 Duration: 0.662 ms Changes: ---------- ID: php5installed Function: pkg.installed Name: zlib Result: True Comment: Package zlib is already installed. Started: 17:41:01.888682 Duration: 0.532 ms Changes: ---------- ID: php5installed Function: pkg.installed Name: libiconv Result: False Comment: The following package(s) were not found, and no possible matches were found in the package db: libiconv Started: 17:41:01.889304 Duration: 945.379 ms Changes: ---------- ID: php5installed Function: pkg.installed Name: libmcrypt Result: True Comment: Package libmcrypt is already installed. Started: 17:41:02.834894 Duration: 0.755 ms Changes: ---------- ID: php5installed Function: pkg.installed Name: php-mssql Result: True Comment: Package php-mssql is already installed. Started: 17:41:02.835757 Duration: 0.437 ms Changes: ---------- ID: php5installed Function: pkg.installed Name: libpng-devel Result: True Comment: Package libpng-devel is already installed. Started: 17:41:02.836280 Duration: 0.425 ms Changes: ---------- ID: phpinstalled Function: file.managed Name: /home/wangenzhi/tools/php-5.6.21.tar.xz Result: True Comment: File /home/wangenzhi/tools/php-5.6.21.tar.xz is in the correct state Started: 17:41:02.839835 Duration: 72.475 ms Changes: ---------- ID: phpinstalled Function: cmd.run Name: cd /home/wangenzhi/tools/ && tar xf php-5.6.21.tar.xz && cd php-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 && make install Result: True Comment: unless execution succeeded Started: 17:41:02.913239 Duration: 7.166 ms Changes: ---------- ID: phpini Function: file.managed Name: /etc/php.ini Result: True Comment: File /etc/php.ini updated Started: 17:41:02.921572 Duration: 27.204 ms Changes: ---------- diff: --- +++ @@ -5,10 +5,6 @@ ;;;;;;;;;;;;;;;;;;; ; PHP's initialization file, generally called php.ini, is responsible for ; configuring many of the aspects of PHP's behavior. -; hehe -; hehe -; haha -; hehe ; PHP attempts to find and load this configuration from a number of locations. ; The following is a summary of its search order: ---------- ID: phpfpmconf Function: file.managed Name: /usr/local/php/etc/php-fpm.conf Result: True Comment: File /usr/local/php/etc/php-fpm.conf is in the correct state Started: 17:41:02.948910 Duration: 3.481 ms Changes: ---------- ID: php-fpm Function: file.managed Name: /etc/rc.d/init.d/php-fpm Result: True Comment: File /etc/rc.d/init.d/php-fpm is in the correct state Started: 17:41:02.952524 Duration: 4.373 ms Changes: ---------- ID: php-fpm Function: cmd.run Name: chkconfig --add php-fpm && chkconfig php-fpm on Result: True Comment: unless execution succeeded Started: 17:41:02.957028 Duration: 25.414 ms Changes: ---------- ID: php-service Function: cmd.run Name: /etc/init.d/php-fpm restart Result: True Comment: Command "/etc/init.d/php-fpm restart" run Started: 17:41:02.982731 Duration: 1075.021 ms Changes: ---------- pid: 73614 retcode: 0 stderr: stdout: Gracefully shutting down php-fpm . done #可以看到重啟php-fpm Starting php-fpm done Summary ------------- Succeeded: 26 (changed=2) Failed: 5 ------------- Total states run: 31 #在minion端查看php-fpm端口是否在監聽 [root@node2 ~]# ss -tnl LISTEN 0 16384 127.0.0.1:9000
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。