阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

CentOS 6.5 源码编译搭建LNMP(三台独立主机实现)

148次阅读
没有评论

共计 9462 个字符,预计需要花费 24 分钟才能阅读完成。

CentOS 6.5 源码编译搭建 LNMP(三台独立主机实现)

搭建前准备:

1. 三台独立主机

nginx:192.168.1.102

php-fpm:192.168.1.105

MySQL:192.168.1.103

2. 相关软件的源码包

nginx:nginx-1.10.2

php:php-5.6.28

mysql:mariadb-5.5.53

3. 开发环境及依赖包组

包:openssl-devel;pcre-devel;zlib-devel

包组:Development Tools;Server Platform Development

开始搭建:


 

第一台主机的操作:nginx 服务器主机

1. 解压展开源码包 nginx-1.10.2.tar.gz

tar -xf nginx-1.10.2.tar.gz

2. 创建相应路径以便编译时使用

mkdir -pv /var/cache/nginx

3.cd 至 nginx-1.10.2 目录,运行以下命令

./configure  --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-threads --with-stream --with-stream_ssl_module --with-http_slice_module --with-file-aio --with-http_v2_module
 

4.make && make install 即可

5. 开启 nginx,在浏览器测试,出现即没有问题

CentOS 6.5 源码编译搭建 LNMP(三台独立主机实现)

6. 配置 nginx 支持 php-fpm

#vim /etc/nginx/nginx.conf 写入

 
    server {listen 80;
        server_name www.a.com;
        location / {root /test/html;
                index index.html index.htm index.php;
        }
        location ~ \.php$ {root           /test/html;
            fastcgi_pass   192.168.1.105:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /www/test1/$fastcgi_script_name;
            include        fastcgi_params;
        }
    }

第二台主机的操作:php 的主机

1. 解压展开源码包 php-5.6.28.tar.bz2

2.cd 至 php-5.6.28 目录,执行

./configure --prefix=/usr/local/php56 --with-mysql --with-openssl --with-mysqli --enable-mbstring --with-png-dir --with-jpeg-dir --with-freetype-dir --with-zlib --with-libxml-dir=/usr  --enable-xml --enable-sockets --with-mcrypt --with-config-file-path=/etc/php56 --with-config-file-scan-dir=/etc/php56.d --with-bz2 --enable-fpm

其中,–enable-fpm是关键选项

3.make && make install

4. 配置文件的操作

①#cp php.ini-development /etc/php.ini 

②#cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm (将 php-fpm 加入到系统服务中)

③#chkconfig –add php-fpm

查看添加结果:#chkconfig –list php-fpm

CentOS 6.5 源码编译搭建 LNMP(三台独立主机实现)

则完成添加;

注意:此处复制 php-fpm 到 /etc/rc.d/init.d/ 目录下时,有可能 php-fpm 自身没有任何执行权限,会导致添加系统服务时失败,自行添加执行权限即可解决这个问题

5. 修改 php-fpm 配置文件

①修改 php-fpm 的 pid 设置

CentOS 6.5 源码编译搭建 LNMP(三台独立主机实现)

②修改 php-fpm 的进程属主

CentOS 6.5 源码编译搭建 LNMP(三台独立主机实现)

③修改 php-fpm 的监听地址

CentOS 6.5 源码编译搭建 LNMP(三台独立主机实现)

这几项是服务正常开启运行的比较关键的几项,其余配置在此不再赘述

6. 开启 php-fpm 服务

service php-fpm start

CentOS 6.5 源码编译搭建 LNMP(三台独立主机实现)

确保 PHP 主机的 IP:9000 处于监听状态即可

 7. 创建动态资源目录, 做测试用,此处是 /www/test1 目录,创建一个 index.php 文件

 8. 开始测试,效果如下

CentOS 6.5 源码编译搭建 LNMP(三台独立主机实现) 此为请求静态资源

CentOS 6.5 源码编译搭建 LNMP(三台独立主机实现)此为请求动态资源

 

