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 ;}

x

1
[root@www extra]# cat www.conf

2
    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
        }

13
14
        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
    }

测试

1
1

1

测试结果截图

小结

不用URI及特殊字符组合匹配顺序    匹配说明
第一名:“location  = / {”    精确匹配/
第二名:“location  ^~ /images/ {”     匹配常规字符串,不做正则匹配检查, 优先匹配路径
第三名:“location  ~* \.(gif|jpg|jpeg)$ {”     正则匹配
第四名:“location  /documents/ {”     匹配常规字符串,如果有正则则优先匹配正则。
第五名:“location  / {”     所有location都不能匹配后的默认匹配。

nginx-rewrite短域名跳转

lewen.com ====>www.lewen.com
lewen.com 变换为 www.lewen.com
server {
listen       80;
server_name  lewen.com;
rewrite ^/(.*) http://www.lewen.com/$1 permanent;
}
lewen.com/index.html    ====   www.lewen.com/index.html

rewrite配置

[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;}}

15
15

1
[root@web01 extra]# cat www.conf

2
    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 #

44
44

1
[root@web01 extra]# curl -L etiantian.org/index.html

2
web01 www.etiantian.org

3
[root@web01 extra]# curl -Lv 、

4
* About to connect() to etiantian.org port 80 (#0)

5
*   Trying 10.0.0.8... connected

6
* Connected to etiantian.org (10.0.0.8) port 80 (#0)

7
> GET /index.html HTTP/1.1

8
> 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

9
> Host: etiantian.org

10
> Accept: */*

11
>

12
< HTTP/1.1 301 Moved Permanently

13
< Server: nginx/1.12.2

14
< Date: Tue, 27 Feb 2018 12:31:27 GMT

15
< Content-Type: text/html

16
< Content-Length: 185

17
< Connection: keep-alive

18
< Location: http://www.etiantian.org//index.html

19
<

20
* Ignoring the response-body

21
* Connection #0 to host etiantian.org left intact

22
* 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... connected

25
* Connected to www.etiantian.org (10.0.0.8) port 80 (#1)

26
> GET //index.html HTTP/1.1

27
> 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

28
> Host: www.etiantian.org

29
> Accept: */*

30
>

31
< HTTP/1.1 200 OK

32
< Server: nginx/1.12.2

33
< Date: Tue, 27 Feb 2018 12:31:27 GMT

34
< Content-Type: text/html

35
< Content-Length: 24

36
< Last-Modified: Mon, 12 Feb 2018 18:11:30 GMT

37
< Connection: keep-alive

38
< ETag: "5a81d8d2-18"

39
< Accept-Ranges: bytes

40
<

41
web01 www.etiantian.org

42
* Connection #1 to host www.etiantian.org left intact

43
* Closing connection #0

44
* 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: 0

34
34

1
[root@web01 extra]# curl -I jd.com  baidu.com taobao.com

2
HTTP/1.1 302 Moved Temporarily

3
Server: JengineD/1.7.2.1

4
Date: Tue, 27 Feb 2018 12:37:26 GMT

5
Content-Type: text/html

6
Content-Length: 165

7
Location: http://www.jd.com

8
Connection: keep-alive

9
10
HTTP/1.1 200 OK

11
Date: Tue, 27 Feb 2018 12:37:27 GMT

12
Server: Apache

13
Last-Modified: Tue, 12 Jan 2010 13:48:00 GMT

14
ETag: "51-47cf7e6ee8400"

15
Accept-Ranges: bytes

16
Content-Length: 81

17
Cache-Control: max-age=86400

18
Expires: Wed, 28 Feb 2018 12:37:27 GMT

19
Connection: Keep-Alive

20
Content-Type: text/html

21
22
HTTP/1.1 302 Found

23
Server: Tengine

24
Date: Tue, 27 Feb 2018 12:37:27 GMT

25
Content-Type: text/html

26
Content-Length: 258

27
Connection: keep-alive

28
Location: http://www.taobao.com/

29
30
[root@web01 extra]# curl status.lewen.com

31
Active connections: 1

32
server accepts handled requests

33
 84 84 135

34
Reading: 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;}}

11
11

1
##status.conf

2
server {

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
  }

登录验证

1
1

1

[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>

10
10

1
[root@web01 extra]# curl -u oldboy status.lewen.com

2
Enter 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"

2
2

1
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"

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

6
6

1
[root@web01 extra]# curl -u oldboy:123456 status.lewen.com

2
Active connections: 1 

3
server accepts handled requests

4
 46 46 80 

5
Reading: 0 Writing: 1 Waiting: 0 

6

本章回顾

    Apache select和Nginx epoll模型区别形象比喻(面试常考);
    虚拟主机概念及类型分类详解;
    Nginx错误及访问日志及访问日志切割;
    Nginx location介绍及配置实践;
    Nginx Rewrite介绍及配置实践;
    Nginx Web访问认证介绍及配置实践。

mysql二进制部署

#二进制安装MySQL-5.6.39

https://downloads.mysql.com/archives/community/

1
1

1

安装报错
1
Installing 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

5
5

1
Installing 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

2
3
4
原因:缺少libaio库文件 

5
解决方法:yum install libaio* numactl -y 

2
Installing 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就可以解决这个问题了.

4
4

1
Installing 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

2
3
4
如果安装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'

10
10

1
#####To start mysqld at boot time you have to copy

2
#####support-files/mysql.server to the right place for your system

3
#####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'

初始化的帮助信息
1
1

1

####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))

19
19

1
####7.复制启动脚本 授权

2
cp /application/mysql/support-files/mysql.server  /etc/init.d/mysqld

3
chmod +x /etc/init.d/mysqld

4
5
####8.修改启动脚本 和 mysql命令 中的路径

6
sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe /etc/init.d/mysqld

7
8
####9.复制 默认的配置文件   

9
\cp /application/mysql/support-files/my-default.cnf /etc/my.cnf

10
/etc/init.d/mysqld start

11
12
[root@web01 ~]# /etc/init.d/mysqld start

13
Starting MySQL.Logging to '/application/mysql/data/web01.err'.

14
. SUCCESS! 

15
16
####查看

17
18
[root@web01 ~]# ss -lntup |grep 3306

19
tcp    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.表格

24
24

1
####10.PATH路径        添加到系统路径

2
echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile

3
source /etc/profile

4
which mysql

5
6
7
[root@web01 ~]# which mysql

8
/application/mysql/bin/mysql

9
10
11
12
####11.加入开机自启动

13
chkconfig --add mysqld

14
chkconfig mysqld on

15
16
####12.给MySQL root用户设置密码

17
/application/mysql/bin/mysqladmin -u root password 'oldboy123'

18
19
####13.重新登录MySQL数据库

20
mysql -uroot -poldboy123

21
22
####14.数据库基础框架

23
#1.数据库  test mysql

24
#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>

20
20

1
###故障

2
##1./tmp权限

3
##2.主机名解析 hosts解析 #ping 主机名

4
##3.一步一步执行

5
6
##

7
##/application/mysql/bin/mysql

8
##Welcome to the MySQL monitor.  Commands end with ; or \g.

9
##Your MySQL connection id is 1

10
##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 its

15
##affiliates. Other names may be trademarks of their respective

16
##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)

11
11

1
mysql> #查看当前都有啥

2
mysql> show databases;        ********

3
+--------------------+

4
| Database           |

5
+--------------------+

6
| information_schema |

7
| mysql              |

8
| performance_schema |

9
| test               |

10
+--------------------+

11
4 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;

39
39

1
####初级 查看系列-开始

2
##使用某一个数据库

3
###相当于进入 mysql 数据库中  cd mysql ;  cd test

4
#use mysql

5
6
##我想查看当前在哪? pwd    当前正在使用哪个数据库

7
select database();

8
+------------+

9
| database() |

10
+------------+

11
| mysql      |

12
+------------+

13
1 row in set (0.00 sec)

14
15
##我是谁?           查看当前用户

16
select user();

17
+----------------+

18
| user()         |

19
+----------------+

20
| root@localhost |

21
+----------------+

22
1 row in set (0.00 sec)

23
24
###当前系统都有什么用户? 他们可以在哪里登录?  *****

25
select 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
+------+-----------+

36
6 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';

25
25

1
####初级 添加删除系列

2
#创建数据库

3
create database wordpress;

4
#删除数据库

5
drop database wordpress;

6
7
8
#添加用户

9
grant all on wordpress.* to 'wordpress'@'172.16.1.0/255.255.255.0' identified by '123456';

10
11
grant 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;

13
14
#更新系统的权限表

15
flush privileges; 

16
17
18
19
###进行测试

20
mysql -uwordpress -p123456

21
22
mysql -uwordpress -p -h 172.16.1.8

23
24
#删除用户

25
drop 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.

16
16

1
[root@web01 ~]# mysql -uwordpress -p

2
Enter password: 

3
4
####前面创建用户时限制了访问ip 要想本地访问就得再创建一个

5
ERROR 1045 (28000): Access denied for user 'wordpress'@'localhost' (using password: YES)

6
7
8
####制定ip 登录

9
[root@web01 ~]# mysql -uwordpress -h 172.16.1.8 -p

10
Enter password: 

11
Welcome to the MySQL monitor. Commands end with ; or \g.

12
Your MySQL connection id is 24

13
Server version: 5.6.41 MySQL Community Server (GPL)

14
15
Copyright (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.39

20
20

1
###1.查看都有什么数据库

2
###2.查看都有什么用户

3
###3.添加用户

4
5
6
#help sql语句。

7
8
#跳过授权表(不用密码登录)

9
#/etc/init.d/mysqld restart --skip-grant-table

10
11
#mysql 命令行

12
#-u 指定用户

13
#-p 指定密码(不要有空格)

14
#-h 连接到某一台服务器

15
16
17
#更改密码 mysqladmin -uroot -poldboy123 password '新的密码'

18
19
20
db01上部署一个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

3
3

1
  yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel curl-devel -y

2
    yum install freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel -y

3
    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.repo
yum -y install libmcrypt-devel mhash mcrypt
rpm -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=no

40
40

1
####编译配置

2
3
4
tar xf php-5.5.32.tar.gz

5
cd php-5.5.32           #----正式编译前也可以把这个软件安装上(libxslt*)

6
7
./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 commands

35
35

1
编译过程

2
3
##提示 如下内容 即成功

4
Generating files

5
configure: creating ./config.status

6
creating main/internal_functions.c

7
creating main/internal_functions_cli.c

8
+--------------------------------------------------------------------+

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
+--------------------------------------------------------------------+

16
17
Thank you for using PHP.

18
19
config.status: creating php5.spec

20
config.status: creating main/build-defs.h

21
config.status: creating scripts/phpize

22
config.status: creating scripts/man1/phpize.1

23
config.status: creating scripts/php-config

24
config.status: creating scripts/man1/php-config.1

25
config.status: creating sapi/cli/php.1

26
config.status: creating sapi/fpm/php-fpm.conf

27
config.status: creating sapi/fpm/init.d.php-fpm

28
config.status: creating sapi/fpm/php-fpm.service

29
config.status: creating sapi/fpm/php-fpm.8

30
config.status: creating sapi/fpm/status.html

31
config.status: creating sapi/cgi/php-cgi.1

32
config.status: creating ext/phar/phar.1

33
config.status: creating ext/phar/phar.phar.1

34
config.status: creating main/php_config.h

35
config.status: executing default commands

ln -s /application/mysql/lib/libmysqlclient.so.18  /usr/lib64/  #可以不创建
touch ext/phar/phar.phar
make && make install
ln -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 $? 0

44
44

1
安装过程

2
3
Generating phar.php

4
Generating phar.phar

5
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.

6
clicommand.inc

7
pharcommand.inc

8
invertedregexiterator.inc

9
directorygraphiterator.inc

10
directorytreeiterator.inc

11
phar.inc

12
13
Build complete.

14
15
[root@web01 php-5.5.32]# make install

16
Installing PHP CLI binary:        /application/php-5.5.32/bin/

17
Installing PHP CLI man page:      /application/php-5.5.32/php/man/man1/

18
Installing PHP FPM binary:        /application/php-5.5.32/sbin/

19
Installing PHP FPM config:        /application/php-5.5.32/etc/

20
Installing PHP FPM man page:      /application/php-5.5.32/php/man/man8/

21
Installing PHP FPM status page:      /application/php-5.5.32/php/php/fpm/

22
Installing PHP CGI binary:        /application/php-5.5.32/bin/

23
Installing PHP CGI man page:      /application/php-5.5.32/php/man/man1/

24
Installing build environment:     /application/php-5.5.32/lib/php/build/

25
Installing header files:          /application/php-5.5.32/include/php/

26
Installing helper programs:       /application/php-5.5.32/bin/

27
  program: phpize

28
  program: php-config

29
Installing man pages:             /application/php-5.5.32/php/man/man1/

30
  page: phpize.1

31
  page: php-config.1

32
Installing PEAR environment:      /application/php-5.5.32/lib/php/

33
[PEAR] Archive_Tar    - installed: 1.4.0

34
[PEAR] Console_Getopt - installed: 1.4.1

35
[PEAR] Structures_Graph- installed: 1.1.1

36
[PEAR] XML_Util       - installed: 1.3.0

37
[PEAR] PEAR           - installed: 1.10.1

38
Wrote PEAR system config file at: /application/php-5.5.32/etc/pear.conf

39
You may want to add: /application/php-5.5.32/lib/php to your php.ini include_path

40
/home/oldboy/tools/php-5.5.32/build/shtool install -c ext/phar/phar.phar /application/php-5.5.32/bin

41
ln -s -f phar.phar /application/php-5.5.32/bin/phar

42
Installing PDO headers:          /application/php-5.5.32/include/php/ext/pdo/

43
[root@web01 php-5.5.32]# echo $?

44
0

####安装完#复制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.default

17
17

1
####安装完

2
3
#复制php.ini配置文件

4
5
[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

6
7
8
#复制php-fpm配置文件

9
[root@web01 php-5.5.32]# cd /application/php-5.5.32/etc/

10
[root@web01 etc]# ls

11
pear.conf  php-fpm.conf.default

12
[root@web01 etc]# cp php-fpm.conf.default php-fpm.conf

13
[root@web01 etc]# ll

14
total 52

15
-rw-r--r-- 1 root root  1332 Feb 27 22:53 pear.conf

16
-rw-r--r-- 1 root root 22609 Feb 27 22:56 php-fpm.conf

17
-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/

15
15

1
#### 启动

2
3
[root@web01 etc]# /application/php-5.5.32/sbin/php-fpm -t

4
[27-Feb-2018 22:56:53] NOTICE: configuration file /application/php-5.5.32/etc/php-fpm.conf test is successful

5
6
[root@web01 etc]# /application/php-5.5.32/sbin/php-fpm

7
[root@web01 etc]# ss -lntup |grep 9000

8
tcp    LISTEN     0      16384          127.0.0.1:9000                  *:*      users:(("php-fpm",129733,7),("php-fpm",129734,0),("php-fpm",129735,0))

9
10
11
12
13
####添加到系统命令

14
15
[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.php

15
15

1
server {

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
}

12
13
14
15
echo '<?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();} ?>

11
11

1
test_mysql.php

2
3
<?php

4
     //$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.gz
chown -R www.www  *

root@web01 nginx]# chown -R www.www html/
[root@web01 nginx]# ll
[root@web01 blog]# rm -f .maintenance

1
1

1
[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服务器

5
5

1
HOSTNAME    IP    说明

2
lb01    10.0.0.5    Nginx主负载均衡器

3
lb02    10.0.0.6    Nginx辅负载均衡器

4
web01    10.0.0.8    web01服务器

5
web02    10.0.0.7    web02服务器

[root@web01 ~]# /application/nginx/sbin/nginx -V
nginx version: nginx/1.12.2
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure 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;}}

34
34

1
#web01 web02 nginx.conf

2
worker_processes  1;

3
events {

4
    worker_connections  1024;

5
}

6
http {

7
    include       mime.types;

8
    default_type  application/octet-stream;

9
    sendfile        on;

10
    keepalive_timeout  65;

11
12
    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
    }

33
34
}

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.org

8
8

1
tree /application/nginx/html/ -Ld 1

2
3
for name in www bbs blog ;do echo "`hostname` $name.etiantian.org"  > /application/nginx/html/$name/oldboy.html; done

4
 

5
[root@web01 ~]# for name in www bbs blog ;do cat  /application/nginx/html/$name/oldboy.html; done

6
web01 www.etiantian.org

7
web01 bbs.etiantian.org

8
web01 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.org

9
9

1
#web01 web02环境准备完成

2
[root@lb01 ~]# curl 10.0.0.8/oldboy.html

3
web01 bbs.etiantian.org

4
[root@lb01 ~]# curl 10.0.0.7/oldboy.html

5
web02 bbs.etiantian.org

6
[root@lb01 ~]# curl -H Host:www.etiantian.org 10.0.0.8/oldboy.html

7
web01 www.etiantian.org

8
[root@lb01 ~]# curl -H Host:www.etiantian.org 10.0.0.7/oldboy.html

9
web02 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;} }

22
22

1
#lb01

2
worker_processes  1;

3
events {

4
    worker_connections  1024;

5
}

6
http {

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 修改反向代理 向后面发出请求的时候的 请求头的信息

36
36

1
验证故障:

2
wireshark 进行抓包观察

3
[root@lb01 conf]# cat nginx.conf

4
worker_processes  1;

5
events {

6
    worker_connections  1024;

7
}

8
http {

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
}

35
36
proxy_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;} } }

34
34

1
让web服务器记录真实的用户ip地址

2
worker_processes  1;

3
events {

4
    worker_connections  1024;

5
}

6
http {

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

24
24

1
[root@lb01 conf]# curl -H Host:www.lewen.com 10.0.0.6/oldboy.html

2
web02 www.lewen.com 

3
[root@lb01 conf]# curl -H Host:www.lewen.com 10.0.0.6/oldboy.html

4
web01 www.lewen.com 

5
[root@lb01 conf]# curl -H Host:www.lewen.com 10.0.0.6/oldboy.html

6
web02 www.lewen.com 

7
[root@lb01 conf]# curl -H Host:www.lewen.com 10.0.0.6/oldboy.html

8
web01 www.lewen.com 

9
[root@lb01 conf]# curl -H Host:bbs.lewen.com 10.0.0.6/oldboy.html

10
web02 bbs.lewen.com 

11
[root@lb01 conf]# curl -H Host:bbs.lewen.com 10.0.0.6/oldboy.html

12
web01 bbs.lewen.com 

13
[root@lb01 conf]# curl -H Host:bbs.lewen.com 10.0.0.6/oldboy.html

14
web02 bbs.lewen.com 

15
[root@lb01 conf]# curl -H Host:bbs.lewen.com 10.0.0.6/oldboy.html

16
web01 bbs.lewen.com 

17
[root@lb01 conf]# curl -H Host:bbs.lewen.com 10.0.0.5/oldboy.html

18
web01 bbs.lewen.com 

19
[root@lb01 conf]# curl -H Host:bbs.lewen.com 10.0.0.5/oldboy.html

20
web02 bbs.lewen.com 

21
[root@lb01 conf]# curl -H Host:www.lewen.com 10.0.0.5/oldboy.html

22
web01 www.lewen.com 

23
[root@lb01 conf]# curl -H Host:www.lewen.com 10.0.0.5/oldboy.html

24
web02 www.lewen.com 

yum install -y keepalived

1
1

1
yum 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} }

