相逢意气为君饮,系马高楼垂柳边。这篇文章主要讲述第十七周相关的知识,希望能为你提供帮助。
1、nginx负载均衡中常见的算法及原理有哪些?轮询(默认)
每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除。
upstream backserver
server 192.168.0.14;
server 192.168.0.15;
指定权重
指定轮询几率,weight和访问比率成正比,用于后端服务器性能不均的情况。
upstream backserver
server 192.168.0.14 weight=8;
server 192.168.0.15 weight=10;
IP绑定 ip_hash
每个请求按访问ip的hash结果分配,这样每个访客固定访问一个后端服务器,可以解决session的问题。
upstream backserver
ip_hash;
server 192.168.0.14:88;
server 192.168.0.15:80;
fair(第三方)
按后端服务器的响应时间来分配请求,响应时间短的优先分配。
upstream backserver
server server1;
server server2;
fair;
5、url_hash(第三方)
按访问url的hash结果来分配请求,使每个url定向到同一个后端服务器,后端服务器为缓存时比较有效。
upstream backserver
server squid1:3128;
server squid2:3128;
hash $request_uri;
hash_method crc32;
2、使用rewrite规则实现将所有到a域名的访问rewrite到b域名location /
root /data/nginx/html/pc
index index.html;
rewrite /http://www.b.com permanent;
3、实现反向代理客户端IP透传vi /apps/nginx/conf/conf.d/pc.conf
upstream webserver
server 10.0.0.101:80 weight=1 fail_timeout=5s max_fails=3;
server 10.0.0.102:80 weight=1 fail_timeout=5s max_fails=3 backup;
server
listen 80;
server_name www.magedu.org;
location /
index index.html index.php
root /data/nginx/html/pc
location /web
index index.html;
proxy_pass http://webserver/;
proxy_ser_header x-Forwarded-For $proxy_add_x_forwarded_for ;
4、用LNMP实现wordpress站点搭建
【第十七周】1、安装数据库
yum -y install mariadb-server
mysql_secure_installation
2、创建用户并授权
create database wordpress;
create user wordpress@192.168.253.% identified by 123456
grant all on wordpress.* to wordpress@192.168.253.%;
3、安装PHP
yum -y install php
yum -y install php-fpm
systemctl restart --now php-fpm.service
[root@localhost sbin]# grep ^[^;
] /etc/php-fpm.d/www.conf
[www]
listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1
user = www
group = www
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
slowlog = /var/log/php-fpm/www-slow.log
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_admin_flag[log_errors] = on
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session
ping.path = /ping
pm.status_path = /pm_status
4、安装nginx
yum -y install gcc pcre-devel openssl-devel zlib-devel
[root@localhost src]# wget http://nginx.org/download/nginx-1.18.0.tar.gz
--2022-02-01 04:29:26--http://nginx.org/download/nginx-1.18.0.tar.gz
Resolving nginx.org (nginx.org)... 52.58.199.22, 3.125.197.172, 2a05:d014:edb:5704::6, ...
Connecting to nginx.org (nginx.org)|52.58.199.22|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://183.207.33.41:9011/nginx.org/c3pr90ntc0td/download/nginx-1.18.0.tar.gz [following]
--2022-02-01 04:29:26--http://183.207.33.41:9011/nginx.org/c3pr90ntc0td/download/nginx-1.18.0.tar.gz
Connecting to 183.207.33.41:9011... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1039530 (1015K) [application/octet-stream]
Saving to: ‘nginx-1.18.0.tar.gz’
100%[====================================================================================================================>
] 1,039,5305.43MB/sin 0.2s
2022-02-01 04:29:27 (5.43 MB/s) - ‘nginx-1.18.0.tar.gz’ saved [1039530/1039530]
[root@localhost src]# tar xf nginx-1.18.0.tar.gz
[root@localhost src]# cd nginx-1.18.0/
[root@localhost nginx-1.18.0]# ls
autoCHANGESCHANGES.ruconfconfigurecontribhtmlLICENSEmanREADMEsrc
[root@localhost nginx-1.18.0]# ./configure --prefix=/apps/nginx \\
make &
&
make install
server
listen80;
server_namewww.magedu.org;
root/data/nginx/wordpress;
#charset koi8-r;
#access_loglogs/host.access.logmain;
location /
root/data/nginx/wordpress;
indexindex.php index.html index.htm;
#error_page404/404.html;
# redirect server error pages to the static page /50x.html
#
error_page500 502 503 504/50x.html;
location = /50x.html
roothtml;
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \\.php$
#proxy_passhttp://127.0.0.1;
## pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \\.php$
root/data/nginx/wordpress;
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME/document_root$fastcgi_script_name;
includefastcgi_params;
#location ~ \\.php$
#proxy_passhttp://127.0.0.1;
## pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \\.php$
root/data/nginx/wordpress;
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME/document_root$fastcgi_script_name;
includefastcgi_params;
# deny access to .htaccess files, if Apaches document root
# concurs with nginxs one
#
location ~ ^/(ping|pm_status)$
include fastcgi_params;
fastcgi_pass127.0.0.1:9000;
fastcgi_paramPATH_TRANSLATED/document_root$fastcgi_script_name;
5、部署wordpress
wgethttps://wordpress.org/wordpress-5.4.2.tar.gz
cd /data/nginx/wordpress
tar xfhttps://wordpress.org/wordpress-5.4.2.tar.gz
define( DB_NAME, wordpress );
/* MySQL database username /
define( DB_USER, wordpress );
/* MySQL database password /
define( DB_PASSWORD, 123456 );
/* MySQL hostname /
define( DB_HOST, localhost );
推荐阅读
- linux 配置本地光盘YUM源
- centos8.5 更新失败
- Linux之killall命令
- ubuntu20.04安装中文输入法
- 一堆有用或有趣的小工具,也许对你有所帮助
- docker部署ldap
- 安装cockpit后,出现web console 禁用后台自动打开xmanager的问题
- e-1防火墙-selinux-调优
- Linux如何查看ip地址