LNMP架构

简介:

LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构。

Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统。代表版本有:debiancentosubuntufedoragentoo等。

Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。

Mysql是一个小型关系型数据库管理系统

PHP是一种在服务器端执行的嵌入HTML文档的脚本语言

这四种软件均为免费开源软件,组合到一起,成为一个免费、高效、扩展性强的网站服务系统。

特点

Nginx是一个小巧而高效的Linux下的Web服务器软件,是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler 站点开发的,已经在一些俄罗斯的大型网站上运行多年,相当的稳定。

Nginx性能稳定、功能丰富、运维简单、处理静态文件速度快且消耗系统资源极少。

优点

作为 Web 服务器:相比 Apache,Nginx 使用更少的资源,支持更多的并发连接,体现更高的效率。

作为负载均衡服务器:Nginx 既可以在内部直接支持RailsPHP,也可以支持作为 HTTP代理服务器对外进行服务。Nginx 用C编写,不论是系统资源开销还是CPU使用效率都比Perlbal要好的多。

作为邮件代理服务器:Nginx同时也是一个非常优秀的邮件代理服务器(最早开发这个产品的目的之一也是作为邮件代理服务器),Last/fm 描述了成功并且美妙的使用经验。

Nginx 安装非常的简单,配置文件非常简洁(还能够支持perl语法)。Nginx支持平滑加载新的配置,还能够在不间断服务的情况下进行软件版本的升级。

系统环境: RHEL6 x86-64 selinux and iptables disabled

一. mysql安装编译

软件包依赖性:

yum install -y gcc gcc-c++ make ncurses-devel bison openssl-devel zlib-devel cmake
tar zxvf mysql-5.5.12.tar.gz
cd mysql-5.5.12
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql    \#安装目录
    -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data    \#数据库存放目录
    -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock    \#Unix socket 文件路径
    -DWITH_MYISAM_STORAGE_ENGINE=1    \#安装 myisam 存储引擎
    -DWITH_INNOBASE_STORAGE_ENGINE=1    \#安装 innodb 存储引擎
    -DWITH_ARCHIVE_STORAGE_ENGINE=1    \#安装 archive 存储引擎
    -DWITH_BLACKHOLE_STORAGE_ENGINE=1    \#安装 blackhole 存储引擎
    -DWITH_PARTITION_STORAGE_ENGINE=1    \#安装数据库分区
    -DENABLED_LOCAL_INFILE=1    \#允许从本地导入数据
    -DWITH_READLINE=1    \#快捷键功能
    -DWITH_SSL=yes    \#支持 SSL
    -DDEFAULT_CHARSET=utf8    \#使用 utf8 字符
    -DDEFAULT_COLLATION=utf8_general_ci    \#校验字符
    -DEXTRA_CHARSETS=all    \#安装所有扩展字符集
    -DMYSQL_TCP_PORT=3306    \#MySQL 监听端口


make && make install
[root@server1 mysql]# cd support-files/
[root@server1 support-files]# ls
magic  my-default.cnf  mysqld_multi.server  mysql-log-rotate  mysql.server
[root@server1 support-files]# cp my-default.cnf /etc/my.cnf

[root@server1 mysql]# vim /etc/my.cnf
更改以下内容:
        # These are commonly set, remove the # and set as required.
        basedir = /usr/local/lnmp/mysql
        datadir = /usr/local/lnmp/mysql/data
        port = 3306
        # server_id = .....
        socket = /usr/local/lnmp/mysql/data/mysql.sock

[root@server1 support-files]# cp mysql.server /etc/init.d/mysqld

[root@server1 support-files]# groupadd -g 27 mysql
[root@server1 support-files]# useradd -u 27 -g 27 mysql
[root@server1 support-files]# id mysql
uid=27(mysql) gid=27(mysql) groups=27(mysql)
[root@server1 support-files]# cd ..
[root@server1 mysql]# chown -R mysql.mysql .

[root@server1 bin]# vim ~/.bash_profile 
更改内容:
        PATH=$PATH:/usr/local/mysql/bin
[root@server1 bin]# source ~/.bash_profile 

[root@server1 mysql]# bin/mysql_install_db --user=mysql --basedir=/usr/local/lnmp/mysql --datadir=/usr/local/lnmp/mysql/data

[root@server1 mysql]# chown -R mysql data
[root@server1 mysql]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/usr/local/lnmp/mysql/data/server1.err'.
. SUCCESS! 
[root@server1 mysql]# mysql_secure_installation       #更改密码为REDHAT.org123

[root@server1 mysql]# /etc/init.d/mysqld start
[root@server1 mysql]# /etc/init.d/mysqld status
 SUCCESS! MySQL running (2452)

[root@server1 mysql]# bin/mysql -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 5.7.17 Source distribution

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.08 sec)

二.  PHP安装编译

软件包依赖性:

yum install net-snmp-devel curl-devel libxml2-devel libpng-devel libjpeg-devel freetype-devel gmp-devel openldap-devel -y

