lnmp分离部署 目录 目录.... 1 版权声明:.... 2 文档信息:.... 2 1.在192.168.200.101上安装nginx. 3 2.在192.168.200.102上安装mysql. 5 3.在192.168.200.103上安装php. 7 文档信息: 文档作者:amun 文档版本:Version 1.1 修改记录:2017-04-18 系统环境:CentOS 6.8 64 bit 环境: 一、在三台机器上分别部署: Nginx 192.168.200.101 Mysql 192.168.200.102 Php 192.168.200.103 1.在192.168.200.101上安装nginx yum -y installpcre-devel zlib-devel useradd -M -s/sbin/nologin nginx tar xfnginx-1.6.0.tar.gz -C /usr/src/ cd/usr/src/nginx-1.6.0/ ./configure--prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module--with-http_stub_status_module --with-http_gzip_static_module --with-pcre && make &&make install ln -s/usr/local/nginx/sbin/nginx /usr/local/sbin/ 修改nginx配置文件,把server段的以下内容去掉注释 vim/usr/local/nginx/conf/nginx.conf 65行左右 location ~ \.php${ fastcgi_pass 192.168.200.103:9000; ##PHP服务器的IP地址,及监听端口 fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name; include fastcgi_params; } 检查语法及启动: nginx –t nginx 使用浏览器访问http://192.168.200.101能正常访问 Nginx服务安装完毕 创建与PHP、mysql结合的结合页面 cd /var/www/html vim index.php ##添加测试页面 <?php $link = mysql_connect(‘192.168.200.102‘,‘root‘,‘123456‘); if ($link) echo "Success..."; else echo "Failure..."; mysql_close(); phpinfo(); ?> 2.在192.168.200.102上安装mysql 安装前准备: yum -y install gcccmake useradd -M -s/sbin/nologin mysql tar xfmysql-5.5.22.tar.gz cd mysql-5.5.22 cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-DSYSCONFDIR=/etc -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_TCP_PORT=3306-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DMYSQL_USER=mysql -DEXTRA_CHARSETS=all-DWITH_READLINE=1 -DWITH_SSL=system -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1-DWITH_INNOBASE_STORAGE_ENGINE=1 make &&make install 配置mysql cd/usr/local/mysql/ chown -Rmysql.mysql /usr/local/mysql/ 初始化数据库: ./scripts/mysql_install_db--user=mysql --datadir=/usr/local/mysql/data 调整mysql: cd/usr/local/mysql/ cpsupport-files/my-medium.cnf /etc/my.cnf cpsupport-files/mysql.server /etc/init.d/mysqld chmod +x/etc/init.d/mysqld chkconfig mysqldon 环境变量设置: vim /etc/profile 在最后一行添加 PATH=/bin:/usr/local/mysql/bin/:$PATH source /etc/profile vim/etc/ld.so.conf 添加以下内容: includeld.so.conf.d/*.conf /usr/local/mysql/lib/ 启用配置 Ldconfig 创建mysql数据库用户 mysqladmin -urootpassword ‘123456‘ 数据库授权: grant allprivileges on *.* to ‘root‘@‘%‘ identified by ‘123456‘; grant allprivileges on *.* to ‘root‘@‘localhost‘ identified by ‘123456‘; flush privileges; 3.在192.168.200.103上安装php PHP所需依赖及添加用户 yum -y install gccopenssl-devel pcre pcre-devel zlib-devel libxml2-devel curl-devel libjpeg-devellibpng-devel freetype-devel bzip2-devel useradd -M -s/sbin/nologin www 安装php扩展工具 源代码安装libmcrypt tar zxflibmcrypt-2.5.8.tar.gz cdlibmcrypt-2.5.8/ ./configure &&make && make install ln -s/usr/local/lib/libmcrypt.* /usr/lib/ 源代码安装mhash tar zxfmhash-0.9.9.9.tar.gz cd mhash-0.9.9.9/ ./configure&& make && make install ln -s /usr/local/lib/libmhash*/usr/lib/ 源代码安装mcrypt tar zxfmcrypt-2.6.8.tar.gz cd mcrypt-2.6.8/ ./configure 编译时候报错: configure: error:*** libmcrypt was not found 解决办法: ln-s /usr/local/bin/libmcrypt_config /usr/bin/libmcrypt_config exportLD_LIBRARY_PATH=/usr/local/lib: LD_LIBRARY_PATH 重新执行./configure后安装 make &&make install 安装php tar xfphp-5.3.28.tar.gz cd php-5.3.28 ./configure--prefix=/usr/local/php5 --with-gd --with-zlib --with-mysql=mysqlnd--with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-config-file-path--enable-mbsrting --enable-fpm --with-jpeg-dir=/usr/lib --enable-sockets&& make && make install 调整php、php-fpm加入系统服务: cpphp.ini-development /usr/local/php5/php.ini ln -s/usr/local/php5/bin/* /usr/local/bin/ ln -s/usr/local/php5/sbin/* /usr/local/sbin/ cpsapi/fpm/init.d.php-fpm /etc/init.d/php-fpm chmod +x/etc/init.d/php-fpm chkconfig --addphp-fpm chkconfig php-fpmon 修改php-fpm配置文件: cd/usr/local/php5/etc/ cpphp-fpm.conf.default php-fpm.conf vim/usr/local/php5/etc/php-fpm.conf 修改以下内容: [global] pid =run/php-fpm.pid error_log =log/php-fpm.log log_level = error daemonize = yes [www] user = www group = www listen = 127.0.0.1.:9000 pm = dynamic ## 进程管理方式为dynamic,static为静态 pm.max_children =32 ##子进程最大数根据官方建议,小于2GB内存的服务器, ##可以只开启64个进程,4GB以上内存的服务器可以开启200个进程。 pm.start_servers =15 ##动态方式下的起始php-fpm进程数量。 pm.min_spare_servers= 5 ##动态方式下的最小php-fpm进程数量 pm.max_spare_servers= 32 ##动态方式下的最大php-fpm进程数量 启动php-fpm service php-fpmstart cd /var/www/html vim index.php ##添加测试页面,必须和nginx的测试页面在相同路径下 <?php $link = mysql_connect(‘192.168.200.102‘,‘root‘,‘123456‘); if ($link) echo "Success..."; else echo "Failure..."; mysql_close(); phpinfo(); ?> 最后使用客户端浏览器访问http://192.168.200.101/index.php end
本文出自 “微凉清风的博客” 博客,请务必保留此出处http://amunlinux.blog.51cto.com/13112118/1946774
原文地址:http://amunlinux.blog.51cto.com/13112118/1946774