怎樣在ansible-playbook中批量搭建LAMP?針對這個問題,今天小編總結(jié)了這篇文章,希望幫助更多想學(xué)習(xí)LAMP的同學(xué)找到更加簡單易行的辦法。
成都創(chuàng)新互聯(lián)專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于成都網(wǎng)站設(shè)計、網(wǎng)站建設(shè)、西鄉(xiāng)塘網(wǎng)絡(luò)推廣、成都微信小程序、西鄉(xiāng)塘網(wǎng)絡(luò)營銷、西鄉(xiāng)塘企業(yè)策劃、西鄉(xiāng)塘品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們最大的嘉獎;成都創(chuàng)新互聯(lián)為所有大學(xué)生創(chuàng)業(yè)者提供西鄉(xiāng)塘建站搭建服務(wù),24小時服務(wù)熱線:13518219792,官方網(wǎng)址:www.cdcxhl.com
yum -y install httpd
yum -y install mariadb-server mysql
systemctl start mairadb
yum -y install php php-mysql
vim /var/www/html/index.php
systemctl restart httpd
mkdir -pv /etc/ansible/lamp/roles/{prepare,httpd,mysql,php}/{tasks,files,templates,vars,meta,default,handlers}
cd /etc/ansible/
cp /etc/httpd/conf/httpd.conf lamp/roles/httpd/files/
cp /etc/my.cnf lamp/roles/mysql/files/
vim lamp/roles/prepare/tasks/main.yml
- name: provide yumrepo file
shell: rm -rf /etc/yum.repos.d/*.repo #刪除原有yum配置文件
shell: wget - o /etc/yum.repos.d/CentOS-Base.repohttp://mirrors.aliyun.com/repo/Centos-repo #下載新的yum配置文件
- name: clean the yum repo
shell: yum clean all
- name: clean the iptables
shell: systemctl stop firewalld #關(guān)閉防火墻
cp /var/www/html/index.php lamp/roles/httpd/files/
vim lamp/roles/httpd/tasks/main.yml
- name: web server install
yum: name=httpd state=present #安裝httpd服務(wù)
- name: provide test page
copy: src=index.php dest=/var/www/html #提供測試頁
notify: restart httpd #當(dāng)前面的copy執(zhí)行成功后,通過notify通知名字為restart httpd的handlers運(yùn)行
- name: restart httpd
service: name=httpd enabled=yes state=restarted #重啟httpd服務(wù)
vim lamp/roles/mysql/tasks/main.yml
- name: install the mysql
yum: name=mariadb-server state=present #安裝mysql服務(wù)
- name: mkdir date directory
shell: mkdir -p /mydata/data #創(chuàng)建掛載點目錄
- name: provide configration file
copy: src=my.cnf dest=/etc/my.cnf #拷貝mysql的配置文件
- name: chage the owner
shell: chown -R mysql:mysql /mydata/* #更改屬主和屬主
- name: start mariadb
service: name=mariadb enabled=yes state=started #啟動mysql服務(wù)
vim lamp/roles/php/tasks/main.yml
- name: install php
yum: name=php state=present #安裝php
- name: install php-mysql
yum: name=php-mysql state=present #安裝php與mysql交互插件
vim lamp/roles/site.yml
- name: LAMP build
remote_user: root
hosts: all
roles:
- prepare
- mysql
- php
- httpd
ansible-playbook -i /etc/ansible/hosts ./site.yml
看完上訴內(nèi)容,你們掌握在ansible-playbook中批量搭建LAMP的方法了嗎?如果想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!