设为首页 收藏本站
查看: 1350|回复: 0

LNMP搭建

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-2-18 08:35:51 | 显示全部楼层 |阅读模式
安装mysql
[iyunv@hongsrc]# wgethttp://cdn.mysql.com//Downloads/ ... ux2.6-x86_64.tar.gz
一、解压
[iyunv@hongsrc]# tar zxf mysql-5.5.47-linux2.6-x86_64.tar.gz
[iyunv@hongsrc]# mv mysql-5.5.47-linux2.6-x86_64 /usr/local/mysql

二、建立mysql用户

[iyunv@localhost src]# useradd -s/sbin/nologin –M  mysql



三、初始化数据库

[iyunv@hongmysql]# mkdir -p /data/mysql ; chown -R mysql:mysql /data/mysql
[iyunv@hong mysql]# yum -y installlibaio-*  (apt-*)
[iyunv@localhostmysql]#  ./scripts/mysql_install_db--user=mysql --datadir=/data/mysql

四、拷贝启动脚本和配置文件
[iyunv@hongmysql]# cp support-files/my-large.cnf /etc/my.cnf
[iyunv@hongmysql]# cp support-files/mysql.server /etc/init.d/mysqld
[iyunv@hongmysql]# chmod 755 /etc/init.d/mysqld

五、修改配置文件
[iyunv@hongmysql]# vim /etc/init.d/mysqld
46basedir=/usr/local/mysql
47 datadir=/data/mysql

六、添加开机启动,启动mysql
[iyunv@hongmysql]# chkconfig --add mysqld
[iyunv@hongmysql]# chkconfig mysqld on
[iyunv@hongmysql]#  service mysqld start

七、查看mysql服务和端口有没启动
[iyunv@hongmysql]# netstat –lnp
[iyunv@hongmysql]# ps aux |grep mysqld

安装php
[iyunv@localhost src]# wget http://cn2.php.net/distributions/php-5.5.30.tar.gz

  • 解压。

[iyunv@hong php]#tar zxf php-5.5.30.tar.gz
[iyunv@hong php]#mv /usr/local/src/php-5.5.30 /usr/local/php

二、安装所需要的包
[iyunv@hong php]# yum -y install gcc   libxml2-*  curl-devel  libjpeg-*  libpng-*  freetype-* openssl-*(libcurl-devel)
[iyunv@hong php]# rpm -ivh http://www.aminglinux.com/bbs/da ... ease-6-7.noarch.rpm

[iyunv@hong php]# yum install -y  libmcrypt-devel

三、创建用户
[iyunv@hong etc]# useradd -s /sbin/nologin -M php-fpm

四、配置编译
[iyunv@hong php]#  ./configure --prefix=/usr/local/php--with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=php-fpm--with-fpm-group=php-fpm --with-mysql=/usr/local/mysql--with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir--with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir--with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring--enable-exif --enable-zend-multibyte --disable-ipv6 --with-pear --with-curl--with-openssl

五、进行编译和安装
[iyunv@hong php]#make  &&  make install
/usr/bin/ld: cannot find -lltdlcollect2: ld returned 1 exit statusmake: *** [sapi/fpm/php-fpm] 错误 1

解决方法:

yum install -y libtool-ltdl-devel
四、修改配置文件
[iyunv@hong php]# cp php.ini-production /usr/local/php/etc/php.ini
[
root@hong php]# vim /usr/local/php/etc/php.ini

1933 [global]
1934 pid = /usr/local/php/var/run/php-fpm.pid
1935 error_log = /usr/local/php/var/log/php-fpm.log
1936 [www]
1937 listen = /tmp/php-fcgi.sock
1938 user = php-fpm
1939 group = php-fpm
1940 pm = dynamic
1941 pm.max_children = 50
1942 pm.start_servers = 20
1943 pm.min_spare_servers = 5
1944 pm.max_spare_servers = 35
1945 pm.max_requests = 500
1946 rlimit_files = 1024

六、复制启动脚本,开机自动加载
[iyunv@hong php]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[iyunv@hong php]# chmod 755 /etc/init.d/php-fpm
[iyunv@hong php]# chkconfig php-fpm on
[iyunv@hong php]# mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

七、启动服务并查看端口
[iyunv@hong php]# service php-fpm start
[iyunv@hong etc]# ps aux |grep php-fpm
[iyunv@hong etc]# netstat –lnp


Nginx安装
[iyunv@hong src]#wget http://nginx.org/download/nginx-1.8.0.tar.gz
  • 解压

[iyunv@hong src]# tar zxf nginx-1.8.0.tar.gz
[iyunv@localhost src]# cd nginx-1.8.0

二、配置编译
[iyunv@hong nginx]# yum -y install pcre-*
[iyunv@hong nginx]#./configure --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/conf/nginx.conf--with-http_realip_module --with-http_sub_module --with-http_gzip_static_module--with-http_stub_status_module --with-pcre

三、编译安装
[iyunv@hong nginx]#make && make install

