NGINX安装与简单的压力测试
安装编译器及相关的工具
[root@localhost softs]# yum install gcc gcc-c++ autoconf automake -y
模块依赖性:nginx的一些模块需要第三方库的支持,gzip需要libzip库,rewrite需要pcre库,ssl需要libssl库等,可以使用yum安装来解决这些依赖库。
[root@localhost ~]# yum install zlib zlib-devel openssl openssl-devel pcre pcre-devel -y
===========>安装过程所需的一些开发包和支持包
安装pcre-8.33.tar.gz ======> perl语言兼容正则表达式
[root@localhost pcre-8.33]# ./configure --enable-utf8 --enable-rebuild-chartables --enable-newline-is-any --enable-pcregrep-libz && make && make install
安装nginx
[root@localhost nginx-1.5.6]# yum install gd gd-devel libxml2 libxml2-devel
===========>安装gd,libxml库与开发包
[root@localhost nginx-1.5.6]# ./configure --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx/nginx.pid --user=nginx --group=nginx --with-rtsig_module --with-select_module --with-poll_module --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_sub_module --with-http_dav_module --with-http_gzip_static_module --with-http_flv_module --with-http_perl_module --with-perl=/usr/bin/perl --http-log-path=/var/log/nginx/access.log --with-pcre --with-pcre=/usr/src/lnmp/pcre-8.33/ --with-http_stub_status_module
[root@localhost nginx-1.5.6]# make
[root@localhost nginx-1.5.6]# make install
修改nginx的配置文件
[root@localhost nginx-1.5.6]# vi /usr/local/nginx/conf/nginx.conf
user nginx; ####指定nginx的默认用户
worker_processes 1;####启动进程,通常设置成和cpu的数量相等
error_log /var/log/nginx/error.log; ####nginx的错误日志存放目录
#error_log logs/error.log notice;
error_log /var/log/nginx/error.log info; ####nginx的错误日志级别设置
pid /var/run/nginx/nginx.pid;####nginx运行进程pid
events {
worker_connections 1024; #####单个后台worker process进程的最大并发链接数
}
http {
include mime.types; #######设定mime类型,类型由mime.type文件定义
default_type application/octet-stream;
###MIME类型就是设定某种扩展名的文件用一种应用程序来打开的方式类型,当该扩展名文件被访问的时候,浏览器会自动使用指定应用程序来打开
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"';
=========>指定日志的格式
access_log /var/log/nginx/access.log main; ###日志目录
sendfile on; ####sendfile 指令指定 nginx 是否调用 sendfile 函数(zero copy 方式)来输出文件,对于普通应用,必须设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置为 off,以平衡磁盘与网络I/O处理速度,降低系统的uptime.
gzip on; #####开启zip压缩
server {
listen 80;
server_name localhost;
root /www; ####DocumentRoot
index index.html index.htm index.php; ####支持的索引类型
charset gb2312;####支持的语言
location / { try_files $uri $uri/ /index.php;
}
####按顺序检查文件是否存在,返回第一个找到的文件。结尾的斜线表示为文件夹 -$uri/。如果所有的文件都找不到,会进行一个内部重定向到最后一个参数
location ~ /.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
include fastcgi.conf;
}
}
[root@localhost conf]# mkdir /www ####创建相应的目录
[root@localhost conf]# chown nginx.nginx /www/ ####改属组和属主
[root@localhost ~]# mv /usr/local/nginx/html/* /www ###将nginx默认的index.html移动到自己指定的目录也可自己建
[root@localhost html]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf #####启动nginx
浏览器访问127.0.0.1
http://127.0.0.1/index.html
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer tonginx.org.
Commercial support is available at nginx.com.
Thank you for using nginx.
php安装[root@localhost php-5.5.5]# ./configure --prefix=/usr/local/php --enable-fastcgi --enable-fpm --with-mcrypt --with-zlib --enable-mbstring --disable-pdo --with-curl --disable-debug --enable-pic --disable-rpath --enable-inline-optimization --with-bz2 --with-xml --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable mbregex --with-mhash --enable-xslt --enable-memcache --enable-zip --with-pcre-regex --with-mysql --enable-gd --enable-opcache=no
make
make install
mariadb-5.5.33a.tar.gz的安装
创建mariadb用户组
[root@localhost mariadb-5.5.33a]# groupadd mariadb
[root@localhost mariadb-5.5.33a]# useradd -s /sbin/nologin -g mariadb mariadb
安装cmake
解压cmake-2.8.11.2.tar.gz后依次执行 ./bootstrap; make; make install
下载安装mariadb
[root@localhost soft]# wget http://mirrors.scie.in/mariadb/mariadb-5.5.33a/kvm-tarbake-jaunty-x86/mariadb-5.5.33a.tar.gz
[root@localhost soft]# ls
mariadb-5.5.33a.tar.gz
[root@localhost soft]# tar xf mariadb-5.5.33a.tar.gz -C /usr/src/lnmp
[root@localhost soft]# yum install bison gcc* ncurses* -y
[root@localhost mariadb-5.5.33a]# mkdir /mariadb /var/run/maria
[root@localhost mariadb-5.5.33a]# chown -R mariadb.mariadb /mariadb /var/run/maria
[root@localhost mariadb-5.5.33a]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/maria -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_DEBUG=0 -DBUILD_CONFIG=mysql_release -DFEATURE_SET=community -DWITH_EMBEDDED_SERVER=OFF -DMYSQL_UNIX_ADDR=/var/run/maria/mysql.sock -DMYSQL_DATADIR=/mariadb
[root@localhost mariadb-5.5.33a]# make && make install
[root@localhost log]# /usr/local/maria/scripts/mysql_install_db --user=mariadb --basedir=/usr/local/maria --datadir=/mariadb
Installing MariaDB/MySQL system tables in '/mariadb' ...
OK
Filling help tables...
OK
初始化数据库成功
yum install mysql -y ##安装mysql客户端
cp /usr/local/maria/scripts/support-files/mysql.server /etc/init.d/maria
service maria start
php安装
[root@localhost softs]# wget http://ar2.php.net/distributions/php-5.3.27.tar.bz2
[root@localhost softs]# tar xf php-5.3.27.tar.bz2 -C /usr/src/lnmp
[root@localhost softs]# cd /usr/src/lnmp
[root@localhost php-5.3.27]# ./configure --disable-ipv6 --with-libxml-dir=/usr --with-openssl=/usr --with-pcre-regex=/usr/local --with-zlib=/usr --with-bz2=/usr --enable-calendar --with-curl=/usr --with-pcre-dir=/usr/local --enable-ftp --with-openssl-dir=/usr --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-zlib-dir=/usr/local --with-xpm-dir=/usr --with-freetype-dir=/usr/local --enable-gd-native-ttf --enable-gd-jis-conv --with-mhash=/usr/local --enable-mbstring --with-mcrypt=/usr/local --with-mysql=/usr/local/maria --with-mysql-sock=/var/run/maria/maria.sock --with-mysqli=/usr/local/maria/bin/mysql_config --with-snmp=/usr --enable-sockets --enable-zip --enable-fpm
[root@localhost softs]# make && make install
[root@localhost conf]# cd /usr/local/php/etc/
[root@localhost etc]# ls
pear.conf php-fpm.conf.default
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf
[root@localhost etc]# vi /usr/local/webserver/php/etc/php-fpm.conf
去掉以下四行的注释,并自己修改值:
pm.max_children = 20
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 20
启动php
[root@localhost etc]# /usr/local/php/sbin/php-fpm
查看一下nginx.conf的配置,然后启动nginx
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log;
#error_log logs/error.log notice;
error_log /var/log/nginx/error.log info;
pid /var/run/nginx/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
server {
listen 80;
server_name localhost;
root /www;
index index.html index.htm index.php;
charset gb2312;
access_log /var/log/nginx/access.log main;
location / {
try_files $uri $uri/ /index.php;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ /.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ /.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
include fastcgi.conf;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ //.ht {
# deny all;
#}
}
[root@localhost etc]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
[root@localhost etc]# lsof -i:80
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
nginx 3411 root 6u IPv4 342798 TCP *:http (LISTEN)
nginx 3412 nginx 6u IPv4 342798 TCP *:http (LISTEN)
######################
webbench最多可以模拟3万个并发连接去测试网站的负载能力
下载webbench-1.5.tar.bz2
[root@localhost softs]# tar xf webbench-1.5.tar.bz2
[root@localhost softs]# cd webbench-1.5/
[root@localhost softs]# make && make install
压力测试
[root@localhost www]# webbench -c 3000 -t 10 http://127.0.0.1/index.html
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.
Benchmarking: GET http://127.0.0.1/index.html
3000 clients, running 10 sec.
Speed=1726008 pages/min, 24739128 bytes/sec.
Requests: 287665 susceed, 3 failed.
------------------------------------------------------------------------------
[root@localhost www]# webbench -c 3000 -t 10 http://127.0.0.1/1.jpg
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.
Benchmarking: GET http://127.0.0.1/1.jpg
3000 clients, running 10 sec.
Speed=1670262 pages/min, -212381851 bytes/sec.
Requests: 278376 susceed, 1 failed.
- 07-30如何用u盘重装win10系统
- 07-30bios设置u盘启动
- 07-30技嘉主板bios如何设置u盘启动项
- 12-22开源视频平台:MediaCore(MediaDrop)
- 12-22JVMjavacore和heapdump文件生成选项
- 12-22使用飞信机器人发短信需要开放的端口
- 12-22TCP连接的三次握手--一次故障记录
- 12-22磁盘管理之一 逻辑卷管理
- 01-11全球最受赞誉公司揭晓:苹果连续九年第一
- 12-09罗伯特·莫里斯:让黑客真正变黑
- 12-09谁闯入了中国网络?揭秘美国绝密黑客小组TA
- 12-09警示:iOS6 惊现“闪退”BUG
- 12-05亚马逊推出新一代基础模型 任意模态生成大模
- 12-05OpenAI拓展欧洲业务 将在苏黎世设立办公室
- 12-05微软质疑美国联邦贸易委员会泄露信息 督促其
- 12-05联交所取消宝宝树上市地位 宝宝树:不会对公
- 12-04企业微信致歉:文档打开异常已完成修复