lnmp架构(linux+nginx+mysql+php)
架构要点:
linux服务平台
nginx--http服务
mysql--存储
php/perl/python--前端处理语言
架构方式,源码编译,易于满足需求
1.mysql编译
1)编译环境需要
yum install -y gcc gcc-c++ make ncurses-devel bison openssl-devel zlib-devel cmake
2)编译开始
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
#安装目录
-DMYSQL_DATADIR=/usr/local/mysql/data \
#数据库存放目录
-DMYSQL_UNIX_ADDR=/usr/local/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 监听端口
生成makefile文件
make && make install 编译安装
重新编译时,需要清除缓存
rm -rf CMakeCache.txt
此时mysql已经安装好,在/usr/local/mysql
3)服务设置
groupadd -g 27 mysql
useradd -u 27 -g 27 -d /usr/local/mysql -M -s /sbin/nologin mysql
#为mysql服务创建用户
chmod -R mysql.mysql /usr/local/mysql
cd /usr/local/mysql
cp support-files/my-*.cnf /etc/my.cnf #根据自己主机配置,选择配置文件
scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data #数据库配置
chown -R root /usr/local/mysql
chown -R mysql /usr/local/mysql/data
cp support-files/mysql.server /etc/init.d/mysqld
service mysqld start #启动服务
chkconfig mysqld on #开机自启动
echo "export PATH=\$PATH:/usr/local/mysql/bin" >> ~/.bash_profile
source ~/.bash_profile
#将mysql命令添加到环境变量
2.nginx配置
nginx与apache相比有以下优势:在性能上,nginx占用很少的系统资源,能支持更多的并发链接,达到更高的访问率;在功能上,Nginx是优秀的代理服务器和负载均衡器;在安装配置上,简单灵活。
nginx模块基本都是静态编译,同时对Fast-CGI支持比较好.在处理链接上,nginx支持epoll,而且体积小一般只有几百K。
Nginx的优点有以下几点:
1.作为Web服务器,nginx处理静态文件、索引文件以及自动索引效率非常高。
2.作为代理服务器,Nginx可以实现无缓存的反向代理加速,提高网站运行速度。
3.作为负载均衡服务器,Nginx既可以在内部直接支持Rails和PHP,也可以支持HTTP代理服务器,对外进行服务。同时支持简单的容错和利用算法进行负载均衡。
4.在性能方面,Nginx是专门为性能优化而开发的,在实现上非常注重效率。它采用内核Poll模型,可以支持更多的并发连接,最大可以支持对50 000个并发连接数的响应,而且占用很低的内存资源。
5.在稳定性方面,Nginx采取了分阶段资源分配技术,使得对CPU与内存的占用率非常低。Nginx官方表示Nginx保持10 000个没有活动的连接,这些连接只占2.5M内存,因此,类似DOS这样的攻击对Nginx来说基本上是没有任何作用的。
6.在高可用性方面,Nginx支持热部署,启动速度特别迅速,因此可以在不间断服务的情况下,对软件版本或者配置进行升级,即使运行数月也无需重新启动
1)环境准备
nginx源码包,nginx-sticky-module(支持模块)
gcc,gcc-c++
yum install pcre-devel openssl-devel gcc gcc-c++ -y
2)编译
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --add-module=../nginx-sticky-module-1.0
make && make install
ln -s /usr/local/nginx/sbin/nginx /usr/sbin
groupadd -g 48 nginx
useradd -u 48 -g 48 -d /usr/local/nginx
配置文件
/usr/local/nginx/conf/nginx.conf
user nginx;
worker_processes 1; #和cpu个数配置
events {
use epoll;
worker_connections 65535;
}
http {
include
mime.types;
default_type application/octet-stream;
sendfile
on;
tcp_nopush on;
keepalive_timeout 65;
gzip on;
server {
listen
80;
server_name localhost;
location / {
root html;
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
root
html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include
fastcgi.conf;
}
location /status {
stub_status on;
access_log off;
}
}
}
nginx -t 检测语法
nginx #运行
3 php安装
1)编译
yum install -y libxml2-devel curl-devel libjpeg-turbo-devel.x86_64 gmp-devel net-snmp-devel libpng-devel freetype-devel-2.3.11-14.el6_3.1.x86_64
rpm -ivh re2c-0.13.5-1.el6.x86_64.rpm
./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --with-mysql= --with-mysqli= --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --without-pear --with-gettext --with-gmp --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mhash
make && make install
错误:make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1
机器内存小于1G
解决办法:参数加上--disable-fileinfo
2)配置
进入源码包
cd php-5.4.36
cp php.ini-production /usr/local/lnmp/php/etc/php.ini #php
cd sapi/fpm
cp cp init.d.php-fpm /etc/init.d/fpm-php #php 启动脚本
cd /usr/loacl/lnmp/php/etc
cp php-fpm.conf.default php-fpm.conf #重启php,而不启动http服务
更改配置文件
1)vim php-fpm.conf
2)vim php.ini
添加时区
二,lnmp扩展
1.lamp架构
2.lnamp架构 (linux+nginx+apache+mysql+php/jsp)
3.lnammp/lnammj(linux+nginx+tomcat+mysql+php/jsp/asp)
架构要点:
linux服务平台
nginx--http服务
mysql--存储
php/perl/python--前端处理语言
架构方式,源码编译,易于满足需求
1.mysql编译
1)编译环境需要
yum install -y gcc gcc-c++ make ncurses-devel bison openssl-devel zlib-devel cmake
2)编译开始
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
#安装目录
-DMYSQL_DATADIR=/usr/local/mysql/data \
#数据库存放目录
-DMYSQL_UNIX_ADDR=/usr/local/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 监听端口
生成makefile文件
make && make install 编译安装
重新编译时,需要清除缓存
rm -rf CMakeCache.txt
此时mysql已经安装好,在/usr/local/mysql
3)服务设置
groupadd -g 27 mysql
useradd -u 27 -g 27 -d /usr/local/mysql -M -s /sbin/nologin mysql
#为mysql服务创建用户
chmod -R mysql.mysql /usr/local/mysql
cd /usr/local/mysql
cp support-files/my-*.cnf /etc/my.cnf #根据自己主机配置,选择配置文件
scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data #数据库配置
chown -R root /usr/local/mysql
chown -R mysql /usr/local/mysql/data
cp support-files/mysql.server /etc/init.d/mysqld
service mysqld start #启动服务
chkconfig mysqld on #开机自启动
echo "export PATH=\$PATH:/usr/local/mysql/bin" >> ~/.bash_profile
source ~/.bash_profile
#将mysql命令添加到环境变量
2.nginx配置
nginx与apache相比有以下优势:在性能上,nginx占用很少的系统资源,能支持更多的并发链接,达到更高的访问率;在功能上,Nginx是优秀的代理服务器和负载均衡器;在安装配置上,简单灵活。
nginx模块基本都是静态编译,同时对Fast-CGI支持比较好.在处理链接上,nginx支持epoll,而且体积小一般只有几百K。
Nginx的优点有以下几点:
1.作为Web服务器,nginx处理静态文件、索引文件以及自动索引效率非常高。
2.作为代理服务器,Nginx可以实现无缓存的反向代理加速,提高网站运行速度。
3.作为负载均衡服务器,Nginx既可以在内部直接支持Rails和PHP,也可以支持HTTP代理服务器,对外进行服务。同时支持简单的容错和利用算法进行负载均衡。
4.在性能方面,Nginx是专门为性能优化而开发的,在实现上非常注重效率。它采用内核Poll模型,可以支持更多的并发连接,最大可以支持对50 000个并发连接数的响应,而且占用很低的内存资源。
5.在稳定性方面,Nginx采取了分阶段资源分配技术,使得对CPU与内存的占用率非常低。Nginx官方表示Nginx保持10 000个没有活动的连接,这些连接只占2.5M内存,因此,类似DOS这样的攻击对Nginx来说基本上是没有任何作用的。
6.在高可用性方面,Nginx支持热部署,启动速度特别迅速,因此可以在不间断服务的情况下,对软件版本或者配置进行升级,即使运行数月也无需重新启动
1)环境准备
nginx源码包,nginx-sticky-module(支持模块)
gcc,gcc-c++
yum install pcre-devel openssl-devel gcc gcc-c++ -y
2)编译
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --add-module=../nginx-sticky-module-1.0
make && make install
ln -s /usr/local/nginx/sbin/nginx /usr/sbin
groupadd -g 48 nginx
useradd -u 48 -g 48 -d /usr/local/nginx
配置文件
/usr/local/nginx/conf/nginx.conf
user nginx;
worker_processes 1; #和cpu个数配置
events {
use epoll;
worker_connections 65535;
}
http {
include
mime.types;
default_type application/octet-stream;
sendfile
on;
tcp_nopush on;
keepalive_timeout 65;
gzip on;
server {
listen
80;
server_name localhost;
location / {
root html;
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
root
html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include
fastcgi.conf;
}
location /status {
stub_status on;
access_log off;
}
}
}
nginx -t 检测语法
nginx #运行
3 php安装
1)编译
yum install -y libxml2-devel curl-devel libjpeg-turbo-devel.x86_64 gmp-devel net-snmp-devel libpng-devel freetype-devel-2.3.11-14.el6_3.1.x86_64
rpm -ivh re2c-0.13.5-1.el6.x86_64.rpm
./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --with-mysql= --with-mysqli= --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --without-pear --with-gettext --with-gmp --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mhash
make && make install
错误:make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1
机器内存小于1G
解决办法:参数加上--disable-fileinfo
2)配置
进入源码包
cd php-5.4.36
cp php.ini-production /usr/local/lnmp/php/etc/php.ini #php
cd sapi/fpm
cp cp init.d.php-fpm /etc/init.d/fpm-php #php 启动脚本
cd /usr/loacl/lnmp/php/etc
cp php-fpm.conf.default php-fpm.conf #重启php,而不启动http服务
更改配置文件
1)vim php-fpm.conf
2)vim php.ini
添加时区
二,lnmp扩展
1.lamp架构
2.lnamp架构 (linux+nginx+apache+mysql+php/jsp)
3.lnammp/lnammj(linux+nginx+tomcat+mysql+php/jsp/asp)