s28 LNMP架构服务搭建
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                s28 LNMP架构服务搭建
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                nginx-location使用
location語法
location使用的語法例子為:location [=|~|~*|^~] uri{對location語法列表說明。|1ocation | [=|~|~*|^~] |uri |{..}.|指令 |匹配標識。 |匹配的網站網址。|匹配URI后要執行的配置段。上述語法中的URI部分是關鍵,這個URI可以是普通的字符串地址路徑或者是正則表達式,當匹配成功則執行后面大括號里面的相關指令。正則表達式的前面還可以有~或~*等特殊的字符。這兩種特殊字符~或~*匹配的區別為:“ ~ ” 用于區分天小寫(大小寫敏感)的匹配;~/images{}“ ~* ” 用于不區分大小寫的匹配。還可以用邏輯操作符!對上面的匹配取反,即 !~ 和!~* 。“ ^~ ” 作用是在常規的字符串匹配檢查之后,不做正則表達式的檢查,即如果最明確的那個字符
實現配置
[root@www extra]# cat www.confserver {listen       80;server_name  www.etiantian.org etiantian.org;root   html/www;location / {return 401;}location = / {return 402;}location /documents/ {return 403;}location ^~ /images/ {return 404;}location ~* \.(gif|jpg|jpeg)$ {return 500;}access_log logs/access_www.log main ;}x1[root@www extra]# cat www.conf2 ?  server {3 ? ? ?  listen ? ? ? 80;4 ? ? ?  server_name  www.etiantian.org etiantian.org;5 ? ? ?  root ? html/www;6 ? ? ? 7 ? ? ?  location / {8 ? ? ? ? ? return 401;9 ? ? ?  }10 ? ? ?  location = / {11 ? ? ? ? ?  return 402;12 ? ? ?  }1314 ? ? ?  location /documents/ {15 ? ? ? ? ?  return 403;16 ? ? ?  }17 ? ? ?  location ^~ /images/ {18 ? ? ? ? ?  return 404;19 20 ? ? ?  }21 22 ? ? ?  location ~* \.(gif|jpg|jpeg)$ {23 ? ? ? ? ?  return 500;24 ? ? ?  }25 ? ? ?  access_log logs/access_www.log main ;26 ?  }測試
111測試結果截圖小結
不用URI及特殊字符組合匹配順序? ? 匹配說明第一名:“location? = / {”? ? 精確匹配/第二名:“location? ^~ /images/ {”? ?? 匹配常規字符串,不做正則匹配檢查, 優先匹配路徑第三名:“location? ~* \.(gif|jpg|jpeg)$ {”? ?? 正則匹配第四名:“location? /documents/ {”? ?? 匹配常規字符串,如果有正則則優先匹配正則。第五名:“location? / {”? ?? 所有location都不能匹配后的默認匹配。nginx-rewrite短域名跳轉
lewen.com ====>www.lewen.comlewen.com 變換為 www.lewen.comserver {listen? ? ?? 80;server_name? lewen.com;rewrite ^/(.*) http://www.lewen.com/$1 permanent;}lewen.com/index.html? ? ====?? www.lewen.com/index.htmlrewrite配置
[root@web01 extra]# cat www.confserver {listen 80;server_name etiantian.org;rewrite (^.*) http://www.etiantian.org/$1 permanent;}server {listen 80;server_name www.etiantian.org ;access_log logs/access_www.log main;location / {root html/www;index index.html index.htm;}}15151[root@web01 extra]# cat www.conf2 ? server {3 ? ? ? listen 80;4 ? ? ? server_name etiantian.org;5 ? ? ? rewrite (^.*) ? http://www.etiantian.org/$1 permanent;6 ? }7 ? server {8 ? ? ? listen ? ? ? 80;9 ? ? ? server_name www.etiantian.org ;10 ? ? ? access_log logs/access_www.log main;11 ? ? ? location / {12 ? ? ? ? ? root ? html/www;13 ? ? ? ? ? index index.html index.htm;14 ? ? ? }15 ? }測試
[root@web01 extra]# curl -L etiantian.org/index.html web01 www.etiantian.org [root@web01 extra]# curl -Lv 、 * About to connect() to etiantian.org port 80 (#0) * Trying 10.0.0.8... connected * Connected to etiantian.org (10.0.0.8) port 80 (#0) > GET /index.html HTTP/1.1 > User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.21 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2 > Host: etiantian.org > Accept: */* > < HTTP/1.1 301 Moved Permanently < Server: nginx/1.12.2 < Date: Tue, 27 Feb 2018 12:31:27 GMT < Content-Type: text/html < Content-Length: 185 < Connection: keep-alive < Location: http://www.etiantian.org//index.html < * Ignoring the response-body * Connection #0 to host etiantian.org left intact * Issue another request to this URL: 'http://www.etiantian.org//index.html' * About to connect() to www.etiantian.org port 80 (#1) * Trying 10.0.0.8... connected * Connected to www.etiantian.org (10.0.0.8) port 80 (#1) > GET //index.html HTTP/1.1 > User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.21 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2 > Host: www.etiantian.org > Accept: */* > < HTTP/1.1 200 OK < Server: nginx/1.12.2 < Date: Tue, 27 Feb 2018 12:31:27 GMT < Content-Type: text/html < Content-Length: 24 < Last-Modified: Mon, 12 Feb 2018 18:11:30 GMT < Connection: keep-alive < ETag: "5a81d8d2-18" < Accept-Ranges: bytes < web01 www.etiantian.org * Connection #1 to host www.etiantian.org left intact * Closing connection #0 * Closing connection #44441[root@web01 extra]# curl -L etiantian.org/index.html2web01 www.etiantian.org3[root@web01 extra]# curl -Lv 、4* About to connect() to etiantian.org port 80 (#0)5* ? Trying 10.0.0.8... connected6* Connected to etiantian.org (10.0.0.8) port 80 (#0)7> GET /index.html HTTP/1.18> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.21 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.29> Host: etiantian.org10> Accept: */*11>12< HTTP/1.1 301 Moved Permanently13< Server: nginx/1.12.214< Date: Tue, 27 Feb 2018 12:31:27 GMT15< Content-Type: text/html16< Content-Length: 18517< Connection: keep-alive18< Location: http://www.etiantian.org//index.html19<20* Ignoring the response-body21* Connection #0 to host etiantian.org left intact22* Issue another request to this URL: 'http://www.etiantian.org//index.html'23* About to connect() to www.etiantian.org port 80 (#1)24* ? Trying 10.0.0.8... connected25* Connected to www.etiantian.org (10.0.0.8) port 80 (#1)26> GET //index.html HTTP/1.127> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.21 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.228> Host: www.etiantian.org29> Accept: */*30>31< HTTP/1.1 200 OK32< Server: nginx/1.12.233< Date: Tue, 27 Feb 2018 12:31:27 GMT34< Content-Type: text/html35< Content-Length: 2436< Last-Modified: Mon, 12 Feb 2018 18:11:30 GMT37< Connection: keep-alive38< ETag: "5a81d8d2-18"39< Accept-Ranges: bytes40<41web01 www.etiantian.org42* Connection #1 to host www.etiantian.org left intact43* Closing connection #044* Closing connection #Http狀態碼301和302概念簡單區別及企業應用案例http://oldboy.blog.51cto.com/2561410/1774260?測試其他網站[root@web01 extra]# curl -I jd.com baidu.com taobao.com HTTP/1.1 302 Moved Temporarily Server: JengineD/1.7.2.1 Date: Tue, 27 Feb 2018 12:37:26 GMT Content-Type: text/html Content-Length: 165 Location: http://www.jd.com Connection: keep-aliveHTTP/1.1 200 OK Date: Tue, 27 Feb 2018 12:37:27 GMT Server: Apache Last-Modified: Tue, 12 Jan 2010 13:48:00 GMT ETag: "51-47cf7e6ee8400" Accept-Ranges: bytes Content-Length: 81 Cache-Control: max-age=86400 Expires: Wed, 28 Feb 2018 12:37:27 GMT Connection: Keep-Alive Content-Type: text/htmlHTTP/1.1 302 Found Server: Tengine Date: Tue, 27 Feb 2018 12:37:27 GMT Content-Type: text/html Content-Length: 258 Connection: keep-alive Location: http://www.taobao.com/[root@web01 extra]# curl status.lewen.com Active connections: 1 server accepts handled requests84 84 135 Reading: 0 Writing: 1 Waiting: 034341[root@web01 extra]# curl -I jd.com baidu.com taobao.com2HTTP/1.1 302 Moved Temporarily3Server: JengineD/1.7.2.14Date: Tue, 27 Feb 2018 12:37:26 GMT5Content-Type: text/html6Content-Length: 1657Location: http://www.jd.com8Connection: keep-alive910HTTP/1.1 200 OK11Date: Tue, 27 Feb 2018 12:37:27 GMT12Server: Apache13Last-Modified: Tue, 12 Jan 2010 13:48:00 GMT14ETag: "51-47cf7e6ee8400"15Accept-Ranges: bytes16Content-Length: 8117Cache-Control: max-age=8640018Expires: Wed, 28 Feb 2018 12:37:27 GMT19Connection: Keep-Alive20Content-Type: text/html2122HTTP/1.1 302 Found23Server: Tengine24Date: Tue, 27 Feb 2018 12:37:27 GMT25Content-Type: text/html26Content-Length: 25827Connection: keep-alive28Location: http://www.taobao.com/2930[root@web01 extra]# curl status.lewen.com31Active connections: 132server accepts handled requests33 84 84 13534Reading: 0 Writing: 1 Waiting: 0
Nginx status
##status.conf
server {listen  80;server_name  status.etiantian.org;location / {stub_status on;access_log   off;auth_basic           "closed site";auth_basic_user_file /application/nginx/conf/htpasswd;}}11111##status.conf2server {3 ?  listen  80;4 ?  server_name  status.etiantian.org;5 ?  location / {6 ? ?  stub_status on;7 ? ?  access_log ? off;8 ? ?  auth_basic ? ? ? ? ? "closed site";9 ? ?  auth_basic_user_file /application/nginx/conf/htpasswd;10 ?  }11  }登錄驗證
111[root@web01 extra]# curl -u oldboy status.lewen.com Enter host password for user 'oldboy': <html> <head><title>403 Forbidden</title></head> <body bgcolor="white"> <center><h1>403 Forbidden</h1></center> <hr><center>nginx/1.14.0</center> </body> </html> 10101[root@web01 extra]# curl -u oldboy status.lewen.com2Enter host password for user 'oldboy':3<html>4<head><title>403 Forbidden</title></head>5<body bgcolor="white">6<center><h1>403 Forbidden</h1></center>7<hr><center>nginx/1.14.0</center>8</body>9</html>10一直報錯錯誤日志2018/09/02 19:31:29 [error] 2577#0: *44 open() "/application/nginx-1.14.0//conf/conf/htpasswd" failed (2: No such file or directory), client: 10.0.0.1, server: status.lewen.com, request: "GET / HTTP/1.1", host: "status.lewen.com" 2212018/09/02 19:31:29 [error] 2577#0: *44 open() "/application/nginx-1.14.0//conf/conf/htpasswd" failed (2: No such file or directory), client: 10.0.0.1, server: status.lewen.com, request: "GET / HTTP/1.1", host: "status.lewen.com"2糾正修改配置文件密碼文件的路徑或者直接用絕地路徑[root@web01 extra]# curl -u oldboy:123456 status.lewen.com Active connections: 1 server accepts handled requests46 46 80 Reading: 0 Writing: 1 Waiting: 0 661[root@web01 extra]# curl -u oldboy:123456 status.lewen.com2Active connections: 1 3server accepts handled requests4 46 46 80 5Reading: 0 Writing: 1 Waiting: 0 6本章回顧
?? ? Apache select和Nginx epoll模型區別形象比喻(面試常考);?? ? 虛擬主機概念及類型分類詳解; ?? ? Nginx錯誤及訪問日志及訪問日志切割;?? ? Nginx location介紹及配置實踐;?? ? Nginx Rewrite介紹及配置實踐;?? ? Nginx Web訪問認證介紹及配置實踐。mysql二進制部署
#二進制安裝MySQL-5.6.39https://downloads.mysql.com/archives/community/111安裝報錯1Installing MySQL system tables.../application/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory原因:缺少libaio庫文件 解決方法:yum install libaio* numactl -y 551Installing MySQL system tables.../application/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory234原因:缺少libaio庫文件 5解決方法:yum install libaio* numactl -y 2Installing MySQL system tables.../application/mysql/bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory如果安裝mysql出現了以上的報錯信息.這是卻少numactl這個時候如果是Centos就yum -y install numactl就可以解決這個問題了. 441Installing MySQL system tables.../application/mysql/bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory234如果安裝mysql出現了以上的報錯信息.這是卻少numactl這個時候如果是Centos就yum -y install numactl就可以解決這個問題了. #####To start mysqld at boot time you have to copy #####support-files/mysql.server to the right place for your system #####mysql啟動腳本 默認放在support-files/mysql.server ##### #####記得給MySQL設置個密碼 #####PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! #####To do so, start the server, then issue the following commands: ##### ##### /application/mysql/bin/mysqladmin -u root password 'new-password' ##### /application/mysql/bin/mysqladmin -u root -h web01 password 'new-password'10101#####To start mysqld at boot time you have to copy2#####support-files/mysql.server to the right place for your system3#####mysql啟動腳本 默認放在support-files/mysql.server 4#####5#####記得給MySQL設置個密碼6#####PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !7#####To do so, start the server, then issue the following commands:8#####9##### /application/mysql/bin/mysqladmin -u root ? ? ? ? password 'new-password'10##### /application/mysql/bin/mysqladmin -u root -h web01 password 'new-password'初始化的幫助信息111####7.復制啟動腳本 授權 cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld chmod +x /etc/init.d/mysqld####8.修改啟動腳本 和 mysql命令 中的路徑 sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe /etc/init.d/mysqld####9.復制 默認的配置文件 \cp /application/mysql/support-files/my-default.cnf /etc/my.cnf /etc/init.d/mysqld start[root@web01 ~]# /etc/init.d/mysqld start Starting MySQL.Logging to '/application/mysql/data/web01.err'. . SUCCESS! ####查看[root@web01 ~]# ss -lntup |grep 3306 tcp LISTEN 0 80 :::3306 :::* users:(("mysqld",1898,10))19191####7.復制啟動腳本 授權2cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld3chmod +x /etc/init.d/mysqld45####8.修改啟動腳本 和 mysql命令 中的路徑6sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe /etc/init.d/mysqld78####9.復制 默認的配置文件 ? 9\cp /application/mysql/support-files/my-default.cnf /etc/my.cnf10/etc/init.d/mysqld start1112[root@web01 ~]# /etc/init.d/mysqld start13Starting MySQL.Logging to '/application/mysql/data/web01.err'.14. SUCCESS! 1516####查看1718[root@web01 ~]# ss -lntup |grep 330619tcp ? LISTEN ? ? 0 ? ? ?80 ? ? ? ? ? ? ? ? ? :::3306 ? ? ? ? ? ? ? ? :::* ? ? users:(("mysqld",1898,10))####10.PATH路徑 添加到系統路徑 echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile source /etc/profile which mysql[root@web01 ~]# which mysql /application/mysql/bin/mysql####11.加入開機自啟動 chkconfig --add mysqld chkconfig mysqld on####12.給MySQL root用戶設置密碼 /application/mysql/bin/mysqladmin -u root password 'oldboy123'####13.重新登錄MySQL數據庫 mysql -uroot -poldboy123####14.數據庫基礎框架 #1.數據庫 test mysql #2.表格24241####10.PATH路徑 ? ? ? 添加到系統路徑2echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile3source /etc/profile4which mysql567[root@web01 ~]# which mysql8/application/mysql/bin/mysql9101112####11.加入開機自啟動13chkconfig --add mysqld14chkconfig mysqld on1516####12.給MySQL root用戶設置密碼17/application/mysql/bin/mysqladmin -u root password 'oldboy123'1819####13.重新登錄MySQL數據庫20mysql -uroot -poldboy1232122####14.數據庫基礎框架23#1.數據庫 test mysql24#2.表格注意###故障 ##1./tmp權限 ##2.主機名解析 hosts解析 #ping 主機名 ##3.一步一步執行## ##/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>20201###故障2##1./tmp權限3##2.主機名解析 hosts解析 #ping 主機名4##3.一步一步執行56##7##/application/mysql/bin/mysql8##Welcome to the MySQL monitor. Commands end with ; or \g.9##Your MySQL connection id is 110##Server version: 5.5.49 MySQL Community Server (GPL)11##12##Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.13##14##Oracle is a registered trademark of Oracle Corporation and/or its15##affiliates. Other names may be trademarks of their respective16##owners.17##18##Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.19##20##mysql>mysql SQL語句
#查看系統中所有數據庫#show databases;#查看系統中所有的用戶#使用某一個數據庫mysql> #查看當前都有啥 mysql> show databases; ******** +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.07 sec)11111mysql> #查看當前都有啥2mysql> show databases; ? ? ? ********3+--------------------+4| Database ? ? ? ? ? |5+--------------------+6| information_schema |7| mysql ? ? ? ? ? ? |8| performance_schema |9| test ? ? ? ? ? ? ? |10+--------------------+114 rows in set (0.07 sec)####初級 查看系列-開始 ##使用某一個數據庫 ###相當于進入 mysql 數據庫中 cd mysql ; cd test #use mysql##我想查看當前在哪? pwd 當前正在使用哪個數據庫 select database(); +------------+ | database() | +------------+ | mysql | +------------+ 1 row in set (0.00 sec)##我是誰? 查看當前用戶 select user(); +----------------+ | user() | +----------------+ | root@localhost | +----------------+ 1 row in set (0.00 sec)###當前系統都有什么用戶? 他們可以在哪里登錄? ***** 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.02 sec) ####初級 查看系列-結束 ###show databases; ###select user,host from mysql.user;39391####初級 查看系列-開始2##使用某一個數據庫3###相當于進入 mysql 數據庫中 cd mysql ; cd test4#use mysql56##我想查看當前在哪? pwd ? 當前正在使用哪個數據庫7select database();8+------------+9| database() |10+------------+11| mysql ? ? |12+------------+131 row in set (0.00 sec)1415##我是誰? ? ? ? ? ? 查看當前用戶16select user();17+----------------+18| user() ? ? ? ? |19+----------------+20| root@localhost |21+----------------+221 row in set (0.00 sec)2324###當前系統都有什么用戶? 他們可以在哪里登錄? *****25select user,host from mysql.user;26+------+-----------+27| user | host ? ? |28+------+-----------+29| root | 127.0.0.1 |30| root | ::1 ? ? ? |31| ? ? | localhost |32| root | localhost |33| ? ? | web01 ? ? |34| root | web01 ? ? |35+------+-----------+366 rows in set (0.02 sec)37####初級 查看系列-結束38###show databases;39###select user,host from mysql.user;####初級 添加刪除系列 #創建數據庫 create database wordpress; #刪除數據庫 drop database wordpress;#添加用戶 grant all on wordpress.* to 'wordpress'@'172.16.1.0/255.255.255.0' identified by '123456';grant all on wordpress.* to 'wordpress'@'172.16.1.0/255.255.255.0' identified by '123456'; 授權所有的權限, wordpress數據庫所有的權限 給 wordpress用戶 可以在172.16.1.0/255.255.255.0 網段登錄數據庫 這個用戶的密碼123456;#更新系統的權限表 flush privileges; ###進行測試 mysql -uwordpress -p123456mysql -uwordpress -p -h 172.16.1.8#刪除用戶 drop user wordpress@'172.16.1.8';25251####初級 添加刪除系列2#創建數據庫3create database wordpress;4#刪除數據庫5drop database wordpress;678#添加用戶9grant all on wordpress.* to 'wordpress'@'172.16.1.0/255.255.255.0' identified by '123456';1011grant all on wordpress.* ? ? ? ? ? ? ? ? to 'wordpress'@'172.16.1.0/255.255.255.0' identified by '123456';12授權所有的權限, wordpress數據庫所有的權限 給 wordpress用戶 可以在172.16.1.0/255.255.255.0 網段登錄數據庫 這個用戶的密碼123456;1314#更新系統的權限表15flush privileges; 16171819###進行測試20mysql -uwordpress -p1234562122mysql -uwordpress -p -h 172.16.1.82324#刪除用戶25drop user wordpress@'172.16.1.8';[root@web01 ~]# mysql -uwordpress -p Enter password: ####前面創建用戶時限制了訪問ip 要想本地訪問就得再創建一個 ERROR 1045 (28000): Access denied for user 'wordpress'@'localhost' (using password: YES)####制定ip 登錄 [root@web01 ~]# mysql -uwordpress -h 172.16.1.8 -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 24 Server version: 5.6.41 MySQL Community Server (GPL)Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. 16161[root@web01 ~]# mysql -uwordpress -p2Enter password: 34####前面創建用戶時限制了訪問ip 要想本地訪問就得再創建一個5ERROR 1045 (28000): Access denied for user 'wordpress'@'localhost' (using password: YES)678####制定ip 登錄9[root@web01 ~]# mysql -uwordpress -h 172.16.1.8 -p10Enter password: 11Welcome to the MySQL monitor. Commands end with ; or \g.12Your MySQL connection id is 2413Server version: 5.6.41 MySQL Community Server (GPL)1415Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.16###1.查看都有什么數據庫 ###2.查看都有什么用戶 ###3.添加用戶#help sql語句。#跳過授權表(不用密碼登錄) #/etc/init.d/mysqld restart --skip-grant-table#mysql 命令行 #-u 指定用戶 #-p 指定密碼(不要有空格) #-h 連接到某一臺服務器#更改密碼 mysqladmin -uroot -poldboy123 password '新的密碼'db01上部署一個mysql5.6.3920201###1.查看都有什么數據庫2###2.查看都有什么用戶3###3.添加用戶456#help sql語句。78#跳過授權表(不用密碼登錄)9#/etc/init.d/mysqld restart --skip-grant-table1011#mysql 命令行12#-u 指定用戶13#-p 指定密碼(不要有空格)14#-h 連接到某一臺服務器151617#更改密碼 mysqladmin -uroot -poldboy123 password '新的密碼'181920db01上部署一個mysql5.6.39 yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel curl-devel -yyum install freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel -yrpm -qa zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel curl-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel 331 yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel curl-devel -y2 ? yum install freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel -y3 ? rpm -qa zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel curl-devel freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel ? ?部署php
#解壓PHP軟件,進行編譯安裝,將程序安裝到/application目錄中,并且創建軟鏈接#安裝其它相關程序---libmcrypt ??wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repoyum -y install libmcrypt-devel mhash mcryptrpm -qa libmcrypt-devel mhash mcrypt http://php.net/releases/安裝PHP過程??
####編譯配置tar xf php-5.5.32.tar.gz cd php-5.5.32 #----正式編譯前也可以把這個軟件安裝上(libxslt*)./configure --prefix=/application/php-5.5.32 \ --with-mysql=mysqlnd \ --with-pdo-mysql=mysqlnd \ --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=www \ --with-fpm-group=www \ --enable-ftp \ --enable-opcache=no40401####編譯配置234tar xf php-5.5.32.tar.gz5cd php-5.5.32 ? ? ? ? ? #----正式編譯前也可以把這個軟件安裝上(libxslt*)67./configure --prefix=/application/php-5.5.32 \8--with-mysql=mysqlnd \9--with-pdo-mysql=mysqlnd \10--with-freetype-dir \11--with-jpeg-dir \12--with-png-dir \13--with-zlib \14--with-libxml-dir=/usr \15--enable-xml \16--disable-rpath \17--enable-bcmath \18--enable-shmop \19--enable-sysvsem \20--enable-inline-optimization \21--with-curl \22--enable-mbregex \23--enable-fpm \24--enable-mbstring \25--with-mcrypt \26--with-gd \27--enable-gd-native-ttf \28--with-openssl \29--with-mhash \30--enable-pcntl \31--enable-sockets \32--with-xmlrpc \33--enable-soap \34--enable-short-tags \35--enable-static \36--with-xsl \37--with-fpm-user=www \38--with-fpm-group=www \39--enable-ftp \40--enable-opcache=no編譯過程##提示 如下內容 即成功 Generating files configure: creating ./config.status creating main/internal_functions.c creating main/internal_functions_cli.c +--------------------------------------------------------------------+ | License: | | This software is subject to the PHP License, available in this | | distribution in the file LICENSE. By continuing this installation | | process, you are bound by the terms of this license agreement. | | If you do not agree with the terms of this license, you must abort | | the installation process at this point. | +--------------------------------------------------------------------+Thank you for using PHP.config.status: creating php5.spec config.status: creating main/build-defs.h config.status: creating scripts/phpize config.status: creating scripts/man1/phpize.1 config.status: creating scripts/php-config config.status: creating scripts/man1/php-config.1 config.status: creating sapi/cli/php.1 config.status: creating sapi/fpm/php-fpm.conf config.status: creating sapi/fpm/init.d.php-fpm config.status: creating sapi/fpm/php-fpm.service config.status: creating sapi/fpm/php-fpm.8 config.status: creating sapi/fpm/status.html config.status: creating sapi/cgi/php-cgi.1 config.status: creating ext/phar/phar.1 config.status: creating ext/phar/phar.phar.1 config.status: creating main/php_config.h config.status: executing default commands35351編譯過程23##提示 如下內容 即成功4Generating files5configure: creating ./config.status6creating main/internal_functions.c7creating main/internal_functions_cli.c8+--------------------------------------------------------------------+9| License: ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |10| This software is subject to the PHP License, available in this ? ? |11| distribution in the file LICENSE. By continuing this installation |12| process, you are bound by the terms of this license agreement. ? ? |13| If you do not agree with the terms of this license, you must abort |14| the installation process at this point. ? ? ? ? ? ? ? ? ? ? ? ? ? |15+--------------------------------------------------------------------+1617Thank you for using PHP.1819config.status: creating php5.spec20config.status: creating main/build-defs.h21config.status: creating scripts/phpize22config.status: creating scripts/man1/phpize.123config.status: creating scripts/php-config24config.status: creating scripts/man1/php-config.125config.status: creating sapi/cli/php.126config.status: creating sapi/fpm/php-fpm.conf27config.status: creating sapi/fpm/init.d.php-fpm28config.status: creating sapi/fpm/php-fpm.service29config.status: creating sapi/fpm/php-fpm.830config.status: creating sapi/fpm/status.html31config.status: creating sapi/cgi/php-cgi.132config.status: creating ext/phar/phar.133config.status: creating ext/phar/phar.phar.134config.status: creating main/php_config.h35config.status: executing default commandsln -s /application/mysql/lib/libmysqlclient.so.18? /usr/lib64/? #可以不創建 touch ext/phar/phar.pharmake && make installln -s /application/php-5.5.32/ /application/php安裝過程Generating phar.php Generating phar.phar PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled. clicommand.inc pharcommand.inc invertedregexiterator.inc directorygraphiterator.inc directorytreeiterator.inc phar.incBuild complete.[root@web01 php-5.5.32]# make install Installing PHP CLI binary: /application/php-5.5.32/bin/ Installing PHP CLI man page: /application/php-5.5.32/php/man/man1/ Installing PHP FPM binary: /application/php-5.5.32/sbin/ Installing PHP FPM config: /application/php-5.5.32/etc/ Installing PHP FPM man page: /application/php-5.5.32/php/man/man8/ Installing PHP FPM status page: /application/php-5.5.32/php/php/fpm/ Installing PHP CGI binary: /application/php-5.5.32/bin/ Installing PHP CGI man page: /application/php-5.5.32/php/man/man1/ Installing build environment: /application/php-5.5.32/lib/php/build/ Installing header files: /application/php-5.5.32/include/php/ Installing helper programs: /application/php-5.5.32/bin/program: phpizeprogram: php-config Installing man pages: /application/php-5.5.32/php/man/man1/page: phpize.1page: php-config.1 Installing PEAR environment: /application/php-5.5.32/lib/php/ [PEAR] Archive_Tar - installed: 1.4.0 [PEAR] Console_Getopt - installed: 1.4.1 [PEAR] Structures_Graph- installed: 1.1.1 [PEAR] XML_Util - installed: 1.3.0 [PEAR] PEAR - installed: 1.10.1 Wrote PEAR system config file at: /application/php-5.5.32/etc/pear.conf You may want to add: /application/php-5.5.32/lib/php to your php.ini include_path /home/oldboy/tools/php-5.5.32/build/shtool install -c ext/phar/phar.phar /application/php-5.5.32/bin ln -s -f phar.phar /application/php-5.5.32/bin/phar Installing PDO headers: /application/php-5.5.32/include/php/ext/pdo/ [root@web01 php-5.5.32]# echo $? 044441安裝過程23Generating phar.php4Generating phar.phar5PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.6clicommand.inc7pharcommand.inc8invertedregexiterator.inc9directorygraphiterator.inc10directorytreeiterator.inc11phar.inc1213Build complete.1415[root@web01 php-5.5.32]# make install16Installing PHP CLI binary: ? ? ? /application/php-5.5.32/bin/17Installing PHP CLI man page: ? ? /application/php-5.5.32/php/man/man1/18Installing PHP FPM binary: ? ? ? /application/php-5.5.32/sbin/19Installing PHP FPM config: ? ? ? /application/php-5.5.32/etc/20Installing PHP FPM man page: ? ? /application/php-5.5.32/php/man/man8/21Installing PHP FPM status page: ? ? /application/php-5.5.32/php/php/fpm/22Installing PHP CGI binary: ? ? ? /application/php-5.5.32/bin/23Installing PHP CGI man page: ? ? /application/php-5.5.32/php/man/man1/24Installing build environment: ? ? /application/php-5.5.32/lib/php/build/25Installing header files: ? ? ? ? /application/php-5.5.32/include/php/26Installing helper programs: ? ? ? /application/php-5.5.32/bin/27 program: phpize28 program: php-config29Installing man pages: ? ? ? ? ? ? /application/php-5.5.32/php/man/man1/30 page: phpize.131 page: php-config.132Installing PEAR environment: ? ? /application/php-5.5.32/lib/php/33[PEAR] Archive_Tar ? - installed: 1.4.034[PEAR] Console_Getopt - installed: 1.4.135[PEAR] Structures_Graph- installed: 1.1.136[PEAR] XML_Util ? ? ? - installed: 1.3.037[PEAR] PEAR ? ? ? ? ? - installed: 1.10.138Wrote PEAR system config file at: /application/php-5.5.32/etc/pear.conf39You may want to add: /application/php-5.5.32/lib/php to your php.ini include_path40/home/oldboy/tools/php-5.5.32/build/shtool install -c ext/phar/phar.phar /application/php-5.5.32/bin41ln -s -f phar.phar /application/php-5.5.32/bin/phar42Installing PDO headers: ? ? ? ? /application/php-5.5.32/include/php/ext/pdo/43[root@web01 php-5.5.32]# echo $?440####安裝完#復制php.ini配置文件[root@web01 php-5.5.32]# cp /home/oldboy/tools/php-5.5.32/php.ini-production /application/php-5.5.32/lib/php.ini#復制php-fpm配置文件 [root@web01 php-5.5.32]# cd /application/php-5.5.32/etc/ [root@web01 etc]# ls pear.conf php-fpm.conf.default [root@web01 etc]# cp php-fpm.conf.default php-fpm.conf [root@web01 etc]# ll total 52 -rw-r--r-- 1 root root 1332 Feb 27 22:53 pear.conf -rw-r--r-- 1 root root 22609 Feb 27 22:56 php-fpm.conf -rw-r--r-- 1 root root 22609 Feb 27 22:53 php-fpm.conf.default17171####安裝完23#復制php.ini配置文件45[root@web01 php-5.5.32]# cp /home/oldboy/tools/php-5.5.32/php.ini-production /application/php-5.5.32/lib/php.ini678#復制php-fpm配置文件9[root@web01 php-5.5.32]# cd /application/php-5.5.32/etc/10[root@web01 etc]# ls11pear.conf php-fpm.conf.default12[root@web01 etc]# cp php-fpm.conf.default php-fpm.conf13[root@web01 etc]# ll14total 5215-rw-r--r-- 1 root root ?1332 Feb 27 22:53 pear.conf16-rw-r--r-- 1 root root 22609 Feb 27 22:56 php-fpm.conf17-rw-r--r-- 1 root root 22609 Feb 27 22:53 php-fpm.conf.default#### 啟動[root@web01 etc]# /application/php-5.5.32/sbin/php-fpm -t [27-Feb-2018 22:56:53] NOTICE: configuration file /application/php-5.5.32/etc/php-fpm.conf test is successful[root@web01 etc]# /application/php-5.5.32/sbin/php-fpm [root@web01 etc]# ss -lntup |grep 9000 tcp LISTEN 0 16384 127.0.0.1:9000 *:* users:(("php-fpm",129733,7),("php-fpm",129734,0),("php-fpm",129735,0))####添加到系統命令[root@web01 etc]# ln -s /application/php-5.5.32/sbin/php-fpm /usr/bin/15151#### 啟動23[root@web01 etc]# /application/php-5.5.32/sbin/php-fpm -t4[27-Feb-2018 22:56:53] NOTICE: configuration file /application/php-5.5.32/etc/php-fpm.conf test is successful56[root@web01 etc]# /application/php-5.5.32/sbin/php-fpm7[root@web01 etc]# ss -lntup |grep 90008tcp ? LISTEN ? ? 0 ? ? ?16384 ? ? ? ? ?127.0.0.1:9000 ? ? ? ? ? ? ? ? *:* ? ? users:(("php-fpm",129733,7),("php-fpm",129734,0),("php-fpm",129735,0))910111213####添加到系統命令1415[root@web01 etc]# ln -s /application/php-5.5.32/sbin/php-fpm /usr/bin/LNMP搭建網站前測試。
測試nginx與php配合是否成功php與MySQL配合是否成功部署網站測試nginx與php
server {listen 80;server_name blog.etiantian.org;root html/blog;index index.php index.html index.htm;location ~ .*\.(php|php5)?$ {fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;include fastcgi.conf;} }echo '<?php phpinfo();?>' >/application/nginx/html/blog/test_info.php15151server {2 ? ? ? listen ? ? ? 80;3 ? ? ? server_name blog.etiantian.org;4 ? ? ? ? ? root ? html/blog;5 ? ? ? ? ? index index.php index.html index.htm;6 ? ? ? ? ? location ~ .*\.(php|php5)?$ {7 ? ? ? ? ? fastcgi_pass ? 127.0.0.1:9000;8 ? ? ? ? ? fastcgi_index index.php;9 ? ? ? ? ? include ? ? ? fastcgi.conf;10 ? ? ? }11}12131415echo '<?php phpinfo();?>' >/application/nginx/html/blog/test_info.php測試php與MySQL
test_mysql.php<?php//$link_id=mysql_connect('主機名','用戶','密碼');$link_id=mysql_connect('172.16.1.51','wordpress','123456') or mysql_error();if($link_id){echo "mysql successful by oldboy ! \n";}else{echo mysql_error();} ?>11111test_mysql.php23<?php4 ? ? //$link_id=mysql_connect('主機名','用戶','密碼');5 ? ?$link_id=mysql_connect('172.16.1.51','wordpress','123456') or mysql_error();6 ? ?if($link_id){7 ? ? ? ? echo "mysql successful by oldboy ! \n";8 ? }else{9 ? ? ? ? echo mysql_error();10 ? }11?>部署博客
https://cn.wordpress.org/wordpress-4.9.4-zh_CN.tar.gzchown -R www.www? *root@web01 nginx]# chown -R www.www html/[root@web01 nginx]# ll[root@web01 blog]# rm -f .maintenance111[root@web01 blog]# rm -f .maintenance負載均衡與反向代理
區別圖例
負載均衡 LVS 中小型公司用的不多 ?(配置麻煩)實際部署
HOSTNAME IP 說明 lb01 10.0.0.5 Nginx主負載均衡器 lb02 10.0.0.6 Nginx輔負載均衡器 web01 10.0.0.8 web01服務器 web02 10.0.0.7 web02服務器551HOSTNAME ? IP ? 說明2lb01 ? 10.0.0.5 ? Nginx主負載均衡器3lb02 ? 10.0.0.6 ? Nginx輔負載均衡器4web01 ? 10.0.0.8 ? web01服務器5web02 ? 10.0.0.7 ? web02服務器[root@web01 ~]# /application/nginx/sbin/nginx -Vnginx version: nginx/1.12.2built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC) built with OpenSSL 1.0.1e-fips 11 Feb 2013TLS SNI support enabledconfigure arguments: --user=www --group=www --prefix=/application/nginx-1.12.2 --with-http_stub_status_module --with-http_ssl_module#web01 web02 nginx.conf worker_processes 1; events {worker_connections 1024; } http {include mime.types;default_type application/octet-stream;sendfile on;keepalive_timeout 65;log_format main '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';server {listen 80;server_name www.lewen.com;location / {root html/www;index index.html index.htm;}access_log logs/access_www.log main;}server {listen 80;server_name bbs.lewen.com;location / {root html/bbs;index index.html index.htm;}access_log logs/access_bbs.log main;}}34341#web01 web02 nginx.conf2worker_processes 1;3events {4 ? worker_connections 1024;5}6http {7 ? include ? ? ? mime.types;8 ? default_type application/octet-stream;9 ? sendfile ? ? ? on;10 ? keepalive_timeout 65;1112 ? log_format main '$remote_addr - $remote_user [$time_local] "$request" '13 ? ? ? ? ? ? ? ? ? ? '$status $body_bytes_sent "$http_referer" '14 ? ? ? ? ? ? ? ? ? ? '"$http_user_agent" "$http_x_forwarded_for"';15 ? server {16 ? ? ? listen ? ? ? 80;17 ? ? ? server_name www.lewen.com;18 ? ? ? location / {19 ? ? ? ? ? root ? html/www;20 ? ? ? ? ? index index.html index.htm;21 ? ? ? }22 ? ? ? access_log logs/access_www.log main;23 ? }24 ? server {25 ? ? ? listen ? ? ? 80;26 ? ? ? server_name bbs.lewen.com;27 ? ? ? location / {28 ? ? ? ? ? root ? html/bbs;29 ? ? ? ? ? index index.html index.htm;30 ? ? ? }31 ? ? ? access_log logs/access_bbs.log main;32 ? }3334}tree /application/nginx/html/ -Ld 1for name in www bbs blog ;do echo "`hostname` $name.etiantian.org" > /application/nginx/html/$name/oldboy.html; done[root@web01 ~]# for name in www bbs blog ;do cat /application/nginx/html/$name/oldboy.html; done web01 www.etiantian.org web01 bbs.etiantian.org web01 blog.etiantian.org881tree /application/nginx/html/ -Ld 123for name in www bbs blog ;do echo "`hostname` $name.etiantian.org" > /application/nginx/html/$name/oldboy.html; done4 5[root@web01 ~]# for name in www bbs blog ;do cat /application/nginx/html/$name/oldboy.html; done6web01 www.etiantian.org7web01 bbs.etiantian.org8web01 blog.etiantian.org#web01 web02環境準備完成 [root@lb01 ~]# curl 10.0.0.8/oldboy.html web01 bbs.etiantian.org [root@lb01 ~]# curl 10.0.0.7/oldboy.html web02 bbs.etiantian.org [root@lb01 ~]# curl -H Host:www.etiantian.org 10.0.0.8/oldboy.html web01 www.etiantian.org [root@lb01 ~]# curl -H Host:www.etiantian.org 10.0.0.7/oldboy.html web02 www.etiantian.org991#web01 web02環境準備完成2[root@lb01 ~]# curl 10.0.0.8/oldboy.html3web01 bbs.etiantian.org4[root@lb01 ~]# curl 10.0.0.7/oldboy.html5web02 bbs.etiantian.org6[root@lb01 ~]# curl -H Host:www.etiantian.org 10.0.0.8/oldboy.html7web01 www.etiantian.org8[root@lb01 ~]# curl -H Host:www.etiantian.org 10.0.0.7/oldboy.html9web02 www.etiantian.org下面錯誤的配置#lb01 worker_processes 1; events {worker_connections 1024; } http {include mime.types;default_type application/octet-stream;sendfile on;keepalive_timeout 65;upstream server_pools { server 10.0.0.7:80 weight=1;server 10.0.0.8:80 weight=1;}server { listen 80;server_name www.etiantian.org;location / {proxy_pass http://server_pools;} }22221#lb012worker_processes 1;3events {4 ? worker_connections 1024;5}6http {7 ? include ? ? ? mime.types;8 ? default_type application/octet-stream;9 ? sendfile ? ? ? on;10 ? keepalive_timeout 65;11 ? 12 ? upstream server_pools { 13 ? ? ? ? server 10.0.0.7:80 weight=1;14 ? ? ? ? server 10.0.0.8:80 weight=1;15 ? }16 ? server { 17 ? ? ? listen ? ? ? 80;18 ? ? ? server_name www.etiantian.org;19 ? ? ? location / {20 ? ? ? proxy_pass http://server_pools;21 ? }22}驗證故障: wireshark 進行抓包觀察 [root@lb01 conf]# cat nginx.conf worker_processes 1; events {worker_connections 1024; } http {include mime.types;default_type application/octet-stream;sendfile on;keepalive_timeout 65;upstream server_pools { server 10.0.0.7:80 weight=1;server 10.0.0.8:80 weight=1;}server { listen 80;server_name bbs.lewen.com;location / {proxy_pass http://server_pools;proxy_set_header Host $host;} }server { listen 80;server_name www.lewen.com;location / {proxy_pass http://server_pools;proxy_set_header Host $host;} } }proxy_set_header 修改反向代理 向后面發出請求的時候的 請求頭的信息36361驗證故障:2wireshark 進行抓包觀察3[root@lb01 conf]# cat nginx.conf4worker_processes 1;5events {6 ? worker_connections 1024;7}8http {9 ? include ? ? ? mime.types;10 ? default_type application/octet-stream;11 ? sendfile ? ? ? on;12 ? keepalive_timeout 65;13 ? 14 ? upstream server_pools { 15 ? ? ? ? server 10.0.0.7:80 weight=1;16 ? ? ? ? server 10.0.0.8:80 weight=1;17 ? }18 ? server { 19 ? ? ? listen ? ? ? 80;20 ? ? ? server_name bbs.lewen.com;21 ? ? ? location / {22 ? ? ? proxy_pass http://server_pools;23 ? ? ? proxy_set_header Host $host;24 ? }25}26 ? server { 27 ? ? ? listen ? ? ? 80;28 ? ? ? server_name www.lewen.com;29 ? ? ? location / {30 ? ? ? proxy_pass http://server_pools;31 ? ? ? proxy_set_header Host $host;32 ? }33}34}3536proxy_set_header 修改反向代理 向后面發出請求的時候的 請求頭的信息
正確的配置讓web服務器記錄真實的用戶ip地址 worker_processes 1; events {worker_connections 1024; } http {include mime.types;default_type application/octet-stream;sendfile on;keepalive_timeout 65;upstream server_pools { server 10.0.0.7:80 weight=1;server 10.0.0.8:80 weight=1;}server { listen 80;server_name bbs.lewen.com;location / {proxy_pass http://server_pools;proxy_set_header Host $host;proxy_set_header X-Forwarded-For $remote_addr;}}server { listen 80;server_name www.lewen.com;location / {proxy_pass http://server_pools;proxy_set_header Host $host;proxy_set_header X-Forwarded-For $remote_addr;} } }34341讓web服務器記錄真實的用戶ip地址2worker_processes 1;3events {4 ? worker_connections 1024;5}6http {7 ? include ? ? ? mime.types;8 ? default_type application/octet-stream;9 ? sendfile ? ? ? on;10 ? keepalive_timeout 65;11 ? 12 ? upstream server_pools { 13 ? ? ? ? server 10.0.0.7:80 weight=1;14 ? ? ? ? server 10.0.0.8:80 weight=1;15 ? }16 ? server { 17 ? ? ? listen ? ? ? 80;18 ? ? ? server_name bbs.lewen.com;19 ? ? ? location / {20 ? ? ? proxy_pass http://server_pools;21 ? ? ? proxy_set_header Host $host;22 ? ? ? proxy_set_header X-Forwarded-For $remote_addr;23 ? ? ? }24 ? }25 ? server { 26 ? ? ? listen ? ? ? 80;27 ? ? ? server_name www.lewen.com;28 ? ? ? location / {29 ? ? ? proxy_pass http://server_pools;30 ? ? ? proxy_set_header Host $host;31 ? ? ? proxy_set_header X-Forwarded-For $remote_addr;32 ? ? ? } ? ?33 ? }34}
測試[root@lb01 conf]# curl -H Host:www.lewen.com 10.0.0.6/oldboy.html web02 www.lewen.com [root@lb01 conf]# curl -H Host:www.lewen.com 10.0.0.6/oldboy.html web01 www.lewen.com [root@lb01 conf]# curl -H Host:www.lewen.com 10.0.0.6/oldboy.html web02 www.lewen.com [root@lb01 conf]# curl -H Host:www.lewen.com 10.0.0.6/oldboy.html web01 www.lewen.com [root@lb01 conf]# curl -H Host:bbs.lewen.com 10.0.0.6/oldboy.html web02 bbs.lewen.com [root@lb01 conf]# curl -H Host:bbs.lewen.com 10.0.0.6/oldboy.html web01 bbs.lewen.com [root@lb01 conf]# curl -H Host:bbs.lewen.com 10.0.0.6/oldboy.html web02 bbs.lewen.com [root@lb01 conf]# curl -H Host:bbs.lewen.com 10.0.0.6/oldboy.html web01 bbs.lewen.com [root@lb01 conf]# curl -H Host:bbs.lewen.com 10.0.0.5/oldboy.html web01 bbs.lewen.com [root@lb01 conf]# curl -H Host:bbs.lewen.com 10.0.0.5/oldboy.html web02 bbs.lewen.com [root@lb01 conf]# curl -H Host:www.lewen.com 10.0.0.5/oldboy.html web01 www.lewen.com [root@lb01 conf]# curl -H Host:www.lewen.com 10.0.0.5/oldboy.html web02 www.lewen.com 24241[root@lb01 conf]# curl -H Host:www.lewen.com 10.0.0.6/oldboy.html2web02 www.lewen.com 3[root@lb01 conf]# curl -H Host:www.lewen.com 10.0.0.6/oldboy.html4web01 www.lewen.com 5[root@lb01 conf]# curl -H Host:www.lewen.com 10.0.0.6/oldboy.html6web02 www.lewen.com 7[root@lb01 conf]# curl -H Host:www.lewen.com 10.0.0.6/oldboy.html8web01 www.lewen.com 9[root@lb01 conf]# curl -H Host:bbs.lewen.com 10.0.0.6/oldboy.html10web02 bbs.lewen.com 11[root@lb01 conf]# curl -H Host:bbs.lewen.com 10.0.0.6/oldboy.html12web01 bbs.lewen.com 13[root@lb01 conf]# curl -H Host:bbs.lewen.com 10.0.0.6/oldboy.html14web02 bbs.lewen.com 15[root@lb01 conf]# curl -H Host:bbs.lewen.com 10.0.0.6/oldboy.html16web01 bbs.lewen.com 17[root@lb01 conf]# curl -H Host:bbs.lewen.com 10.0.0.5/oldboy.html18web01 bbs.lewen.com 19[root@lb01 conf]# curl -H Host:bbs.lewen.com 10.0.0.5/oldboy.html20web02 bbs.lewen.com 21[root@lb01 conf]# curl -H Host:www.lewen.com 10.0.0.5/oldboy.html22web01 www.lewen.com 23[root@lb01 conf]# curl -H Host:www.lewen.com 10.0.0.5/oldboy.html24web02 www.lewen.com yum install -y keepalived111yum install -y keepalived給LVS用的#keepalive配置文件詳解global_defs {router_id LB01 }vrrp_instance VI_1 {state MASTERinterface eth0virtual_router_id 51priority 150advert_int 1authentication {auth_type PASSauth_pass 1111}virtual_ipaddress {10.0.0.3/24 dev eth0 label eth0:1} }20201#keepalive配置文件詳解23global_defs {4 ? router_id LB015}67vrrp_instance VI_1 {8 ? state MASTER9 ? interface eth010 ? virtual_router_id 5111 ? priority 15012 ? advert_int 113 ? authentication {14 ? ? ? auth_type PASS15 ? ? ? auth_pass 111116 ? }17 ? virtual_ipaddress {18 ? ? 10.0.0.3/24 dev eth0 label eth0:119 ? }20}
keepalive基于 服務器 ,除非網段了,電斷了,才會飄Nginx 關了不會飄if [ `netstat -lntup|grep nginx|wc -l` -ne 1 ];then/etc/init.d/keepalived stopfi[root@lb01 conf]# cat /server/scripts/check_lb.sh #!/bin/bashif [ `ps -ef |grep nginx|grep -v grep` -eq 0 ];then/etc/init.d/keepalived stop fi [root@lb01 conf]# chmod +x /server/scripts/check_lb.sh771[root@lb01 conf]# cat /server/scripts/check_lb.sh2#!/bin/bash34if [ `ps -ef |grep nginx|grep -v grep` -eq 0 ];then5 ? /etc/init.d/keepalived stop6fi7[root@lb01 conf]# chmod +x /server/scripts/check_lb.shvrrp_script check_nginx { script "/server/scripts/check_lb01.sh" interval 2 weight 2 }注意 {} 的空格 注意格式標準正確881vrrp_script check_nginx {2script "/server/scripts/check_lb01.sh"3interval 24weight 25}678注意 {} 的空格 ? 注意格式標準正確[root@lb01 keepalived]# cat keepalived.conf global_defs {router_id LB01 }vrrp_script check_lb {script "/server/scripts/check_lb.sh"interval 2weight 2 }vrrp_instance VI_1 {state MASTERinterface eth0virtual_router_id 51priority 150advert_int 1authentication {auth_type PASSauth_pass 1111}virtual_ipaddress {10.0.0.3/24 dev eth0 label eth0:1}track_script {check_lb}} 30301[root@lb01 keepalived]# cat keepalived.conf2global_defs {3 ? router_id LB014}56vrrp_script check_lb {7 ? script "/server/scripts/check_lb.sh"8 ? interval 29 ? weight 210}1112vrrp_instance VI_1 {13 ? state MASTER14 ? interface eth015 ? virtual_router_id 5116 ? priority 15017 ? advert_int 118 ? authentication {19 ? ? ? auth_type PASS20 ? ? ? auth_pass 111121 ? }22 ? virtual_ipaddress {23 ? ? ? 10.0.0.3/24 dev eth0 label eth0:124 ? }25 ? track_script {26 ? ? ? check_lb27 ? }2829}30http://www.dedecms.com/http://www.discuz.net/forum.php 使用db01上面的數據庫把用戶的上傳目錄掛載到 nfs01
總結
以上是生活随笔為你收集整理的s28 LNMP架构服务搭建的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: python pip国内源
 - 下一篇: mysql报错排查总结