SaltStack的salt-ssh使用及LAMP状态设计部署
生活随笔
收集整理的這篇文章主要介紹了
SaltStack的salt-ssh使用及LAMP状态设计部署
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
SaltStack的salt-ssh使用及LAMP狀態(tài)設(shè)計(jì)部署
1、salt-ssh的使用
官方文檔:https://docs.saltstack.com/en/2016.11/topics/ssh/index.html
(1)安裝salt-ssh [root@linux-node1 ~]# yum install -y salt-ssh(2)配置salt-ssh [root@linux-node1 ~]# vim /etc/salt/roster linux-node1:host: 192.168.56.11user: rootpasswd: 123123 linux-node2:host: 192.168.56.12user: rootpasswd: 123123(3)使用ssh遠(yuǎn)程執(zhí)行 [root@linux-node1 ~]# salt-ssh '*' -r 'uptime' linux-node2:----------retcode:0stderr:stdout:root@192.168.56.12's password: 14:07:19 up 14 days, 8:41, 2 users, load average: 0.04, 0.08, 0.07 linux-node1:----------retcode:0stderr:stdout:root@192.168.56.11's password: 14:07:20 up 23 days, 8:13, 2 users, load average: 2.86, 0.81, 0.342、配置管理
(1)什么是狀態(tài)?
所謂的狀態(tài)就是希望系統(tǒng)運(yùn)行某些命令之后的結(jié)果。描述狀態(tài)使用YAML格式的文件。SLS:salt state
舉例安裝apache,如下:
(2) LAMP的狀態(tài)設(shè)計(jì)與實(shí)現(xiàn)部署
1、設(shè)計(jì)分析
| 使用模塊 | pkg | file | service |
| LAMP | httpd、php、mariadb、mariadb-server、php-mysql、php-pdo、php-cli | /etc/httpd/conf/httpd.conf、/etc/php.ini | httpd、mysqld |
2、Aapche的狀態(tài)配置
[root@linux-node1 prod]# pwd /srv/salt/prod [root@linux-node1 prod]# mkdir apache php mysql [root@linux-node1 prod]# tree . ├── apache ├── mysql └── php3 directories, 0 files[root@linux-node1 prod]# cd apache/ [root@linux-node1 apache]# vim apache.sls #編寫apache的狀態(tài)模塊 apache-install:pkg.installed:- name: httpdapache-config:file.managed:- name: /etc/httpd/conf/httpd.conf- source: salt://apache/files/httpd.conf #salt://代表著環(huán)境的根路徑- user: root- group: root- mode: 644apache-service:service.running:- name: httpd- enable: True [root@linux-node1 apache]# mkdir files #創(chuàng)建source目錄 [root@linux-node1 apache]# cd files/ [root@linux-node1 files]# cp /etc/httpd/conf/httpd.conf . [root@linux-node1 apache]# tree . ├── apache.sls └── files└── httpd.conf1 directory, 2 files [root@linux-node1 apache]# salt 'linux-node1' state.sls apache.apache saltenv=prod3、php的狀態(tài)配置
[root@linux-node1 prod]# cd php [root@linux-node1 php]# mkdir files [root@linux-node1 php]# vim init.sls php-install:pkg.installed:- pkgs:- php- php-pdo- php-mysqlphp-config:file.managed:- name: /etc/php.ini- source: salt://php/files/php.ini- user: root- group: root- mode: 644 [root@linux-node1 php]# cp /etc/php.ini files/ [root@linux-node1 php]# tree . ├── files │ └── php.ini └── init.sls1 directory, 2 files4、mysql的狀態(tài)配置
[root@linux-node1 prod]# cd mysql/ [root@linux-node1 mysql]# vim init.sls mysql-install:pkg.installed:- pkgs:- mariadb- mariadb-servermysql-config:file.managed:- name: /etc/my.cnf- source: salt://mysql/files/my.cnf- user: root- gourp: root- mode: 644mysql-service:service.running:- name: mariadb-server- enable: True [root@linux-node1 mysql]# mkdir files [root@linux-node1 mysql]# cp /etc/my.cnf files/ [root@linux-node1 prod]# tree . ├── apache │ ├── files │ │ └── httpd.conf │ └── init.sls ├── mysql │ ├── files │ │ └── my.cnf │ └── init.sls └── php├── files│ └── php.ini└── init.sls [root@linux-node1 prod]# salt -S '192.168.56.11' state.sls php.init saltenv=prod linux-node1.example.com: ----------ID: php-installFunction: pkg.installedResult: TrueComment: The following packages were installed/updated: php-mysqlThe following packages were already installed: php-pdo, phpStarted: 10:30:14.780998Duration: 118711.436 msChanges: ----------php-mysql:----------new:5.4.16-43.el7_4old: ----------ID: php-configFunction: file.managedName: /etc/php.iniResult: TrueComment: File /etc/php.ini is in the correct stateStarted: 10:32:13.556562Duration: 51.913 msChanges: Summary for linux-node1.example.com ------------ Succeeded: 2 (changed=1) Failed: 0 ------------ Total states run: 2 Total run time: 118.763 s5、寫入top file,執(zhí)行高級(jí)狀態(tài)
[root@linux-node1 base]# pwd /srv/salt/base [root@linux-node1 base]# vim top.sls prod:'linux-node1.example.com':- apache.init- php.init- mysql.init [root@linux-node1 base]# salt 'linux-node1*' state.highstate linux-node1.example.com: ----------ID: apache-installFunction: pkg.installedName: httpdResult: TrueComment: All specified packages are already installedStarted: 10:39:04.214911Duration: 762.144 msChanges: ----------ID: apache-configFunction: file.managedName: /etc/httpd/conf/httpd.confResult: TrueComment: File /etc/httpd/conf/httpd.conf is in the correct stateStarted: 10:39:04.979376Duration: 13.105 msChanges: ----------ID: apache-serviceFunction: service.runningName: httpdResult: TrueComment: The service httpd is already runningStarted: 10:39:04.992962Duration: 36.109 msChanges: ----------ID: php-installFunction: pkg.installedResult: TrueComment: All specified packages are already installedStarted: 10:39:05.029241Duration: 0.65 msChanges: ----------ID: php-configFunction: file.managedName: /etc/php.iniResult: TrueComment: File /etc/php.ini is in the correct stateStarted: 10:39:05.029987Duration: 10.642 msChanges: ----------ID: mysql-installFunction: pkg.installedResult: TrueComment: All specified packages are already installedStarted: 10:39:05.040793Duration: 0.422 msChanges: ----------ID: mysql-configFunction: file.managedName: /etc/my.cnfResult: TrueComment: File /etc/my.cnf is in the correct stateStarted: 10:39:05.041301Duration: 7.869 msChanges: ----------ID: mysql-serviceFunction: service.runningName: mariadbResult: TrueComment: The service mariadb is already runningStarted: 10:39:05.049284Duration: 28.054 msChanges: Summary for linux-node1.example.com ------------ Succeeded: 8 Failed: 0 ------------ Total states run: 8 Total run time: 858.995 ms 本文轉(zhuǎn)自 IT_外賣小哥 ?51CTO博客,原文鏈接:http://blog.51cto.com/jinlong/2062769 SaltStackSaltStack總結(jié)
以上是生活随笔為你收集整理的SaltStack的salt-ssh使用及LAMP状态设计部署的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: VScode配置eslint保存自动格式
- 下一篇: Jupyter Notebook代码字体