nginx news
http://nginx.org/
作用:实现伪静态的功能
yum install pcre pcre-devel -y
yum install gcc gcc-devel -y yum install openssl openssl-devel -y
wget -q http://nginx.org/download/nginx-1.6.3.tar.gz
参数:-q 下载不提示。
tar xf nginx-1.6.3.tar.gz cd nginx-1.6.3
yum list |grep nginx 或yum list *nginx*
useradd www -s /sbin/nologin -M
./configure --user=www --group=www --prefix=/application/nginx-1.6.3/ --with-http_stub_status_module --with-http_ssl_module
echo $? #返回值为0 则正确
make make install
ln -s /application/nginx-1.6.3/ /application/nginx
[root@web01 conf]# /application/nginx/sbin/nginx -t nginx: the configuration file /application/nginx-1.6.3//conf/nginx.conf syntax is ok nginx: configuration file /application/nginx-1.6.3//conf/nginx.conf test is successful
/application/nginx/sbin/nginx
netstat -lntup|grep 80 lsof -i :80
windows下连接输入http://10.0.0.8
linux下可以用 wget 127.0.0.1显示200K就是正常的。
[root@web01 conf]# wget 127.0.0.1 --2016-08-26 03:28:39-- http://127.0.0.1/ Connecting to 127.0.0.1:80... connected. HTTP request sent, awaiting response... 200 OK Length: 4 [text/html] Saving to: “index.html” 100%[======================================>] 4 --.-K/s in 0s 2016-08-26 03:28:39 (630 KB/s) - “index.html” saved [4/4]
[root@web01 ~]# ls /application/ nginx nginx-1.6.3 [root@web01 ~]# /application/nginx/sbin/nginx -V nginx version: nginx/1.6.3 built by gcc 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC) TLS SNI support enabled configure arguments: --user=www --group=www --prefix=/application/nginx-1.6.3/ --with-http_stub_status_module --with-http_ssl_module
cat /application/nginx/logs/error.log
egrep -v "^$|#" nginx.conf.default >nginx.conf
[root@web01 conf]# vim nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; #可改的监听端口 server_name www.chrishg.net; #可改为的域名 autoindex on; #允许客户端浏览我的目录 location / { root html/www; #对应的目录 index index.html index.htm; } }
添加虚拟主机在http{ } 模块里增加下面代码:多虚拟主机就添加多组以下内容。
server { listen 80; server_name bbs.chrishg.net; location / { root html/bbs; index index.html index.htm;
server { listen 10.0.0.102:80; server_name bbs.chrishg.net; location / { root html/bbs; index index.html index.htm;
server { listen 10.0.0.102:80; server_name bbs.chrishg.net chrishg.net; location / { root html/bbs; index index.html index.htm;
##status server { listen 80; server_name status.chrishg.net; location / { stub_status on; access_log off; } }
添加后,打开网页会显示如下:
Active connections: 2 #活动的连接 server accepts handled requests 4 4 17 # Reading: 0 Writing: 1 Waiting: 1 #
/application/nginx/sbin/nginx -t
/application/nginx/sbin/nginx
/application/nginx/sbin/nginx -s reload
/application/nginx/sbin/nginx -s stop
在企业运维实践场中,每一个配置操作处理完毕后都应该进行快速有效的检查,这是一个合格运维人员的良好习惯。尽量使得在Nginx启动的同时,还会调用脚本通过获取header信息或模拟用户访问指定URL(wget等方式)来自动检查Nginx是否正常,最大限度的保证服务重启后,能迅速确定网站情况,而无须手工敲命令查看。这样如果配置有问题就可以迅速使用上一版本备份配置文件覆盖回来。
[root@localhost conf]# cat check_url.sh
#!/bin/bash
#author:chenfu 2017-10-22 QQ532088799
#--------function split--------
. /etc/rc.d/init.d/functions
function checkURL()
{
checkUrl=$1
echo 'check url start ...'
judge=($(curl -I -s --connect-timeout 2 ${checkUrl}|head -1 | tr " " "\n"))
if [[ "${judge[1]}" == '200' && "${judge[2]}" == 'OK' ]]
then
action "${checkUrl}" /bin/true
else
action "${checkUrl}" /bin/false
echo -n "retrying again...";sleep 3;
judgeagain=($(curl -I -s --connect-timeout 2 ${checkUrl}| head -1| tr "\r" "\n"))
if [[ "${judgeagain[1]}" == '200' && "${judgeagain[2]}" == 'OK' ]]
then
action "${chekcUrl}, retried again" /bin/true
else
action "${chekcUrl}, retried again" /bin/false
fi
fi
sleep 1;
}
# usage method
checkURL http://www.etiantian.org
Active connections: 1 #Nginx正处理的活动连接数有1个
server accepts handled requests #第一个server表示Nginx启动到现在共处理20个连接
#第二个accepts表示Nginx启动到现在共成功创建20次握 #手
#第三个handled requests表示共处理了23次请求
20 20 23
Reading: 0 Writing: 1 Waiting: 0 #Reading为Nginx读取到客户端的Header信息数
#Writing为Nginx返回给客户端的Header数
#Waiting为Nginx已经处理完正等候下一次请求指令的驻 #留连接。在开启keepalive的情况下
#这个值等于active-(reading+writing)
日志记录属于核心功能模块(ngx_core_module)的参数,该参数名字是error.log,针对自己来说最好定义在Main全局区块中,当然也可以放置不同的虚拟主机中单独记录。
error_log file level[debug|info|notice|warn|error|crit|alert|emerg];
关键字 日志文件 错误日志级别
error_log默认配置:
#default:error_log logs/error.log error;
可以放置的标签段:
#context:main,http,server,location
此功能由ngx_http_log_module模块负责
控制日志的参数参数 | 说明 |
log_format | 用来定义记录日志的格式(可以定义多种日志格式,取不同的名字即可) |
access_log | 用来指定日志文件的路径及使用何种日志格式记录日志 |
Nginx日志变量 | 说明 |
$remote_addr | 记录访问网站的客户端地址 |
$http_x_forwarded_for | 当前端有代理服务器时,设置Web节点记录客户端地址的配置,此参数生效的前提是代理服务器上也进行了相关的x_forwarded_for设置 |
$remote_user | 远程客户端名称 |
$time_local | 记录访问时间与时区 |
$request | 用户的http请求起始行信息 |
$status | http状态码,记录请求返回的状态,例如200,404,301 |
$body_bytes_sents | 服务器发送给客户端的响应body字节数 |
$http_referer | 记录此次请求是从哪个链接访问过来的,可以根据referer进行防盗链设置 |
$http_user_agent | 记录客户端访问信息,例如浏览器手机客户端等 |
buffer=size #存放访问日志的缓冲区大小
flush=time #将缓冲区的日志刷到磁盘的时间
gzip[=level] #表示压缩级别
[if=condition] #表示其他条件(一般的场景中这些都无需配置,极端优化 #时才可能会考虑这些参数)
默认的配置:
access_log logs/access.log combined;
日志内容配置:
log_format main '$remote_addr - $remote_user [$time_local] "$request"'
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
[root@localhost nginx]# cat /server/script/cut_nginx_log.sh
#!/bin/bash
Dateformat=`date +%Y%m%d`
Basedir="/application/nginx"
Nginxlogdir="$Basedir/logs"
Logname="access_www"
[ -d $Nginxlogdir ] && cd $Nginxlogdir || exit 1
[ -f ${Logname}.log ] || exit 1
/bin/mv ${Logname}.log ${Dateformat}_${Logname}.log
$Basedir/sbin/nginx -s reload
Nginx常用的日志收集分析工具有rsyslog、awstats、flume、ELK、storm等
wget -q http://mirrors.utc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm rpm -ivh epel-release-6-8.narch.rpm yum install nginx
亿级PV超大型网站集群架构图形化深度揭秘讲解 - CSDN学院 - CSDN.NET
http://edu.csdn.net/course/detail/2278
官方地址:http://dev.mysql.com/downloads/mysql/5.5.html#downloads
cd /home/oldboy/tools wget http://cdn.mysql.com/archives/mysql-5.5/mysql-5.5.49-linux2.6-x86_64.tar.gz
cd /home/oldboy/tools tar xf mysql-5.5.49-linux2.6-x86_64.tar.gz mv mysql-5.5.49-linux2.6-x86_64 /application/mysql-5.5.49 ln -s /application/mysql-5.5.49 /application/mysql ls /application/
mkdir /application/ useradd -s /sbin/nologin mysql -M id mysql
chown -R mysql.mysql /application/mysql/data/
cd /application/mysql/ ./scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data/ --user=mysql ll data/
在cat /etc/hosts 文件里添加解释:
172.16.1.8 web01
\cp support-files/my-small.cnf /etc/my.cnf cp support-files/mysql.server /etc/init.d/mysqld sed -i 's#/usr/local/#/application/#g' /application/mysql/bin/mysqld_safe /etc/init.d/mysqld chmod +x /etc/init.d/mysqld
/application/mysql/bin/mysqld_safe --user=mysql & lsof -i :3306 netstat -lntup |grep 3306
[root@web01 bin]# /application/mysql/bin/mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.5.49 MySQL Community Server (GPL) 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> #这样代表成功安装了
PATH="/application/mysql/bin/:$PATH" [root@web01 bin]# echo $PATH /application/mysql/bin/:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin [root@web01 bin]# which mysql /application/mysql/bin/mysql 编辑vim /etc/profile 添加PATH="/application/mysql/bin/:$PATH" 到最后,实现环境变量永久生效 . /etc/profile #添加完后重读配置文件。
/etc/init.d/mysqld stop /etc/init.d/mysqld start /etc/init.d/mysqld restart chkconfig --add mysqld chkconfig --list mysql chkconfig mysql on
/application/mysql/data/ 机器名.err 如: cat /application/mysql/data/web01.err
[root@web01 mysql]# ls -ld /tmp drwxrwxrwt. 4 root root 4096 Aug 30 01:22 /tmp
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
上面问题有3种可能原因及其解决方法如下:
1、删除并重新初始化数据库,出现此问题一般都是因为数据库初始货有问题,
2、或者是MySQL数据文件损坏了,也可能是MySQL数据目录权限有问题。
3、检查主机名对应主机IP解析是否正确。
MySQL安装完成后,默认情况下,管理员账号root是无密码的,这个必须设置。
show databases; #查看当前所有数据库 select user(); #查看当前的登录用户
mysqladmin -uroot password "oldboy123" #设置密码 mysql -uroot -poldboy123 #用密码登陆 mysqladmin -uroot -poldboy123 password 123456 #改密码
history -c #清空全部历史记录 history -d 1024 #清除第1024条历史记录
show databases; 查看所有数据库
ls -ld /application/mysql/ ls -ld /application/nginx
[root@web01 ~]# netstat -lntup |egrep "3306|80" tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 51971/mysqld tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 50047/nginx
wget 127.0.0.1 mysql -uroot -p
rpm -qa zlib-devel libxm12-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel freetype-devel libping-devel gd-devel libcurl-devel libxslt-devel
yum install -y zlib-devel libxm12-devel libjpeg-devel libjpeg-turbo-devel libiconv-devel freetype-devel libping-devel gd-devel libcurl-devel libxslt-devel
cd /home/oldboy/tools wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz tar -zxvf libiconv-1.14.tar.gz cd libiconv-1.14 ./configure --prefix=/usr/local/libiconv make make install cd ../
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo yum install libmcrypt-devel -y
yum install -y mhash mcrypt
cd /home/oldboy/tools wget http://mirrors.sohu.com/php/php-5.5.32.tar.gz tar xf php-5.5.32.tar.gz cd php-5.5.32 #配置参数 ./configure --prefix=/application/php-5.5.32 --with-mysql=/application/mysql/ --with-pdo-mysql=mysqlnd --with-iconv-dir=/usr/local/libiconv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --enable-short-tags --enable-static --with-xsl --with-fpm-user=nginx --with-fpm-group=nginx --enable-ftp --enable-opcache=no echo $?
方法一: (5.3版本有共享库的报错) ln -s /application/mysql/lib/libmysqlclient.so.18 /usr/lib64/ 方法二:找出这个文件将路径添加到 /etc/ld.so.conf find / -name "libmysqlclient.so.18" /application/mysql-5.5.49-linux2.6-x86_64/lib/libmysqlclient.so.18 vim /etc/ld.so.conf 添加内容如下: /application/mysql/lib/ 然后用以下命令保存: ldconfig
touch ext/phar/phar.phar 如果在PHP编译时使用--with-mysql=mysqlnd替代--with-mysql=/application/mysql则没有上述2点的错误发生。 make #说明如果在物理机多核可以用make -j 8 指定核心数 make install
1、设置软链接以方便访问。 ln -s /application/php-5.5.32/ /application/php ls /application/php/ 2、查看PHP配置默认模板文件。 [root@web01 php-5.5.32]# ls -l php.* -rw-r--r-- 1 1001 1001 2523 Feb 2 2016 php.gif -rw-r--r-- 1 1001 1001 69236 Feb 2 2016 php.ini-development -rw-r--r-- 1 1001 1001 69266 Feb 2 2016 php.ini-production 3、拷贝PHP配置文件到PHP默认目录,并更改文件名为php.ini cp php.ini-production /application/php/lib/php.ini ls -l /application/php/lib/php.ini 3.2.4 配置PHP服务(FastCGI方式)的配置文件php-fpm.conf cd /application/php/etc/ cp php-fpm.conf.default php-fpm.conf
/application/php/sbin/php-fpm ps -ef |grep php-fpm lsof -i :9000
Fatal error: Uncaught exception 'BadMethodCallException' with message 'Cannot set any files or directories in magic ".phar" directory' in /home/oldboy/tools/php-5.5.32/ext/phar/phar.php:1173 Stack trace: #0 /home/oldboy/tools/php-5.5.32/ext/phar/phar.php(1173): Phar->offsetSet('.phar', '') #1 /home/oldboy/tools/php-5.5.32/ext/phar/phar.php(1139): PharCommand::phar_add_file(Object(Phar), 0, '.phar', Object(SplFileInfo), NULL, true) #2 /home/oldboy/tools/php-5.5.32/ext/phar/phar.php(1077): PharCommand::phar_add(Object(Phar), 0, '/home/oldboy/to...', NULL, '/\\.svn/', Object(SplFileInfo), NULL, true) #3 [internal function]: PharCommand->cli_cmd_run_pack(Array) #4 /home/oldboy/tools/php-5.5.32/ext/phar/phar.php(225): call_user_func(Array, Array) #5 /home/oldboy/tools/php-5.5.32/ext/phar/phar.php(2089): CLICommand->__construct(19, Array) #6 {main} thrown in /home/oldboy/tools/php-5.5.32/ext/phar/phar.php on line 1173 make: *** [ext/phar/phar.phar] Error 255 原因是上面1.2.2.2在touch ext/phar/phar.phar 时变成了touch ext/phar/phar/.phar 解决: cd ext/phar/phar/ #进入目录中 mv .phar /tmp #删除创建错的文件 touch ext/phar/phar.phar #重新创建文件 make #重新make,这次的时间很短
cd /application/nginx/conf/extra vim blog.conf server { listen 80; server_name blog.chrishg.net; location / { root html/blog; index index.html index.htm; } #添加以下这一段代码 location ~ .*\.(php|php5)?$ { root html/blog; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } } /application/nginx/sbin/nginx -t /application/nginx/sbin/nginx -s reload
cd /application/nginx/html/blog/ echo "<?php phpinfo(); ?>" >test_info.php #添加测试内容注意();这里是分号。 [root@web01 blog]# cat test_info.php <?php phpinfo(); ?> 在网页上打开测试 blog.chrishg.net/test_info.php
cd /application/nginx/html/blog/ 在这个目录里代添测试文件 vim test_mysql.php <?php $link_id=mysql_connect('localhost','root','oldboy123') or mysql_error(); if($link_id){ echo "mysql successful by oldboy !"; }else{ echo mysql_error(); } ?>
blog.chrishg.net/test_mysql.php
mysqladmin -uroot -p123456 password oldboy123
mysql -uroot -poldboy123 #登陆mysql show databases; #显示当前所有库 drop database test; #删除没用的库 show databases; create database wordpress; #创建库 select user(); #查看当前用户 system whoami #在mysql外查看当前用户是谁 select user,host from mysql.user; #查询所有用户 +------+-----------+ | user | host | +------+-----------+ | root | 127.0.0.1 | | root | ::1 | | | localhost | | root | localhost | | | web01 | | root | web01 | +------+-----------+ 6 rows in set (0.00 sec) ********************分隔线***************************** grant all on wordpress.* to wordpress@'localhost' identified by '123456'; 上行geant为授权 ,第一个wordpress为库名,后面的”*“为所有表,第二个wordpress为用户名,@后的localhost为授权登陆的IP 为本地,identified by (身份)后的‘123456’为密码 ----------------------------------------- drop user wordpress@'localhost' #此句为删用户 ---------------------------------------------------------------- select user,host from mysql.user; show grants for wordpress@'localhost'; #查看用户权限 flush privileges; #修改后刷新
cd /application/nginx/conf/extra vim blog.conf 增加下面黄色部份内容 server { listen 80; server_name blog.chrishg.net; location / { root html/blog; index index.php index.html index.htm; } location ~ .*\.(php|php5)?$ { root html/blog; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php;
cd /home/oldboy/tools wget https://cn.wordpress.org/wordpress-4.5.3-zh_CN.tar.gz tar xf wordpress-4.5.3-zh_CN.tar.gz cp -a wordpress/* /application/nginx/html/blog/ chown -R www.www /application/nginx/html/blog/
浏览器输入网址:http://blog.chrishg.net
配置***
mysql -uwordpress -p123456 use wordpress; show tables;
/archives/%post_id%.html
server { listen 80; server_name blog.chrishg.net; root html/blog; index index.php index.html index.htm; location / { if (-f $request_filename/index.html){ rewrite (.*) $1/index.html break; } if (-f $request_filename/index.php){ rewrite (.*) $1/index.php; } if (!-f $request_filename){ rewrite (.*) /index.php; } } location ~ .*\.(php|php5)?$ { root html/blog; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } } 注:以下这行,也可以实现以上多行的功能 try files $url/ /index.php?q=$uri%args;
我们这里的IP地址是:172.16.1.51 db01
#创建用户 useradd -s /sbin/nologin mysql -M #创建目录、解压、授权 cd /home/oldboy/tools tar xf mysql-5.5.49-linux2.6-x86_64.tar.gz mkdir /application/ mv mysql-5.5.49-linux2.6-x86_64 /application/mysql-5.5.49 ln -s /application/mysql-5.5.49 /application/mysql chown -R mysql.mysql /application/mysql/data/ #初始化数据库 cd /application/mysql/ ./scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data/ --user=mysql #复制配置文件 \cp /application/mysql/support-files/my-small.cnf /etc/my.cnf cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld #替换配置路径 sed -i 's#/usr/local/#/application/#g' /application/mysql/bin/mysqld_safe /etc/init.d/mysqld #授权配置文件 chmod +x /etc/init.d/mysqld #配置环境变量 PATH="/application/mysql/bin/:$PATH" echo 'PATH="/application/mysql/bin/:$PATH"' >>/etc/rc.local #启动并查端口 /etc/init.d/mysqld start lsof -i :3306 netstat -lntup |grep 3306
cd /home/oldboy/tools mysqldump -uroot -poldboy123 wordpress -B |gzip>bak.sql.gz scp bak.sql.gz root@10.0.0.51:/tmp
mysqladmin -uroot password oldboy123 cd /tmp gzip -d bak.sql.gz mysql -uroot -poldboy123 </tmp/bak.sql #还原 mysql -uroot -poldboy123 -e "show datablwes like 'wordpress';" #还原后查看 mysql -uroot -poldboy123 #登录数据库 grant all on wordpress.* to wordpress@'172.16.1.%' identified by '123456'; flush privileges; #创建wordpress数据管理员并刷新 select user,host from mysql.user; #查看用户表
cd /application/nginx/html/blog/ vim wp-config.php 修改第32行 sed -i 's#DB_HOST', 'localhost#DB_HOST', '172.16.1.51#g' wp-config.php
use wordpress; show tables; select * from old_posts\G; #文字型式查看表
机器IP:172.16.1.31 nfs01
useradd -u 503 www id www
vim /etc/exports #share /data by oldboy for bingbing at 20160725 /data 172.16.1.0/24(rw,sync,all_squash,anonuid=503,anongid=503) ##指定UID
[root@web01 html]# rpm -qa rpcbind nfs-utils rpcbind-0.2.0-12.el6.x86_64 nfs-utils-1.2.3-70.el6_8.1.x86_64
[root@web01 html]# showmount -e 172.16.1.31 Export list for 172.16.1.31: /backup 172.16.1.0/24 /data 172.16.1.0/24 [root@web01 html]# /etc/init.d/rpcbind status rpcbind (pid 1314) is running...
cd /application/nginx/html/blog/wp-content/uploads mv 2016 /tmp mount -t nfs 172.16.1.31:/data/nfs-blog /application/nginx/html/blog/wp-content/uploads/ echo " mount -t nfs 172.16.1.31:/data/nfs-blog /application/nginx/html/blog/wp-content/uploads/" >> /etc/rc.local cp -a /tmp/2016/ /application/nginx/html/blog/wp-content/uploads
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
长按识别二维码并关注微信
更方便到期提醒、手机管理