四、启动nginx
[iyunv@hong nginx]# /usr/local/nginx/sbin/nginx
注意:要关闭httpd。

五、配置nginx文件
[iyunv@hong nginx]# vim /usr/local/nginx/nginx.conf

65         location ~ \.php$ {
66             root           html;
67             fastcgi_pass   127.0.0.1:9000;
68             fastcgi_index  index.php;
69  fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;   //这个地方如果没更改路径,访问时就会是404
70            include       fastcgi_params;
71         }

六、测试php
[iyunv@hong html]# cd /usr/local/nginx/html

1.编辑一个php文件
[iyunv@hong html]#vim info.php
<?php
phpinfo();
?>

2.检查配置文件
~[iyunv@hong html]# /usr/local/nginx/sbin/nginx  -t

3.启动nginx服务
~[iyunv@hong html]# /usr/local/nginx/sbin/nginx -s reload

~4.访问网页


六、编辑nginx脚本(自己编辑)
[iyunv@hong html]# vim /etc/init.d/nginx
#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings

NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"
RETVAL=0
prog="Nginx"

start() {
        echo -n $"Starting$prog: "
        mkdir -p /dev/shm/nginx_temp
        daemon $NGINX_SBIN -c$NGINX_CONF
        RETVAL=$?
        echo
        return $RETVAL
}

stop() {
        echo -n $"Stopping$prog: "
        killproc -p $NGINX_PID$NGINX_SBIN -TERM
        rm -rf /dev/shm/nginx_temp
        RETVAL=$?
        echo
        return $RETVAL
}

reload(){
        echo -n $"Reloading$prog: "
        killproc -p $NGINX_PID$NGINX_SBIN -HUP
        RETVAL=$?
        echo
        return $RETVAL
}

restart(){
        stop
        start
}

configtest(){
    $NGINX_SBIN -c $NGINX_CONF -t
    return 0
}

case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  reload)
        reload
        ;;
  restart)
        restart
        ;;
  configtest)
        configtest
        ;;
  *)
        echo $"Usage: $0{start|stop|reload|restart|configtest}"
        RETVAL=1
esac

exit $RETVAL

赋予权限755
[iyunv@hong html]# chmod 755 /etc/init.d/nginx

添加成开机自启动
[iyunv@hong html]# chkconfig --add nginx
[iyunv@hong html]# chkconfig  nginxon
[iyunv@hong html]# service nginx restart

七、修改nginx配置文件

[iyunv@hong html]# > /usr/local/nginx/conf/nginx.conf  
[iyunv@hong html]# vim /usr/local/nginx/conf/nginx.conf
user nobody nobody;

worker_processes 2;

error_log/usr/local/nginx/logs/nginx_error.log crit;

pid /usr/local/nginx/logs/nginx.pid;

worker_rlimit_nofile 51200;


events

{

    useepoll;

   worker_connections 6000;

}


http

