阿裡雲一鍵部署LNMP(Linux+Nginx+MySQL+PHP)棧

來源:互聯網
上載者:User

阿裡雲一鍵部署LNMP(Linux+Nginx+MySQL+PHP)棧

摘要: LNMP代表Linux+Nginx+MySQL+PHP網站伺服器架構。通過ROS資源編排可以阿裡雲上一鍵部署LNMP棧。

LNMP代表Linux+Nginx+MySQL+PHP網站伺服器架構。本文主要目的是為大家提供一種非常簡單的方法,在阿裡雲上部署LNMP棧。
通過<阿裡雲ROS資源編排服務>,將VPC、NATGateway、ECS建立,LNMP棧部署程序自動化,使大家能夠非常方便地部署一個LNMP棧。

急速部署LNMP棧

一鍵部署LNMP棧>>

screenshot

screenshot

注意:

·必須確保可以正確下載nginx-.rpm安裝包,我們可以選擇類似如下的URL:

·http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

·CentOS-7

·我們選擇的資料中心在上海/北京。

ROS範本安裝LNMP棧

安裝LNMP:關閉防火牆,關閉SELinux,安裝nginx,MySQL和PHP。UserData如下:

"systemctl stop firewalld.service 
",
"systemctl disable firewalld.service 
",
"sed -i 's/^SELINUX=/# SELINUX=/' /etc/selinux/config 
",
"sed -i '/# SELINUX=/a SELINUX=disabled' /etc/selinux/config 
",
"setenforce 0 
",
"yum install yum-priorities -y 
",
"yum -y install aria2 
",
"aria2c $NginxUrl 
",
"rpm -ivh nginx-*.rpm 
",
"yum -y install nginx 
",
"systemctl start nginx.service 
",
"systemctl enable nginx.service 
",
"yum -y install php-fpm 
",
"systemctl start php-fpm.service 
",
"systemctl enable php-fpm.service 
",
"sed -i '/FastCGI/,/htaccess/s/#//' /etc/nginx/conf.d/default.conf 
",
"sed -i '/FastCGI/s/^/#/' /etc/nginx/conf.d/default.conf 
",
"sed -i '/htaccess/s/^/#/' /etc/nginx/conf.d/default.conf 
",
"sed -i '/SCRIPT_FILENAME/s/\/scripts/\/usr\/share\/nginx\/html\//' /etc/nginx/conf.d/default.conf 
",
"yum -y install mariadb mariadb-server 
",
"systemctl start mariadb.service 
",
"systemctl enable mariadb.service 
",
"yum -y install php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash 
",
"MDSRING=`find / -name mbstring.so` 
",
"echo extension=$MDSRING >> /etc/php.ini 
",
"systemctl restart mariadb.service 
",
"mysqladmin -u root password "$dbrootpassword" 
",
"$(mysql $dbname -u root --password="$dbrootpassword" >/dev/null 2>&1 </dev/null); (( $? != 0 )) 
",
"echo CREATE DATABASE $dbname \; > /tmp/setup.mysql 
",
"echo GRANT ALL ON $dbname.* TO "$dbuser"@"localhost" IDENTIFIED BY "'$dbpassword'" \; >> /tmp/setup.mysql 
",
"mysql -u root --password="$dbrootpassword" < /tmp/setup.mysql 
",
"$(mysql $dbname -u root --password="$dbrootpassword" >/dev/null 2>&1 </dev/null); (( $? != 0 )) 
",
"cd /root 
",
"systemctl restart php-fpm.service 
",
"systemctl restart nginx.service 
",
"echo \<?php >/usr/share/nginx/html/test.php 
",
"echo \$conn=mysql_connect\("'127.0.0.1'", "'$dbuser'", "'$dbpassword'"\)\; >>/usr/share/nginx/html/test.php 
",
"echo if \(\$conn\){ >>/usr/share/nginx/html/test.php 
",
"echoecho \"LNMP platform connect to mysql is successful\!\"\; >>/usr/share/nginx/html/test.php 
",
"echo}else{>>/usr/share/nginx/html/test.php 
",
"echo echo \"LNMP platform connect to mysql is failed\!\"\;>>/usr/share/nginx/html/test.php 
",
"echo }>>/usr/share/nginx/html/test.php 
",
"echophpinfo\(\)\;>>/usr/share/nginx/html/test.php 
",
"echo \?\>>>/usr/share/nginx/html/test.php 
",

測試部署結果

建立完成後,查看資源棧概況:


screenshot

瀏覽器中輸入圖中的的NginxWebsiteURL,得到如下結果,則部署成功:
screenshot

ROS樣本範本

LNMP_basic.json
screenshot


相關產品:

  1. 資源編排ROS
相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.