您好,登錄后才能下訂單哦!
怎樣在ansible-playbook中批量搭建LAMP?針對(duì)這個(gè)問題,今天小編總結(jié)了這篇文章,希望幫助更多想學(xué)習(xí)LAMP的同學(xué)找到更加簡(jiǎn)單易行的辦法。
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
<?php
phpinfo();
?>
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 #提供測(cè)試頁
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)建掛載點(diǎn)目錄
- 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 #啟動(dòng)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)注億速云行業(yè)資訊頻道,感謝各位的閱讀!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。