{

   include mime.types;

   default_type application/octet-stream;

   server_names_hash_bucket_size 3526;

   server_names_hash_max_size 4096;

log_format hong '$remote_addr$http_x_forwarded_for [$time_local]' #日志名字可以修改


   '$host "$request_uri" $status'

   '"$http_referer" "$http_user_agent"';

   sendfile on;

   tcp_nopush on;

   keepalive_timeout 30;

   client_header_timeout 3m;

   client_body_timeout 3m;

   send_timeout 3m;

   connection_pool_size 256;

   client_header_buffer_size 1k;

   large_client_header_buffers 8 4k;

   request_pool_size 4k;

   output_buffers 4 32k;

   postpone_output 1460;

   client_max_body_size 10m;

   client_body_buffer_size 256k;

   client_body_temp_path /usr/local/nginx/client_body_temp;

   proxy_temp_path /usr/local/nginx/proxy_temp;

   fastcgi_temp_path /usr/local/nginx/fastcgi_temp;

   fastcgi_intercept_errors on;

   tcp_nodelay on;

   gzip on;

   gzip_min_length 1k;

   gzip_buffers 4 8k;

   gzip_comp_level 5;

   gzip_http_version 1.1;

   gzip_types text/plain application/x-javascript text/css text/htmapplication/xml;

    includevhosts/*.conf;    #nginx支持默认的虚拟主机

}


然后编辑虚拟主机配置文件

[iyunv@hong html]# cd /usr/local/nginx/conf

[iyunv@hong conf]# mkdir vhosts

[iyunv@localhost vhosts]# vim default.conf


server

{

   listen 80 default_server;

   server_name localhost;

   index index.html index.htm index.php;

root /tmp/123;     //限制第一个默认主机为403

deny all;

}



创建限制访问的目录

[iyunv@hong vshosts]# mkdir /tmp/123


检查配置是否有错
[iyunv@localhost vhosts]# /usr/local/nginx/sbin/nginx –t

访问本地时
[iyunv@hong 123]# curl -x127.0.0.1:80  www.dshjkf.com


虚拟主机添加你需要的网站如:
[iyunv@hong vshosts]# vim hong.conf

server
{
    listen 80;
    server_name www.hong.com;
    index index.html index.htmindex.php;
    root/data/www;     #网站所在路径

    location ~ \.php$ {
        include fastcgi_params;
       # fastcgi_passunix:/tmp/php-fcgi.sock;
                  fastcgi_pass127.0.0.1:9000;            #这个地方不添加端口可能会报502错误
        fastcgi_index index.php;
        fastcgi_paramSCRIPT_FILENAME/data/www$fastcgi_script_name;
    }
}
[iyunv@localhost vhosts]# /usr/local/nginx/sbin/nginx -t
[iyunv@localhost vhosts]# /etc/init.d/nginx reload

测试网站访问
[iyunv@hong www]# curl -x127.0.0.1:80 hong.com -I
HTTP/1.1 302 Moved Temporarily
Server: nginx/1.8.0
Date: Sun, 13 Dec 2015 21:09:07 GMT
Content-Type: text/html
Connection: keep-alive
X-Powered-By: PHP/5.5.30
location: install


PHP-fpm配置文件
/usr/local/php/etc/php-fpm.conf   //php服务配置
  /usr/local/php/etc/php.ini        //php全局配置
  • 清空配置文件

[iyunv@hong~]# > /usr/local/php/etc/php-fpm.conf
[iyunv@hong~]# vim /usr/local/php/etc/php-fpm.conf

[global]
pid =/usr/local/php/var/run/php-fpm.pid
error_log =/usr/local/php/var/log/php-fpm.log
[www]
listen = /tmp/www.sock  (可自定义)
user =php-fpm           (可自定义)
group =php-fpm           (可自定义)
pm = dynamic           //动态加载管理以下模块
pm.max_children= 50     //子进程最大50
pm.start_servers= 20      //刚开始启动20
pm.min_spare_servers= 5    //最小5
pm.max_spare_servers= 35   //最多
pm.max_requests= 500      //在生命周期之类处理多少个请求,自动销毁
rlimit_files= 1024           //每一个进程描述的限制
slowlog = /tmp/www_slow.log  //查找网站速度慢
request_slowlog_timeout = 1  //超时1分钟
php_admin_value[open_basedir]=/data/www/:/tmp/ //多个路径用:冒号隔开


建立多个pool池子(可选)
[www1]
listen =/tmp/php-fcgi1.sock  (可自定义)
user =php-fpm           (可自定义)
group =php-fpm           (可自定义)
pm = dynamic           //动态加载管理以下模块
pm.max_children= 50     //子进程最大50
pm.start_servers= 20      //刚开始启动20
pm.min_spare_servers= 5    //最小5
pm.max_spare_servers= 35   //最多
pm.max_requests= 500      //在生命周期之类处理多少个请求,自动销毁
rlimit_files= 1024           //每一个进程描述的限制

检查是否有错
[iyunv@hong php]# /usr/local/php/sbin/php-fpm -t

重启服务
[iyunv@hong ~]# /etc/init.d/php-fpm restart


建立池子的好处:可以把权限分开,不同域名在不同池子也可以到同一个池子;其次如果一个池子挂了,整个池子的网站都挂了,分开多个池子网站可以分开


解决nginx502
1.编辑虚拟配置文件
[iyunv@hong vhosts]# vim /usr/local/nginx/conf/vhosts/hong.conf

server
{
    listen 80;
    server_name www.hong.com;
    index index.html index.htmindex.php;
    root /data/www;

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass unix:/tmp/www.sock;
        #fastcgi_pass127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_paramSCRIPT_FILENAME /data/www$fastcgi_script_name;
    }
}

检查错误
[iyunv@hong vhosts]# /usr/local/nginx/sbin/nginx -t
重新启动或加载配置文件
[iyunv@hong vhosts]# /etc/init.d/nginx reload

访问出现502,排查步骤:
1.查看错误日志
[iyunv@hong www]# cat /usr/local/nginx/logs/nginx_error.log
2.查看sock文件权限,权限的属主和属组都是root 并且只有读写权限,而nginx的用户是nobody

[iyunv@hong www]# ll -d /tmp/php-fcgi.sock
srw-rw---- 1 root root 0 12月 14 05:26/tmp/php-fcgi.sock

3.所以要修改配置。进入php配置文件
[iyunv@hong www]# vim /usr/local/php/etc/php-fpm.conf
6 user = php-fpm
  7 group = php-fpm
  8 listen.owner = nobody        //监听的用户
  9 listen.group = nobody         //监听的组
(listen.mode =444)

4.启动php服务
[iyunv@localhostvhosts]# /usr/local/php/sbin/php-fpm -t
[12-Jan-201602:14:25] NOTICE: configuration file /usr/local/php/etc/php-fpm.conf test issuccessful

[iyunv@hongwww]# /etc/init.d/php-fpm restart
Gracefullyshutting down php-fpm . done
Startingphp-fpm  done

5.在访问域名看能否访问www.hong.com


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-179358-1-1.html 上篇帖子: LAMP的部署安装 下篇帖子: LAMP discuz安装主要遇到两个问题
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表