41.部署LNMP平台源码

  1. 云栖社区>
  2. 博客>
  3. 正文

41.部署LNMP平台源码

技术小牛人 2017-11-21 22:45:00 浏览817
展开阅读全文

源码部署LNMP

环境需求:关闭防火墙,设置静态IP地址,部署YUM

# systemctl stop firewalld                  #关闭firewalld防火墙

# systemctl disable firewalld.service           #禁止firewalld服务自启

# sed -i -e 's|SELINUX=enforcing|SELINUX=disabled|' /etc/selinux/config  #关闭SELINUX

# sed -i -e 's|SELINUXTYPE=targeted|#SELINUXTYPE=targeted|' /etc/selinux/config

#echo [a]     

name=a

baseurl=file:///run/media/root/CentOS\ 7\ x86_64

gpgcheck=0   > /etc/yum.repos.d/a.repo       #部署YUM                         

# yum clean all                              #清除YUM缓存

# yum makecache                            #重新生成YUM缓存

# echo ‘TYPE=Ethernet                       

BOOTPROTO=static

DEFROUTE=yes

PEERDNS=yes

PEERROUTES=yes

IPV4_FAILURE_FATAL=no

NAME=eth0

DEVICE=eth0

ONBOOT=yes

IPADDR=1.1.1.1

NETMASK=255.255.255.0

GATEWAY=1.1.1.254

DNS1=202.96.134.133   > /etc/sysconfig/network-scripts/ifcfg-eth0 #修改静态IP

 

部署MYSQL数据库

# yum -y remove mariadb-server          #移除YUM版的MYSQL数据库

# yum -y install bison gcc gcc-c++ cmake ncurses-devel  #安装相关组件

# tar xzvf mysql-5.5.22.tar.gz                #解压MYSQL压缩包

# cd mysql-5.5.22/

# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8  -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all            #使用CMAKE检查MYSQL

#make && make install                   #编译安装MYSQL数据库

注释:

-DCMAKE_INSTALL_PREFIX:指定安装路径

-DSYSCONFDIR:指定配置文件路径

-DDEFAULT_CHARSET:指定使用的语言编码

-DDEFAULT_COLLATION:指定默认使用的语言编码校验

-DWITH_EXTRA_CHARSETS:指定可以使用其他的语言编码

# useradd mysql                       #创建运行用户

# chown -R mysql.mysql  /usr/local/mysql/  #授权安装目录

# unalias cp                             #开启CP命令的强制

# cp  -f /usr/local/mysql/support-files/my-medium.cnf  /etc/my.cnf  #拷贝配置

# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data         #初始化MYSQL数据库

# cp /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysqld  #命令放入自启目录

# chkconfig --add mysqld            #添加自启服务到chkconfig工具

# chkconfig mysqld on               #设置为开机自启

# service mysqld start                #重启MYSQL数据库服务

# mysqladmin -u root password  123    设置ROOT用户密码

 

部署Nginx服务器

# yum -y install pcre-devel zlib-devel      #安装相关组件

# useradd -M -s /sbin/nologin nginx       #创建运行用户

# tar xzvf nginx-1.6.0.tar.gz               #解压Nginx压缩包

# cd nginx-1.6.0                     

#./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module            #检查Nginx包完整性

# make && make install                    #编译并安装Nginx

 

部署PHP服务器

# yum -y install gd libxml2-devel libjpeg-devel libpng-devel bzip2 #安装相关组件

# tar xjvf php-7.1.0.tar.bz2                                #解压PHP压缩包

# cd php-7.1.0

# ./configure --prefix=/usr/local/php --with-gd --with-zlib --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php --enable-mbstring --enable-fpm --with-jpeg-dir=/usr/lib

#make && make install                                #编译安装PHP

# cp php.ini-production  /usr/local/php/php.ini            #拷贝PHP配置文件

# cp /usr/local/php/etc/php-fpm.conf.default   /usr/local/php/etc/php-fpm.conf

# cp /usr/local/php/etc/php-fpm.d/www.conf.default   /usr/local/php/etc/php-fpm.d/www.conf                  #拷贝PHP测试页面配置文件     

# useradd -M -s /sbin/nologin php                        #创建运行用户

 

PHP加速模块安装方法,下面版本只适用于PHP5.3,想要支持PHP7请下载高版本。

# tar xzvf ZendGuardLoader-php-5.3-linux-glibc23-x86_64.tar.gz

# cp ZendGuardLoader-php-5.3-linux-glibc23-x86_64/php-5.3.x/ZendGuardLoader.so  /usr/local/php/lib/php/                               #拷贝加速模块到PHP指定目录

# echo 'zend_extension=/usr/local/php/lib/php/ZendGuardLoader.so' >>  /usr/local/php/php.ini

# echo 'zend_loader.enable=1' >> /usr/local/php/php.ini     #添加加速PHP模块

 

配置LNMP环境变量

# echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile  #设置环境变量

# echo "PATH=$PATH:/usr/local/nginx/sbin" >> /etc/profile

# echo "PATH=$PATH:/usr/local/php/sbin" >> /etc/profile

#source /etc/profile

 

配置Nginx支持PHP解析

#vim /usr/local/nginx/conf/nginx.conf   

 location / {

            root   html;

            index index.php index.html index.htm;    #添加index.php首先解析

        }

  

location ~ \.php$ {

            root           html;

            fastcgi_pass   127.0.0.1:9000;          #调用本机的php-fpm进程

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html/$fastcgi_script_name;

            include        fastcgi_params;

        }

#vim /usr/local/nginx/html/index.php

添加内容:

<?php

phpinfo ();                              #PHP测试页面

?>

启动PHPNginx服务

# php-fpm

# nginx

# netstat -lnupt |grep 3306

# netstat -lnupt |grep 80

# netstat -lnupt |grep php-fpm

 

故障排查:解决PHP页面解析出现找不到文件故障

# sed -i -e 's|;cgi.fix_pathinfo=1|cgi.fix_pathinfo=1'  /usr/local/php/php.ini 

本文转自   触动的风   51CTO博客,原文链接:http://blog.51cto.com/10978134/1945763



网友评论

登录后评论
0/500
评论