playbook编写分布式lnmp
生活随笔
收集整理的這篇文章主要介紹了
playbook编写分布式lnmp
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
文章目錄
- playbook安裝分布式lnmp
- 搭建本地yum倉(cāng)庫(kù),使用http發(fā)布
- 編寫yum倉(cāng)庫(kù)配置
- 配置nginx配置文件,設(shè)置nginx支持php解析
- 配置php首頁(yè)文件
- 編寫playbook前準(zhǔn)備
playbook安裝分布式lnmp
搭建本地yum倉(cāng)庫(kù),使用http發(fā)布
yum -y install httpd systemctl start httpd cd /var/www/html mkdir myrepoyum -y install createrepo createrepo myrepo [root@host103 html]# ls myrepo/repodata/cd myrepo #下載rpm 包 wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm rpm -Uvh http://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/l/libargon2-20161029-3.el7.x86_64.rpm rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpmyum install --downloadonly --downloaddir=/var/www/html/myrepo \ php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-gd php72w-mbstring php72w-pdo php72w-xml php72w-fpm php72w-mysqlnd php72w-opcache pcre-devel編寫yum倉(cāng)庫(kù)配置
[root@host103 opt]# cat nginx.repo [nginx-stable] name=nginx stable repo baseurl=http://nginx.org/packages/centos/7/$basearch/ gpgcheck=0 enabled=1[root@host103 opt]# cat my.repo [myrepo] name=myrepo baseurl=http://192.168.23.103/myrepo enabled=1 gpgcheck=0配置nginx配置文件,設(shè)置nginx支持php解析
[root@host103 opt]# egrep -nv '^$|#' default.conf 1:server { 2: listen 80; 3: server_name localhost; 7: location / { 8: root /usr/share/nginx/html;#修改 ,配置文首頁(yè)文件 9: index index.html index.php; 10: } 16: error_page 500 502 503 504 /50x.html; 17: location = /50x.html { 18: root /usr/share/nginx/html; 19: }#修改 29: location ~ \.php$ { 30: root html;#修改,配置php主機(jī)ip和默認(rèn)端口 31: fastcgi_pass 192.168.23.107:9000; 32: fastcgi_index index.php;#修改 33: fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name; 34: include fastcgi_params; 35: } 43:}配置php首頁(yè)文件
[root@host103 opt]# vim index.php <?php #配置連接數(shù)據(jù)的 ip 地址,用戶,密碼 $link=mysqli_connect('192.168.23.106','root','Admin@123'); if($link) echo "<h1>Success!!</h1>"; else echo "Fail!!"; ?>配置nginx和mysql主機(jī)的nfs共享配置文件
[root@host103 opt]# cat nginx_exports /usr/share/nginx/html 192.168.23.0/24(rw,no_root_squash)[root@host103 opt]# cat mysql_exports /var/lib/mysql/ 192.168.23.0/24(rw,no_root_squash) [root@host103 opt]# cat www.conf | grep -v '^;' | grep -v '^$' [www] #修改,配置用戶和組為nginx user = nginx group = nginx #修改,配置監(jiān)聽(tīng)地址php的地址和端口 listen = 192.168.23.107:9000 #修改,設(shè)置為nginx主機(jī)的地址 listen.allowed_clients = 192.168.23.105 pm = dynamic pm.max_children = 50 pm.start_servers = 5 pm.min_spare_servers = 5 pm.max_spare_servers = 35 slowlog = /var/log/php-fpm/www-slow.log php_admin_value[error_log] = /var/log/php-fpm/www-error.log php_admin_flag[log_errors] = on php_value[session.save_handler] = files php_value[session.save_path] = /var/lib/php/session php_value[soap.wsdl_cache_dir] = /var/lib/php/wsdlcache [root@host103 opt]# cat /etc/php.ini | egrep 'mysqli.default_socket|date.timezone' ; http://php.net/date.timezone #修改,設(shè)置時(shí)區(qū) date.timezone = Asia/Shanghai #修改,設(shè)置mysql的套接字文件路徑 mysqli.default_socket = /var/lib/mysql/mysql.sock編寫playbook前準(zhǔn)備
#先配置免密登錄 ssh-keygen ssh-copy-id 192.168.23.105 ssh-copy-id 192.168.23.106 ssh-copy-id 192.168.23.107#配置主機(jī)清單 [root@host103 opt]# egrep -v '^$|#' /etc/ansible/hosts | grep -A1 'servers' [phpservers] 192.168.23.107 [webservers] 192.168.23.105 [dbservers] 192.168.23.106playbook文件
- name: for all gather_facts: falsehosts: webservers dbservers phpserversremote_user: roottasks: - name: stop firewalldservice: name=firewalld state=stopped enabled=no- name: stop selinuxselinux:policy: targetedstate:disabled- name: make yumrepocopy: src=/opt/my.repo dest=/etc/yum.repos.d/my.repo- name: for nginxgather_facts: falsehosts: webserversremote_user: roottasks: - name: modify yum repositorycopy: src=/opt/nginx.repo dest=/etc/yum.repos.d/nginx.repo- name: install nginxyum: name=nginx state=latest - name: start nginxservice: name=nginx state=started enabled=yes- name: install nfsyum: name:- rpcbind- nfs-utils- name: chmod file: path=/usr/share/nginx/html mode=0777- name: modify share directorycopy: src=/opt/nginx_exports dest=/etc/exports- name: start nfsservice: name: "{{item}}"state: startedenabled: yeswith_items:- rpcbind- nfs- name: modify index.phpcopy: src=/opt/index.php dest=/usr/share/nginx/html/index.php- name: for nginx support php copy: src=/opt/default.conf dest=/etc/nginx/conf.d/default.confnotify: restart nginxhandlers: - name: restart nginxservice: name=nginx state=restarted- name: for mysqlgather_facts: falsehosts: dbserversremote_user: roottasks:- name: remove mariadb and yum: name=mariadb* state=absent- name: install mysql57yum: name=mysql57-community-release-el7-10.noarch- name: install mysqlyum: name=mysql-community-server- name: start mysqldservice: name=mysqld state=started enabled=yes- name: initialize mysqlshell: a=$(grep "password" /var/log/mysqld.log | awk 'NR==1{print $NF}') && mysqladmin -u root -p"$a" password 'Admin@123' || echo 'OK'- name: Configuring Authorized Users shell: mysql -uroot -p'Admin@123' -e "grant all privileges on *.* to root@'%' identified by 'Admin@123' with grant option;" -e "flush privileges;" || echo 'OK'- name: remove mysql57-communityyum: name=mysql57-community-release-el7-10.noarc state=absent- name: install nfsyum:name:- rpcbind- nfs-utils- name: modify share directorycopy: src=/opt/mysql_exports dest=/etc/exports- name: start nfsservice:name: "{{item}}"state: startedenabled: yeswith_items:- rpcbind- nfs- name: for phpgather_facts: falsehosts: phpserversremote_user: roottasks: - name: stop firewalldservice: name=firewalld state=stopped enabled=no- name: stop selinuxshell: setenforce 0ignore_errors: yes- name: make yumrepo for phpcopy: src=/opt/my.repo dest=/etc/yum.repos.d/my.repo- name: useradd nginxuser: name=nginx state=present- name: install nfsyum:name: - rpcbind- nfs-utils- name: start nfsservice: name=rpcbind state=started enabled=yes- name: make dir for nginxshell: ls /usr/share/nginx/html || mkdir -p /usr/share/nginx/html- name: make dir for mysql.sockshell: ls /var/lib/mysql/ || mkdir -p /var/lib/mysql- name: mount nfs for nginxmount:path: /usr/share/nginx/htmlsrc: 192.168.23.105:/usr/share/nginx/htmlfstype: nfsstate: mounted- name: mount nfs for mysqlmount:path: /var/lib/mysqlsrc: 192.168.23.106:/var/lib/mysqlfstype: nfsstate: mounted- name: download libargon2 epel webtatic-releaseyum:name:- libargon2- epel-release - webtatic-release- name: install phpyum: name:- php72w- php72w-cli- php72w-common- php72w-devel- php72w-embedded- php72w-gd- php72w-mbstring- php72w-pdo- php72w-xml- php72w-fpm- php72w-mysqlnd- php72w-opcache- name: modify php.inicopy: src=/opt/php.ini dest=/etc/php.ini- name: modify www.confcopy: src=/opt/www.conf dest=/etc/php-fpm.d/www.conf- name: start phpservice: name=php-fpm state=started enabled=yes總結(jié)
以上是生活随笔為你收集整理的playbook编写分布式lnmp的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: playbook 剧本编写
- 下一篇: kubernetes(k8s)架构和组件