更多详情见请继续阅读下一页的精彩内容:http://www.linuxidc.com/Linux/2016-12/138711p2.htm

 

 

LNMP 安装参考如下文章

 

Ubuntu 16.04 下源码配置 LNMP 开发环境 http://www.linuxidc.com/Linux/2016-09/135381.htm

 

Ubuntu 14.04 搭建 LNMP  http://www.linuxidc.com/Linux/2015-05/116933.htm

 

Ubuntu 14.04 LTS 安装 LNMP Nginx\PHP5 (PHP-FPM)\MySQL  http://www.linuxidc.com/Linux/2014-05/102351.htm

 

在部署 LNMP 的时候遇到 Nginx 启动失败的 2 个问题 http://www.linuxidc.com/Linux/2013-03/81120.htm

 

CentOS7.2 编译安装 LNMP http://www.linuxidc.com/Linux/2016-12/138668.htm

 

CentOS 6.5 下编译安装新版 LNMP http://www.linuxidc.com/Linux/2016-10/136047.htm

 

Ubuntu 16.04 下源码配置 LNMP 开发环境 http://www.linuxidc.com/Linux/2016-09/135381.htm

 

更多 CentOS 相关信息见CentOS 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=14

 

第三台主机的操作:MySQL 主机

1. 此处安装 mariadb-5.5.53,首先创建 mariadb 用户和组

groupadd mariadb
useradd -r -g mariadb -s /sbin/nologin

2. 安装依赖包

yum -y install gcc gcc-c++  cmake ncurses libxml2 libxml2-devel bison bison-devel

3. 开始编译

cmake . -DMYSQL_UNIX_ADDR=/tmp/mariadb.sock -DSYSCONFDIR=/etc -DMYSQL_TCP_PORT=3306 -DEXTRA_CHARSETS=all -DMYSQL_USER=mariadb -DCMAKE_INSTALL_PREFIX=/usr/local/mariadb -DMYSQL_DATADIR=/mydata/data  -DWITH_XTRADB_STORAGE_ENGINE=1 -DWITH_FEDERATEDX_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STPRAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWIYH_READLINE=1 -DWIYH_SSL=system -DVITH_ZLIB=system -DWITH_LOBWRAP=0 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci

4.make && make install

此过程比较慢,请耐心等待

5. 更改安装目录的属主属组,并创建数据存储目录、修改其相应的权限

