231fds 发表于 2016-1-19 08:34:58

LNMP下搭建discuz论坛---实战讲解

       1.LNMP 是一个缩写,它指一组通常一起使用来运行动态网站或者服务器的自由软件:
Linux+Nginx+MySQL+php( php-fpm),由于 Nginx 有大并发的优势,现在越来越多的企
业 LAMP 平台都在向 LNMP 迁移。
接着我们开始进入 LNMP 搭建。现实生产环境下, 不同的业务需求都不相同,因此更多的
企业会考虑使用源码搭建 LNMP 环境,这样可以更加灵活使用各个功能参数将性能调制到
最佳状态。当然如果贵公司的环境比较简单, 可以考虑 rpm 包安装。
注意:本实验环境基本上都是从各大官网下载的最新安装包。
安装 LNMP 环境所需要的最基本包
#yum -y install libjpeg-devel libpng-devel libtiff-devel fontconfig-devel freetype-devel libXpm-devel gettext-devel openssl-devel libtool-ltdl-devel gcc *c++*
ncurses-devel      // libjpeg-devel , libpng-devel , libtiff-devel , fontconfig-devel ,
freetypedevel,
libXpm-devel 这些都是图片与字体相关的开发包,为了使 php 可以对其做更好的支持。
gettext 是语言相关的一个函数库。 openssl-devel 是一套工具,用于生成 X.509 协议中所
使用的密钥,公钥等文件。 libtool 是一个通用库支持脚本,在 php 编译过程中会需要使用
到。
2.安装 nginx 软件包
# tar -xzf nginx-1.2.7.tar.gz
# useradd nginx
# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx/ --with-http_stub_status_module --with-http_ssl_module --withsha1=/usr/lib   //-with-sha1 指定希哈函数库位置, 其他参数参看以上共享文档
#make && make install
# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
//启动 nginx
# links 192.168.17.128 //出现 welcome to nginx! 说明nginx 安装成功
3、安装mysql
# tarxf mysql-5.1.54.tar.gz
# cd mysql-5.1.54
# ./configure --prefix=/opt/mysql && make && make install
# useradd -s /sbin/nologin mysql -M
# cd /opt/mysql
# chown mysql.mysql . -R
# ./bin/mysql_install_db --user=mysql
# chown root . -R
# chown mysql var -R
# cp share/mysql/mysql.server /etc/init.d/mysql
# service mysql start
# chkconfig --add mysql
# chkconfig mysql on
# netstat -tnlp |grep :3306        --验证是否已经起来
tcp      0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      16232/mysqld   
4.安装PHP(fpm-->start-->php-->process)
    #yum -y install libxml2-devel mysql-devel (mysql-php)
# tar -xf php-5.5.3.tar.bz2
# ./configure --prefix=/opt/php5 --with-config-file-path=/opt/php5 --enable-fpm --enable-fastcgi--with-mysql=/opt/mysql
        --prefix=/opt/php5                                        --指定php的安装路径
        --with-config-file-path=/opt/php5                --指定php的配置文件存储目录
        --enable-fpm --enable-fastcgi                        --支持以CGI的方式启动php
        --with-mysql=/opt/mysql                                --让php支持mysql数据库