20
20

1
#keepalive配置文件详解

2
3
global_defs {

4
   router_id LB01

5
}

6
7
vrrp_instance VI_1 {

8
    state MASTER

9
    interface eth0

10
    virtual_router_id 51

11
    priority 150

12
    advert_int 1

13
    authentication {

14
        auth_type PASS

15
        auth_pass 1111

16
    }

17
    virtual_ipaddress {

18
     10.0.0.3/24 dev eth0 label eth0:1

19
    }

20
}

keepalive基于 服务器 ,除非网段了,电断了,才会飘

Nginx 关了不会飘

if [ `netstat -lntup|grep nginx|wc -l` -ne 1 ];then
/etc/init.d/keepalived stop
fi

[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.sh

7
7

1
[root@lb01 conf]# cat /server/scripts/check_lb.sh

2
#!/bin/bash

3
4
if [ `ps -ef |grep nginx|grep -v grep` -eq 0 ];then

5
   /etc/init.d/keepalived stop

6
fi

7
[root@lb01 conf]# chmod +x /server/scripts/check_lb.sh

vrrp_script check_nginx { script "/server/scripts/check_lb01.sh" interval 2 weight 2 }注意 {} 的空格 注意格式标准正确

8
8

1
vrrp_script check_nginx {

2
script "/server/scripts/check_lb01.sh"

3
interval 2

4
weight 2

5
}

6
7
8
注意 {} 的空格    注意格式标准正确

[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}}