mkdir -pv /mydata/data
chown -R mariadb:mariadb /mydata/data
cd /usr/local/mariadb
chown -R :mariadb ./*

CentOS 6.5 源码编译搭建 LNMP(三台独立主机实现)

CentOS 6.5 源码编译搭建 LNMP(三台独立主机实现)

6. 初始化数据库,复制配置文件

#scripts/mysql_install_db –user=mariadb –datadir=/mydata/data/

#cp mysql.server /etc/rc.d/init.d/mysqld

#cp my-large.cnf /etc/my.cnf

7. 修改配置文件 /etc/my.cnf

在 mysqld 下添加三个选项:
datadir = /mydata/data
innodb_file_per_table = ON
skip_name_resolve = ON

8. 将 mysqld 加入系统服务,并启动之

#chkconfig –add mysqld

注意:此处如果启动失败,显示错误为

CentOS 6.5 源码编译搭建 LNMP(三台独立主机实现)

则修改 /etc/rc.d/init.d/mysqld, 找到第 311 行,

CentOS 6.5 源码编译搭建 LNMP(三台独立主机实现)

然后再编辑 /etc/my.cnf,在 [mysqld] 中加入

CentOS 6.5 源码编译搭建 LNMP(三台独立主机实现)

之后再加入一个模块[mysqld_safe]

CentOS 6.5 源码编译搭建 LNMP(三台独立主机实现)

最后修改 /usr/local/mariadb 的目录属主属组为 mariadb 用户即可

chown -R mariadb:mariadb /usr/local/mariadb/

如果出现其他错误,则查看 /var/log/mariadb_error.log 日志,对症下药即可

至此,mariadb 已成功安装并启动

CentOS 6.5 源码编译搭建 LNMP(三台独立主机实现)

在第二台主机编写 php 访问 mysql 的代码,测试一下

CentOS 6.5 源码编译搭建 LNMP(三台独立主机实现)

到此为止,三台主机各自配置完毕,LNMP 环境可正常运行


 拓展:

一、为 php 主机安装 xcache,提供加速:

1. 此处编译安装 xcache-3.2.0,还需要一个安装组件 php-devel

2. 解压缩后,cd 至 xcache-3.2.0 目录,执行

/usr/local/php56/bin/phpize #为 php 新增一个模块

3. 编译操作

./configure --enable-xcache --with-php-congig=/usr/local/php56/bin/php-config  

4.make && make install

5. 安装完成后,出现以下结果:

CentOS 6.5 源码编译搭建 LNMP(三台独立主机实现)

将红框内的字符串复制下来备用

6. 然后执行

# mkdir -pv /etc/php56.d

# cp xcache.ini /etc/php56.d

注意:此处创建的目录 /etc/php56.d 必须跟编译 php 时的编译选项:–with-config-file-scan-dir=/etc/php56.d 一致,否则 php 找不到 xcache.ini,导致 xcache 无法工作;

# vim /etc/php56.d/xcache.ini

CentOS 6.5 源码编译搭建 LNMP(三台独立主机实现)

7. 重载 php-fpm,再次请求页面,就会看到:

CentOS 6.5 源码编译搭建 LNMP(三台独立主机实现)

二、安装 wordpress(个人信息发布平台)

1. 此处用的是 wordpress-4.7-zh_CN.zip,直接解压缩即可

2. 在 nginx 主机和 php 主机各存放一份压缩好的 wordpress, 位置是各主机对应在虚拟主机中的 root 定义的位置

CentOS 6.5 源码编译搭建 LNMP(三台独立主机实现)

3. 在 php 主机上操作如下:

# cp cp wp-config-sample.php wp-config.php

# vim wp-config.php

CentOS 6.5 源码编译搭建 LNMP(三台独立主机实现)

4. 测试效果如下:

CentOS 6.5 源码编译搭建 LNMP(三台独立主机实现)

三、安装 phpmyadmin(图形化数据库管理工具)

1. 安装包 phpMyAdmin-4.6.5.2-all-languages.zip

2. 与 wordpress 很相似,放在各自对应的路径下即可,然后修改 php 主机的配置文件:

# cp cp config.sample.inc.php config.inc.php

# vim config.inc.php

CentOS 6.5 源码编译搭建 LNMP(三台独立主机实现)

3. 访问即可,效果如下:

CentOS 6.5 源码编译搭建 LNMP(三台独立主机实现)

本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-12/138711.htm

CentOS 6.5 源码编译搭建 LNMP(三台独立主机实现)

搭建前准备:

1. 三台独立主机

nginx:192.168.1.102

php-fpm:192.168.1.105

MySQL:192.168.1.103

2. 相关软件的源码包

nginx:nginx-1.10.2

php:php-5.6.28

mysql:mariadb-5.5.53

3. 开发环境及依赖包组

包:openssl-devel;pcre-devel;zlib-devel

包组:Development Tools;Server Platform Development

开始搭建:


 

第一台主机的操作:nginx 服务器主机

1. 解压展开源码包 nginx-1.10.2.tar.gz

tar -xf nginx-1.10.2.tar.gz

2. 创建相应路径以便编译时使用

mkdir -pv /var/cache/nginx

3.cd 至 nginx-1.10.2 目录,运行以下命令

./configure  --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-threads --with-stream --with-stream_ssl_module --with-http_slice_module --with-file-aio --with-http_v2_module
 

4.make && make install 即可

5. 开启 nginx,在浏览器测试,出现即没有问题

CentOS 6.5 源码编译搭建 LNMP(三台独立主机实现)

6. 配置 nginx 支持 php-fpm

#vim /etc/nginx/nginx.conf 写入

 
    server {listen 80;
        server_name www.a.com;
        location / {root /test/html;
                index index.html index.htm index.php;
        }
        location ~ \.php$ {root           /test/html;
            fastcgi_pass   192.168.1.105:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /www/test1/$fastcgi_script_name;
            include        fastcgi_params;
        }
    }

第二台主机的操作:php 的主机

1. 解压展开源码包 php-5.6.28.tar.bz2

2.cd 至 php-5.6.28 目录,执行

./configure --prefix=/usr/local/php56 --with-mysql --with-openssl --with-mysqli --enable-mbstring --with-png-dir --with-jpeg-dir --with-freetype-dir --with-zlib --with-libxml-dir=/usr  --enable-xml --enable-sockets --with-mcrypt --with-config-file-path=/etc/php56 --with-config-file-scan-dir=/etc/php56.d --with-bz2 --enable-fpm

其中,–enable-fpm是关键选项

3.make && make install

4. 配置文件的操作

①#cp php.ini-development /etc/php.ini 

②#cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm (将 php-fpm 加入到系统服务中)

③#chkconfig –add php-fpm

查看添加结果:#chkconfig –list php-fpm

CentOS 6.5 源码编译搭建 LNMP(三台独立主机实现)

则完成添加;

注意:此处复制 php-fpm 到 /etc/rc.d/init.d/ 目录下时,有可能 php-fpm 自身没有任何执行权限,会导致添加系统服务时失败,自行添加执行权限即可解决这个问题

5. 修改 php-fpm 配置文件

①修改 php-fpm 的 pid 设置

CentOS 6.5 源码编译搭建 LNMP(三台独立主机实现)

②修改 php-fpm 的进程属主

CentOS 6.5 源码编译搭建 LNMP(三台独立主机实现)

③修改 php-fpm 的监听地址

CentOS 6.5 源码编译搭建 LNMP(三台独立主机实现)

这几项是服务正常开启运行的比较关键的几项,其余配置在此不再赘述

6. 开启 php-fpm 服务

service php-fpm start

CentOS 6.5 源码编译搭建 LNMP(三台独立主机实现)

确保 PHP 主机的 IP:9000 处于监听状态即可

 7. 创建动态资源目录, 做测试用,此处是 /www/test1 目录,创建一个 index.php 文件

 8. 开始测试,效果如下

CentOS 6.5 源码编译搭建 LNMP(三台独立主机实现) 此为请求静态资源

CentOS 6.5 源码编译搭建 LNMP(三台独立主机实现)此为请求动态资源

 

更多详情见请继续阅读下一页的精彩内容:http://www.linuxidc.com/Linux/2016-12/138711p2.htm

 

 

LNMP 安装参考如下文章

 

Ubuntu 16.04 下源码配置 LNMP 开发环境 http://www.linuxidc.com/Linux/2016-09/135381.htm

 

Ubuntu 14.04 搭建 LNMP  http://www.linuxidc.com/Linux/2015-05/116933.htm

 

Ubuntu 14.04 LTS 安装 LNMP Nginx\PHP5 (PHP-FPM)\MySQL  http://www.linuxidc.com/Linux/2014-05/102351.htm

 

在部署 LNMP 的时候遇到 Nginx 启动失败的 2 个问题 http://www.linuxidc.com/Linux/2013-03/81120.htm

 

CentOS7.2 编译安装 LNMP http://www.linuxidc.com/Linux/2016-12/138668.htm

 

CentOS 6.5 下编译安装新版 LNMP http://www.linuxidc.com/Linux/2016-10/136047.htm

 

Ubuntu 16.04 下源码配置 LNMP 开发环境 http://www.linuxidc.com/Linux/2016-09/135381.htm

 

更多 CentOS 相关信息见CentOS 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=14

 

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-21发表,共计9462字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中