yum install -y gcc libmcrypt libmcrypt-devel(需下载安装包或源码编译)

源码编译:

tar jxf php-5.6.35.tar.bz2
cd php-5.6.35

./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local 
    /lnmp/php/etc --with-mysql=/usr/local/lnmp/mysql/ --enable-mysqlnd --with-
    mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl 
    --with-snmp --with-gd -   -with-zlib --with-curl --with-libxml-dir --with-png-dir 
    --with-jpeg-dir --with-freetype-dir --with-pear --with-gettext --enable-inline-
    optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring 
    --enable-fpm --with-mcrypt --with-mhash --with-gmp
make
make install
[root@server1 php-5.6.35]# cp php.ini-production /usr/local/lnmp/php/etc/php.ini
[root@server1 php-5.6.35]# cd sapi/
[root@server1 sapi]# cd fpm/
[root@server1 fpm]# ls
config.m4       init.d.php-fpm.in  php-fpm.8        php-fpm.service     tests
CREDITS         LICENSE            php-fpm.8.in     php-fpm.service.in  www.conf.in
fpm             Makefile.frag      php-fpm.conf     status.html
init.d.php-fpm  php-fpm            php-fpm.conf.in  status.html.in
[root@server1 fpm]# cp init.d.php-fpm /etc/init.d/
[root@server1 init.d]# mv init.d.php-fpm php-fpm
[root@server1 init.d]# chmod +x php-fpm
[root@server1 init.d]# cd /usr/local/lnmp/php/etc/
[root@server1 etc]# cp php-fpm.conf.default php-fpm.conf
[root@server1 etc]# vim php-fpm.conf
pid = run/php-fpm.pid    #去点之前注释

[root@server1 etc]# useradd nginx

[root@server1 etc]# /etc/init.d/php-fpm reload
Reload service php-fpm  done
[root@server1 etc]# netstat -antlp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      921/sshd            
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      998/master          
tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      8985/php-fpm        
tcp        0      0 172.25.100.1:22             172.25.100.250:52824        ESTABLISHED 1382/sshd           
tcp        0      0 172.25.100.1:22             172.25.100.250:53778        ESTABLISHED 2513/sshd           
tcp        0      0 :::22                       :::*                        LISTEN      921/sshd            
tcp        0      0 ::1:25                      :::*                        LISTEN      998/master          
tcp        0      0 :::3306                     :::*                        LISTEN      2452/mysql      

三.  NGINX安装编译

软件包依赖性:

[root@server1 etc]# yum install -y pcre-devel
[root@server1 lnmp]# tar zxf nginx-1.14.0.tar.gz 
[root@server1 lnmp]# cd nginx-1.14.0
[root@server1 nginx-1.14.0]# ls
auto     CHANGES.ru  configure  html     man     src
CHANGES  conf        contrib    LICENSE  README
[root@server1 nginx-1.14.0]# vim auto/cc/gcc
[root@server1 nginx-1.14.0]# ./configure --prefix=/usr/local/lnmp/nginx --with-http_stub_status_module --with-http_ssl_module --with-threads --with-file-aio
[root@server1 nginx-1.14.0]# make
[root@server1 nginx-1.14.0]# make install

[root@server1 nginx-1.14.0]# cd conf
[root@server1 conf]# ls
fastcgi.conf    koi-utf  mime.types  scgi_params   win-utf
fastcgi_params  koi-win  nginx.conf  uwsgi_params
[root@server1 conf]# vim nginx.conf
更改内容:
user  nginx nginx;
worker_processes  auto;

events {
    worker_connections  65535;
}

 location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi.conf;
        }


[root@server1 nginx]# cd html
[root@server1 html]# ls
50x.html  index.html
[root@server1 html]# vim index.php
<?php
  phpinfo()
?>

[root@server1 nginx]# nginx -t
nginx: the configuration file /usr/local/lnmp/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/lnmp/nginx/conf/nginx.conf test is successful
[root@server1 nginx]# nginx 
[root@server1 nginx]# nginx -s reload

 

 更改Nginx默认发布目录:

[root@server1 etc]# vim /usr/local/lnmp/nginx/conf/nginx.conf

location / {
            root   html;
            index  index.php index.html index.htm;
        }

[root@server1 etc]# nginx -s reload

 

 

1010 ; Default socket name for local MySQL connects.  If empty, uses the built-in
1011 ; MySQL defaults.
1012 ; http://php.net/pdo_mysql.default-socket
1013 pdo_mysql.default_socket=/usr/local/lnmp/mysql/data/mysql.sock

1159 ; Default socket name for local MySQL connects.  If empty, uses the built-in
1160 ; MySQL defaults.
1161 ; http://php.net/mysql.default-socket
1162 mysql.default_socket = /usr/local/lnmp/mysql/data/mysql.sock

1218 ; Default socket name for local MySQL connects.  If empty, uses the built-in
1219 ; MySQL defaults.
1220 ; http://php.net/mysqli.default-socket
1221 mysqli.default_socket = /usr/local/lnmp/mysql/data/mysql.sock

 未完。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值