30
30

1
[root@lb01 keepalived]# cat keepalived.conf

2
global_defs {

3
   router_id LB01

4
}

5
6
vrrp_script check_lb {

7
    script "/server/scripts/check_lb.sh"

8
    interval 2

9
    weight 2

10
}

11
12
vrrp_instance VI_1 {

13
    state MASTER

14
    interface eth0

15
    virtual_router_id 51

16
    priority 150

17
    advert_int 1

18
    authentication {

19
        auth_type PASS

20
        auth_pass 1111

21
    }

22
    virtual_ipaddress {

23
        10.0.0.3/24 dev eth0 label eth0:1

24
    }

25
    track_script {

26
        check_lb

27
    }

28
29
}

30

http://www.dedecms.com/
http://www.discuz.net/forum.php
使用db01上面的数据库
把用户的上传目录挂载到 nfs01

s28 LNMP架构服务搭建相关推荐

  1. LNMP架构环境搭建之PHP、Nginx源码编译安装及其简单配置应用

    LNMP架构中的Mysql见上一篇博文"LNMP架构环境搭建之mysql源码编译安装" 一.PHP简介 PHP(外文名:PHP: Hypertext Preprocessor,中文 ...

  2. LNMP架构环境搭建之mysql源码编译安装

    Mysql MySQL是一个开源的数据库,在互联网行业应用的很广泛,下面来记录一下从源码编译安装的步骤,当然,MySQL也有其他安装方式,比如,使用yum下载安装rpm包,或者二进制方式安装,如果机器 ...

  3. LNMP架构的搭建--源码编译(MYSQL,PHP,nginx)

    1.基础知识 1. LNMP架构: LNMP是指一组通常一起使用来运行动态网站或者服务器的自由软件名称首字母缩写.L指Linux,N指Nginx,M一般指MySQL,也可以指MariaDB,P一般指P ...

  4. LNMP架构的搭建——源码编译(PHP,nginx,Mysql)

    一.源码编译 在企业中,我们常常是需要什么模块才会添加什么模块,而源码编译就可以让我们按需安装. yum安装的优缺点: yum安装的优点:安装东西,方便快捷,特别是不用考虑包依赖. yum安装的缺点: ...

  5. LNMP架构环境搭建流程很详细

    PHP 请求 server {listen 80;server_name example.org www.example.org;root /data/www;location / {index in ...

  6. php搭建论坛脚本,lnmp架构的搭建(discuz论坛)

    环境:rhel6.5    172.25.40.1 一.源码编译mysql 1.安装依赖包例如cmake   gcc  gcc-c++  bison   ncurses-devel 2.解压mysql ...

  7. LNMP架构和论坛搭建以及一键部署

    文章目录 数据流向 一.Nginx服务安装 1.关闭防火墙 2.将所需软件包拖入/opt目录下 3.安装依赖包 4.创建运行用户.组 5.配置软件模块 6.编译安装Nginx 7.优化配置文件路径,便 ...

  8. linux 源码搭建lnmp_Linux精华篇—CentOS 7.4下源码编译构建LNMP架构

    CentOS 7.4搭建LNMP 最新版本LNMP:Linux7.4.ngnix1.13.9.mysql5.7.20.php7.1.10 目录: 第一部分 准备工作 第二部分 安装nginx服务 第三 ...

  9. linux编译框架的搭建,Linux精华篇—CentOS 7.4下源码编译构建LNMP架构

    CentOS 7.4搭建LNMP 最新版本LNMP:Linux7.4.ngnix1.13.9.mysql5.7.20.php7.1.10 目录: 第一部分 准备工作 第二部分 安装nginx服务 第三 ...

最新文章

  1. windows8系统设置×××虚拟连接教程
  2. UITableView属性 自己定义UITableViewCell
  3. 饿了么监控平台的架构设计与演进历程
  4. 操作系统原理:进程与线程、进程生命周期、线程的类型
  5. java 排名相同_Java程序员十年面试经验,助你成为offer收割机
  6. php获得指定目录文件,PHP遍历指定文件夹获取路径及大小(包含子文件夹)
  7. Apple分区总体布局结构
  8. NUC1399 Sum It Up【DFS】
  9. q函数表格怎么看_会计表格函数玩不会?送你会计表格函数公式大全,财务人都在用...
  10. arcgis 只能查看指定行政区域_[教程】Arcgis进阶:统计分析
  11. 软件功能性测试方法和流程
  12. 【多图长文】古希腊式、巴洛克式、哥特式.....图说西方建筑简史
  13. 网页游戏打击感实施要点
  14. oracle 独占更新,Oracle的共享封锁 独占封锁和共享更新封锁 (3)
  15. 硬件知识--单片机高精度电流测量电路
  16. 【p4】perforce命令笔记
  17. mt4服务器文件夹,MT4服务器地址在哪个文件
  18. 一文带你读懂 Promise
  19. 大道至简——RISC-V架构之魂(中)
  20. 2020年中国德化陶瓷博览会暨茶具文化节隆重举行—五洲御瓷分会场精品荟萃

热门文章

  1. 学生专用计算机如何打游戏,电竞专业学生日常:白天学语数外计算机,晚上才打游戏...
  2. pythonimportre_Python Re注意问题(持续更新)
  3. pytorch使用清华源安装仍失败解决方案
  4. 数学大师丘成桐:中国的科技至少要倒退20年
  5. 读博熬不住了,拿个硕士学位投身业界如何?看过来人怎么说
  6. tcpdump抓包ftp协议_tcpdump抓包并保存成cap文件
  7. 计算机科学导论实验考试,计算机科学导论实验指导书
  8. [PHP] 项目实践中的自动加载实现
  9. js Object的属性 Configurable,Enumerable,Writable,Value,Getter,Setter
  10. 使用XmlReader读Xml