{"id":30408,"date":"2023-01-20T16:27:30","date_gmt":"2023-01-18T22:51:45","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ansible%e5%ae%89%e8%a3%85nginx%e3%80%81php-fpm%e3%80%81php%e5%92%8cmysql%e3%80%82\/"},"modified":"2025-08-12T19:02:19","modified_gmt":"2025-08-12T11:02:19","slug":"%e4%bd%bf%e7%94%a8ansible%e5%ae%89%e8%a3%85nginx%e3%80%81php-fpm%e3%80%81php%e5%92%8cmysql%e3%80%82","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ansible%e5%ae%89%e8%a3%85nginx%e3%80%81php-fpm%e3%80%81php%e5%92%8cmysql%e3%80%82\/","title":{"rendered":"\u4f7f\u7528Ansible\u5b89\u88c5Nginx\u3001PHP-FPM\u3001PHP\u548cMySQL"},"content":{"rendered":"<p>\u5c1d\u8bd5\u7528Ansible\u64b0\u5199\u8fd9\u91cc\u7684\u64cd\u4f5c\u624b\u518c<\/p>\n<p>\u8bbe\u7f6e.yml<\/p>\n<pre class=\"post-pre\"><code>- hosts: web-server\r\n  remote_user: vagrant\r\n  sudo: yes\r\n  gather_facts: no\r\n\r\n  tasks:\r\n    - name: install nginx rpm\r\n      yum: name=http:\/\/nginx.org\/packages\/centos\/6\/noarch\/RPMS\/nginx-release-centos-6-0.el6.ngx.noarch.rpm state=present\r\n\r\n    - name: install nginx\r\n      yum: name=nginx state=present\r\n\r\n    - name: restart nginx\r\n      service: name=nginx state=restarted\r\n\r\n    - name: chkconfig nginx\r\n      command: chkconfig nginx on\r\n\r\n    - name: install php-fpm\r\n      yum: name=php-fpm state=latest\r\n\r\n    - name: apply php-fpm.conf\r\n      template: src=.\/php-fpm.conf.tpl dest=\/etc\/php-fpm.d\/www.conf backup=yes\r\n\r\n    - name: restart php-fpm\r\n      service: name=php-fpm state=restarted\r\n\r\n    - name: chkconfig php-fpm\r\n      command: chkconfig php-fpm on\r\n\r\n    - name: install php rpm\r\n      yum: name=http:\/\/rpms.famillecollet.com\/enterprise\/remi-release-6.rpm state=present\r\n\r\n    - name: install php\r\n      yum: pkg={{item}} enablerepo=remi,remi-php56 state=present\r\n      with_items:\r\n        - php\r\n        - php-devel\r\n        - php-common\r\n        - php-gd\r\n        - php-mbstring\r\n        - php-mysql\r\n        - php-pdo\r\n        - php-pear\r\n        - php-xml\r\n\r\n    - name: install mysql rpm\r\n      yum: pkg={{item}} state=present\r\n      with_items:\r\n        - http:\/\/dev.mysql.com\/get\/Downloads\/MySQL-5.6\/MySQL-shared-compat-5.6.23-1.el6.x86_64.rpm\r\n        - http:\/\/dev.mysql.com\/get\/Downloads\/MySQL-5.6\/MySQL-shared-5.6.23-1.el6.x86_64.rpm\r\n        - http:\/\/dev.mysql.com\/get\/Downloads\/MySQL-5.6\/MySQL-server-5.6.23-1.el6.x86_64.rpm\r\n        - http:\/\/dev.mysql.com\/get\/Downloads\/MySQL-5.6\/MySQL-client-5.6.23-1.el6.x86_64.rpm\r\n        - http:\/\/dev.mysql.com\/get\/Downloads\/MySQL-5.6\/MySQL-devel-5.6.23-1.el6.x86_64.rpm\r\n\r\n    - name: install mysql\r\n      yum: pkg={{item}} state=present\r\n      with_items:\r\n        - MySQL-client.x86_64\r\n        - MySQL-devel.x86_64\r\n        - MySQL-server.x86_64\r\n        - MySQL-shared-compat.x86_64\r\n        - MySQL-shared.x86_64\r\n\r\n    - name: chkconfig mysql\r\n      command: chkconfig mysql on\r\n\r\n    - name: restart mysql\r\n      service: name=mysql state=restarted\r\n<\/code><\/pre>\n<p>\u4ee5\u4e0b\u662f\u7528\u6bcd\u8bed\u4e2d\u6587\u7684\u4e00\u79cd\u8868\u8ff0\u65b9\u5f0f\uff1a<\/p>\n<p>\u5411\u4e0b \u2193\u2193\u2193\u2193\u2193\u2193\u2193\u2193\u2193\u2193\u2193\u2193\u2193\u2193\u2193\u2193\u2193\u2193\u2193\u2193\u2193\u2193\u2193\u2193\u2193\u2193\u2193\u2193\u2193\u2193\u2193\u2193\u2193\u2193<\/p>\n<pre class=\"post-pre\"><code>$ ansible-playbook -i servers setup.yml -k -K\r\n [WARNING]: The version of gmp you have installed has a known issue regarding\r\ntiming vulnerabilities when used with pycrypto. If possible, you should update\r\nit (i.e. yum update gmp).\r\n\r\nSSH password:\r\nsudo password [defaults to SSH password]:\r\n\r\nPLAY [web-server] *************************************************************\r\n\r\nGATHERING FACTS ***************************************************************\r\nok: [192.168.33.20]\r\n\r\nTASK: [install nginx rpm] *****************************************************\r\nok: [192.168.33.20]\r\n\r\nTASK: [install nginx] *********************************************************\r\nok: [192.168.33.20]\r\n\r\nTASK: [restart nginx] *********************************************************\r\nchanged: [192.168.33.20]\r\n\r\nTASK: [chkconfig nginx] *******************************************************\r\nchanged: [192.168.33.20]\r\n\r\nTASK: [install php-fpm] *******************************************************\r\nok: [192.168.33.20]\r\n\r\nTASK: [apply php-fpm.conf] ****************************************************\r\nok: [192.168.33.20]\r\n\r\nTASK: [restart php-fpm] *******************************************************\r\nchanged: [192.168.33.20]\r\n\r\nTASK: [chkconfig php-fpm] *****************************************************\r\nchanged: [192.168.33.20]\r\n\r\nTASK: [install php rpm] *******************************************************\r\nok: [192.168.33.20]\r\n\r\nTASK: [install php] ***********************************************************\r\nok: [192.168.33.20] =&gt; (item=php,php-devel,php-common,php-gd,php-mbstring,php-mysql,php-pdo,php-pear,php-xml)\r\n\r\nTASK: [install mysql rpm] *****************************************************\r\nok: [192.168.33.20] =&gt; (item=http:\/\/dev.mysql.com\/get\/Downloads\/MySQL-5.6\/MySQL-shared-compat-5.6.23-1.el6.x86_64.rpm,http:\/\/dev.mysql.com\/get\/Downloads\/MySQL-5.6\/MySQL-shared-5.6.23-1.el6.x86_64.rpm,http:\/\/dev.mysql.com\/get\/Downloads\/MySQL-5.6\/MySQL-server-5.6.23-1.el6.x86_64.rpm,http:\/\/dev.mysql.com\/get\/Downloads\/MySQL-5.6\/MySQL-client-5.6.23-1.el6.x86_64.rpm,http:\/\/dev.mysql.com\/get\/Downloads\/MySQL-5.6\/MySQL-devel-5.6.23-1.el6.x86_64.rpm)\r\n\r\nTASK: [install mysql] *********************************************************\r\nok: [192.168.33.20] =&gt; (item=MySQL-client.x86_64,MySQL-devel.x86_64,MySQL-server.x86_64,MySQL-shared-compat.x86_64,MySQL-shared.x86_64)\r\n\r\nTASK: [chkconfig mysql] *******************************************************\r\nchanged: [192.168.33.20]\r\n\r\nTASK: [restart mysql] *********************************************************\r\nchanged: [192.168.33.20]\r\n\r\nPLAY RECAP ********************************************************************\r\n192.168.33.20              : ok=15   changed=6    unreachable=0    failed=0\r\n\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5c1d\u8bd5\u7528Ansible\u64b0\u5199\u8fd9\u91cc\u7684\u64cd\u4f5c\u624b\u518c \u8bbe\u7f6e.yml &#8211; hosts: web-server remote_u [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[227],"class_list":["post-30408","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-227"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u4f7f\u7528Ansible\u5b89\u88c5Nginx\u3001PHP-FPM\u3001PHP\u548cMySQL - Blog - Silicon Cloud<\/title>\n<meta name=\"description\" content=\"\u5173\u4e8e\u4f7f\u7528Ansible\u5b89\u88c5Nginx\u3001PHP-FPM\u3001PHP\u548cMySQL\u7684\u6280\u672f\u6587\u7ae0\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528ansible\u5b89\u88c5nginx\u3001php-fpm\u3001php\u548cmysql\u3002\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u4f7f\u7528Ansible\u5b89\u88c5Nginx\u3001PHP-FPM\u3001PHP\u548cMySQL\" \/>\n<meta property=\"og:description\" content=\"\u5173\u4e8e\u4f7f\u7528Ansible\u5b89\u88c5Nginx\u3001PHP-FPM\u3001PHP\u548cMySQL\u7684\u6280\u672f\u6587\u7ae0\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528ansible\u5b89\u88c5nginx\u3001php-fpm\u3001php\u548cmysql\u3002\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-01-18T22:51:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-08-12T11:02:19+00:00\" \/>\n<meta name=\"author\" content=\"\u96c5, \u609f\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u96c5, \u609f\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ansible%e5%ae%89%e8%a3%85nginx%e3%80%81php-fpm%e3%80%81php%e5%92%8cmysql%e3%80%82\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ansible%e5%ae%89%e8%a3%85nginx%e3%80%81php-fpm%e3%80%81php%e5%92%8cmysql%e3%80%82\/\",\"name\":\"\u4f7f\u7528Ansible\u5b89\u88c5Nginx\u3001PHP-FPM\u3001PHP\u548cMySQL - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2023-01-18T22:51:45+00:00\",\"dateModified\":\"2025-08-12T11:02:19+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/f044a4b7fa4ee2701702942002419ca6\"},\"description\":\"\u5173\u4e8e\u4f7f\u7528Ansible\u5b89\u88c5Nginx\u3001PHP-FPM\u3001PHP\u548cMySQL\u7684\u6280\u672f\u6587\u7ae0\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ansible%e5%ae%89%e8%a3%85nginx%e3%80%81php-fpm%e3%80%81php%e5%92%8cmysql%e3%80%82\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ansible%e5%ae%89%e8%a3%85nginx%e3%80%81php-fpm%e3%80%81php%e5%92%8cmysql%e3%80%82\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ansible%e5%ae%89%e8%a3%85nginx%e3%80%81php-fpm%e3%80%81php%e5%92%8cmysql%e3%80%82\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u4f7f\u7528Ansible\u5b89\u88c5Nginx\u3001PHP-FPM\u3001PHP\u548cMySQL\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/f044a4b7fa4ee2701702942002419ca6\",\"name\":\"\u96c5, \u609f\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e71a913e914f1aad1efc391f92084294bac54bc782acd289638580134cf667a6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e71a913e914f1aad1efc391f92084294bac54bc782acd289638580134cf667a6?s=96&d=mm&r=g\",\"caption\":\"\u96c5, \u609f\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/yawu\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ansible%e5%ae%89%e8%a3%85nginx%e3%80%81php-fpm%e3%80%81php%e5%92%8cmysql%e3%80%82\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"\u4f7f\u7528Ansible\u5b89\u88c5Nginx\u3001PHP-FPM\u3001PHP\u548cMySQL - Blog - Silicon Cloud","description":"\u5173\u4e8e\u4f7f\u7528Ansible\u5b89\u88c5Nginx\u3001PHP-FPM\u3001PHP\u548cMySQL\u7684\u6280\u672f\u6587\u7ae0","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528ansible\u5b89\u88c5nginx\u3001php-fpm\u3001php\u548cmysql\u3002\/","og_locale":"zh_CN","og_type":"article","og_title":"\u4f7f\u7528Ansible\u5b89\u88c5Nginx\u3001PHP-FPM\u3001PHP\u548cMySQL","og_description":"\u5173\u4e8e\u4f7f\u7528Ansible\u5b89\u88c5Nginx\u3001PHP-FPM\u3001PHP\u548cMySQL\u7684\u6280\u672f\u6587\u7ae0","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528ansible\u5b89\u88c5nginx\u3001php-fpm\u3001php\u548cmysql\u3002\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-01-18T22:51:45+00:00","article_modified_time":"2025-08-12T11:02:19+00:00","author":"\u96c5, \u609f","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u96c5, \u609f","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ansible%e5%ae%89%e8%a3%85nginx%e3%80%81php-fpm%e3%80%81php%e5%92%8cmysql%e3%80%82\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ansible%e5%ae%89%e8%a3%85nginx%e3%80%81php-fpm%e3%80%81php%e5%92%8cmysql%e3%80%82\/","name":"\u4f7f\u7528Ansible\u5b89\u88c5Nginx\u3001PHP-FPM\u3001PHP\u548cMySQL - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2023-01-18T22:51:45+00:00","dateModified":"2025-08-12T11:02:19+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/f044a4b7fa4ee2701702942002419ca6"},"description":"\u5173\u4e8e\u4f7f\u7528Ansible\u5b89\u88c5Nginx\u3001PHP-FPM\u3001PHP\u548cMySQL\u7684\u6280\u672f\u6587\u7ae0","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ansible%e5%ae%89%e8%a3%85nginx%e3%80%81php-fpm%e3%80%81php%e5%92%8cmysql%e3%80%82\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ansible%e5%ae%89%e8%a3%85nginx%e3%80%81php-fpm%e3%80%81php%e5%92%8cmysql%e3%80%82\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ansible%e5%ae%89%e8%a3%85nginx%e3%80%81php-fpm%e3%80%81php%e5%92%8cmysql%e3%80%82\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"\u4f7f\u7528Ansible\u5b89\u88c5Nginx\u3001PHP-FPM\u3001PHP\u548cMySQL"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website","url":"https:\/\/www.silicloud.com\/zh\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/f044a4b7fa4ee2701702942002419ca6","name":"\u96c5, \u609f","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e71a913e914f1aad1efc391f92084294bac54bc782acd289638580134cf667a6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e71a913e914f1aad1efc391f92084294bac54bc782acd289638580134cf667a6?s=96&d=mm&r=g","caption":"\u96c5, \u609f"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/yawu\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8ansible%e5%ae%89%e8%a3%85nginx%e3%80%81php-fpm%e3%80%81php%e5%92%8cmysql%e3%80%82\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/30408","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=30408"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/30408\/revisions"}],"predecessor-version":[{"id":56857,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/30408\/revisions\/56857"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=30408"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=30408"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=30408"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}