阅读549 返回首页    go iPhone_iPad_Mac_apple


阿里云一键部署 LNMP栈

LNMP代表Linux+Nginx+MySQL+PHP网站服务器架构。本文主要目的是为大家提供一种非常简单的方法,在阿里云上部署LNMP栈。
通过<阿里云ROS资源编排服务>,将VPC、NAT Gateway、ECS创建,LNMP栈部署过程自动化,使大家能够非常方便地部署一个LNMP栈。

一键部署LNMP栈>>
screenshot
screenshot

注意:

安装LNMP:关闭防火墙,关闭SELinux,安装nginx,MySQL和PHP,最后我们也安装了phpMyAdmin。UserData主要内容如下:

    "systemctl stop firewalld.service \n",
    "systemctl disable firewalld.service \n",
    "sed -i 's/^SELINUX=/# SELINUX=/' /etc/selinux/config \n",
    "sed -i '/# SELINUX=/a SELINUX=disabled' /etc/selinux/config \n",
    "setenforce 0 \n",
    "yum install yum-priorities -y \n",
    "yum -y install aria2 \n",
    "aria2c $NginxUrl \n",
    "rpm -ivh nginx-*.rpm \n",
    "yum -y install nginx \n",
    "systemctl start nginx.service \n",
    "systemctl enable nginx.service \n",
    "yum -y install php-fpm \n",
    "systemctl start php-fpm.service \n",
    "systemctl enable php-fpm.service \n",
    "sed -i '/FastCGI/,/htaccess/s/    #/    /' /etc/nginx/conf.d/default.conf \n",
    "sed -i '/FastCGI/s/^    /    #/' /etc/nginx/conf.d/default.conf \n",
    "sed -i '/htaccess/s/^    /    #/' /etc/nginx/conf.d/default.conf \n",
    "sed -i '/SCRIPT_FILENAME/s/\\/scripts/\\/usr\\/share\\/nginx\\/html\\//' /etc/nginx/conf.d/default.conf \n",
    "yum -y install mariadb mariadb-server \n",
    "systemctl start mariadb.service \n",
    "systemctl enable mariadb.service \n",
    "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 \n",
    "MDSRING=`find / -name mbstring.so` \n",
    "echo extension=$MDSRING >> /etc/php.ini \n",
    "systemctl restart mariadb.service \n",
    "mysqladmin -u root password \"$dbrootpassword\" \n",
    "$(mysql $dbname -u root --password=\"$dbrootpassword\" >/dev/null 2>&1 </dev/null); (( $? != 0 )) \n",
    "echo CREATE DATABASE $dbname ; > /tmp/setup.mysql \n",
    "echo GRANT ALL ON $dbname.* TO \"$dbuser\"@\"localhost\" IDENTIFIED BY \"$dbpassword\" ; >> /tmp/setup.mysql \n",
    "mysql -u root --password=\"$dbrootpassword\" < /tmp/setup.mysql \n",
    "$(mysql $dbname -u root --password=\"$dbrootpassword\" >/dev/null 2>&1 </dev/null); (( $? != 0 )) \n",
    "cd /root \n",
    "aria2c $PhpMyAdminUrl \n",
    "unzip phpMyAdmin-*.zip \nmkdir -p /usr/share/nginx/html/phpmyadmin \nmv phpMyAdmin-*.*/* /usr/share/nginx/html/phpmyadmin \n",
    "systemctl restart php-fpm.service \n",
    "systemctl restart nginx.service \n",

创建完成后,查看资源栈概况:
screenshot

浏览器中输入图中的的NginxWebsiteURL,得到如下结果,则部署nginx成功:
screenshot

浏览器中输入图中的的phpMyAdminWebsiteURL,得到如下结果,则部署phpMyAdmin成功:
screenshot

LNMP_basic.json
screenshot

最后更新:2017-04-20 21:30:39

  上一篇:go 厉害了!阿里的这套“实人认证”系统通过率高达99%
  下一篇:go 测试