# make && make install
cp php.ini-production /opt/php5/php.ini
4、通过php-fpm以进程的方式启动php
# cd /opt/php5/etc/
# cp php-fpm.conf.default php-fpm.conf
# /opt/php5/sbin/php-fpm --以进程的方式启动PHP
# netstat -tnlp | grep php
tcp      0      0 127.0.0.1:9000            0.0.0.0:*                   LISTEN      26789/php-fpm      
# vim php-fpm.conf
159 listen = 127.0.0.1:9000
225 pm.max_children = 32
230 pm.start_servers = 10
235 pm.min_spare_servers = 10
240 pm.max_spare_servers = 12
# ps aux | grep fpm
root   269170.10.3 1377043312 ?      Ss   12:01   0:00 php-fpm: master process (/opt/php5/etc/php-fpm.conf)
nobody   269180.00.2 1377042852 ?      S    12:01   0:00 php-fpm: pool www   
nobody   269190.00.2 1377042852 ?      S    12:01   0:00 php-fpm: pool www   
nobody   269200.00.2 1377042852 ?      S    12:01   0:00 php-fpm: pool www   
nobody   269210.00.2 1377042852 ?      S    12:01   0:00 php-fpm: pool www   
nobody   269220.00.2 1377042856 ?      S    12:01   0:00 php-fpm: pool www   
nobody   269230.00.2 1377042856 ?      S    12:01   0:00 php-fpm: pool www   
nobody   269240.00.2 1377042856 ?      S    12:01   0:00 php-fpm: pool www   
nobody   269250.00.2 1377042856 ?      S    12:01   0:00 php-fpm: pool www   
nobody   269260.00.2 1377042856 ?      S    12:01   0:00 php-fpm: pool www   
nobody   269270.00.2 1377042856 ?      S    12:01   0:00 php-fpm: pool www   
逻辑
nginx<--tcp/socket-->php<--/usr/lib64/mysql/libmysqlclient.so-->mysqld
5.测试是否解析php文件
创建测试文件:
vim /usr/local/nginx/html/test.php
内容如下:
<?php echo phpinfo();?>
测试:
# curl localhost/test.php
或者使用浏览器打开http://YourServerIPAddress/test.php
重要:如果解析不了,检查日志发现连接不到php,我的php版本为5.5.23,比较新的版本,需要在php/etc/php-fpm.conf文件中添加
listen.owner = nobody
listen.group = nobody
这两行,再重启一下服务就能使用php了
原因是/tmp/php-fcgi.sock这个文件没有读权限
至此,最新版的LNMP环境源码编译安装完成了.
6、整合nginx/php/mysql
# cat nginx.conf
usernginx nginx;
worker_processes2;
error_log/usr/local/nginx/logs/error.lognotice;
pid      logs/nginx.pid;
worker_rlimit_nofile 5120;
events {
    use epoll;
    worker_connections5120;
}
http {
    include       mime.types;
    default_typeapplication/octet-stream;
    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 8m;
    #limit_zone one $binary_remote_addr 32k;
    sendfile      on;
    tcp_nopush   on;
    keepalive_timeout60;
    tcp_nodelay on;
    gzipon;
    gzip_min_length1k;
    gzip_buffers   4 16k;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_types       text/plain application/x-javascript text/css application/xml;
    gzip_vary on;   
    log_formatwwwlogs'$remote_addr - $remote_user [$time_local] $request $status $body_bytes_sent $http_referer $http_user_agent $http_x_forwarded_for';
    server {
      listen       80;
      server_namewww.bbs.com;
      location / {
            root   /data/webroot/html/discuz;
            indexindex.php;
      }
      location ~ \.php$ {
            root         /data/webroot/html/discuz;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_indexindex.php;
            fastcgi_paramSCRIPT_FILENAME/data/webroot/html/discuz$fastcgi_script_name;
            include      fastcgi_params;
          }   
}
}
7检测nginx语法正确性
# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
重启nginx服务
service nginx restart
8.安装discuz论坛
下载相关软件包:http://download.comsenz.com/DiscuzX/
#mkdir /data/webroot/html
# unzip Discuz_X3.2_SC_UTF8.zip
# mv upload /data/webroot/html/discuz
# chown -R nginx.nginx /data/webroot/html/discuz
在本地Hosts文件中添加如下记录:
C:\Windows\System32\Drivers\etc\hosts#打开此文件添加如下内容
192.168.17.128       www.bbs.com
9。浏览器打开 192.168.17.128/install开始安装!!!
页: [1]
查看完整版本: LNMP下搭建discuz论坛---实战讲解