概念: 方法一 #安装gcc++ 1.选择一个目录,用于保存安装的文件 2.安装PCRE库 3.安装zlib库 4.安装ssl 5.开始Nginx的安装 安装成功后,会在/usr/local/nginx下产生一个目录 启动Nginx 查看是否启动成功 启动成功,会出现 或者在windows浏览器访问 ,Linux的IP地址,前提是防火墙放行 方法二 配置文件 #user nobody; #错误日志存放路径 #pid logs/nginx.pid; 1.准备多台虚拟机 3.会在/etc/keeplived生成keeplived.conf ! Configuration File for keepalived 脚本文件 启动keepalived,会执行脚本文件,会检测到nginx是否启动,未启动的情况下,启动nginx 使用 启动时可能碰到的错误:
Nginx以事件驱动的方式编写,所以有非常好的性能,同时也是一个非常高效的反向代理、负载平衡服务器。在性能上,Nginx占用很少的系统资源,能支持更多的并发连接,达到更高的访问效率;在功能上,Nginx是优秀的代理服务器和负载均衡服务器;在安装配置上,Nginx安装简单、配置灵活。
Nginx支持热部署,启动速度特别快,还可以在不间断服务的情况下对软件版本或配置进行升级,即使运行数月也无需重新启动。Nginx的安装:
正式开始前,要先安装好编译环境gcc g++开发库
#安装makeyum -y install gcc automake autoconf libtool make yum install gcc gcc-c++ cd /usr/local/src cd /usr/local/src wget https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz tar -zxvf pcre-8.44.tar.gz cd pcre-8.44 ./configure make make install cd /usr/local/src wget http://zlib.net/zlib-1.2.11.tar.gz tar -zxvf zlib-1.2.11.tar.gz cd zlib-1.2.11 ./configure make make install cd /usr/local/src wget https://www.openssl.org/source/openssl-1.1.1g.tar.gz tar -zxvf openssl-1.1.1g.tar.gz cd /usr/local/src wget http://nginx.org/download/nginx-1.18.0.tar.gz tar -zxvf nginx-1.18.0.tar.gz cd nginx-1.18.0 ./configure --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_gzip_static_module --with-http_stub_status_module --with-file-aio --with-http_realip_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.44 --with-zlib=/usr/local/src/zlib-1.2.11 --with-openssl=/usr/local/src/openssl-1.1.1g make -j2 make install /usr/local/nginx/nginx ps -ef | grep nginx root 32708 1 0 11:12 ? 00:00:00 nginx: master process /usr/local/nginx/nginx nobody 32709 32708 0 11:12 ? 00:00:00 nginx: worker process root 32711 9607 0 11:13 pts/1 00:00:00 grep --color=auto nginx
直接使用docker下载 docker pull nginx/unit docker run -d nginx/unit
#工作进程数,通常等于CPU数量或两倍
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;events { # 工作进程最大连接数量,理论上每台nginx服务器的最大连接数为: # worker_processes * worker_connections worker_connections 1024; } 设定http服务器,利用它的反向代理功能提供负载均衡支持 http { # 设置请求包含的内容,存放在mime.types include mime.types; default_type application/octet-stream; # 日志格式 #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; # $remote_addr:获取到的是反向代理服务器的IP地址 # $http_user_agent:用来记录客户浏览器的相关信息 # 因为nginx是一个网关控制中心,如果我们开启了反向代理,那么我们是先去访问 # nginx,然后由nginx对请求进行转发,这样我们就获取不到客户的IP地址 # 可以增加x_forwarded_for信息,用以记录原有客户端的IP地址和原来客户端的请求的服务器地址 # 开启了上面日志,就要开启这个配置,来存放日志 #access_log logs/access.log main; # 设定通过nginx上传文件的大小 client_max_body_size 300m; sendfile on; #tcp_nopush on; # keepalive超时时间。 #keepalive_timeout 0; keepalive_timeout 65; #后端服务器连接的超时时间_发起握手等候响应超时时间 proxy_connect_timeout 90; #连接成功后_等候后端服务器响应时间_ #其实已经进入后端的排队之中等候处理(也可以说是后端服务器处理请求的时间) proxy_read_timeout 180; #后端服务器数据回传时间_就是在规定时间之内后端服务器必须传完所有的数据 proxy_send_timeout 180; #这三个超时时间,就好比,你在网上购物, #proxy_connect_timeout:你买了商品,商家给你投递的时间 #prt:快递在途中运输的时间 #pst:退货时,快递运输的时间 #三者只要有其中一个超时,都会导致这场交易不能够顺利完成 #gzip on; #负载均衡 upstream name{ ip_hash; server 127.0.0.1:9090 down; server 127.0.0.1:8080 weight=2; server 127.0.0.1:6060; server 127.0.0.1:7070 backup; fair; } #格式 upstream 名字{ <负载模式> [负载均衡设备] [IP] <设备状态> } # name: 该服务的名称 # dowm: 该服务器不参与负载均衡 # weight: 开启权重模式,根据权重大小,来对指定访问服务器的比重 # ip_hash: 表示每个请求按访问ip的hash结果分配,相同的ip只能访问同一个后端服务器 # fair: 按后端服务器的响应时间来分配请求,响应时间短的优先分配 #四种分配策略: #1.默认轮询: 每个请求按时间顺序逐一分配到不同的后端服务器中,如果后端服务器宕机,会被自动剔除 #2.weight权重 #3.ip_hash #4.fair # 在需要负载均衡的server中添加proxy_pass http://upstream的服务名称/; # 配置服务 server { # 监听80端口 listen 80; # 监听的服务名称 server_name localhost; # 设置字节编码 #charset koi8-r; #access_log logs/host.access.log main; # 定义拦截规则 location / { root html; index index.html index.htm; } proxy_pass http://upstream的服务名称/; #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ .php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ .php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} } Nginx高可用
2.安装nginx,keepalived
使用yum命令下载安装
yum install keepalived -yglobal_defs { notification_email { #指定keeplived在发生切换时发送emaik到下列对象 acassen@firewall.loc failover@firewall.loc sysadmin@firewall.loc } notification_email_from Alexandre.Cassen@firewall.loc #指定邮件发送人 smtp_server localhost smtp_connect_timeout 30 router_id LVS_DEVEL } #vrrp_sync_group VG_1{ #监控多个网段的实例 # group { # inside_network #实例名 # outside_network # } # notify_master /path/xx.sh #指定当切换到master时,执行的脚本 # notify_backup /path/xx.sh #指定当切换到backup时,执行的脚本 # notify_fault "path/xx.sh VG_1" #故障时执行的脚本 # notify /path/xx.sh # smtp_alert #使用global_defs中提供的邮件地址和smtp服务器发送邮件通知 #} vrrp_script chk_http_port { #脚本配置 script "/usr/local/src/nginx_check.sh" #脚本所在的路径 interval 2 #执行脚本的间隔时间 weight 2 #该服务器的权重 } vrrp_instance VI_1 { state MASTER #备份服务器修改成BACKUP interface eth33 #这个虚拟机使用的网卡 virtual_router_id 51 #主,备机的值必须一样,这个是它们的集群的唯一标识 priority 100 #优先级 主机需要大于从机 advert_int 1 authentication { auth_type PASS auth_pass 1111 } track_script { chk_http_port #(调用检测脚本) } virtual_ipaddress { #虚拟ip 这个ip会与当前主机的ip进行一个绑定 vip 192.168.44.200 } } #!/bin/bash A=`ps -C nginx --no-header |wc -l` if [ $A -eq 0 ];then /usr/local/webserver/nginx/sbin/nginx sleep 2 if [ `ps -C nginx --no-header |wc -l` -eq 0 ];then killall keepalived fi fi systemctl start keepalived.service ps -ef | grep nginx命令验证可能是脚本文件中的路径不对; 权限不够; 配置实例中缺少调用脚本命令 解决方法:修改路径:修改脚本命令中的路径 修改权限:进入到脚本路径下 执行chmod 755 脚本文件名 添加调用脚本: track_script { chk_http_port #(调用检测脚本) } 错误2:Disabling track script chk_http_port due to insecure global_defs { #添加 enable_script_security #开启脚本安全设置 } 错误3:setroubleshootd引起的内存不足 解决方法: vi /etc/selinux/config #SELINUX=enforce #注释掉 #SELINUXTYPE=targeted #注释掉 SELINUX=disabled #增加 #保存 重启生效
本网页所有视频内容由 imoviebox边看边下-网页视频下载, iurlBox网页地址收藏管理器 下载并得到。
ImovieBox网页视频下载器 下载地址: ImovieBox网页视频下载器-最新版本下载
本文章由: imapbox邮箱云存储,邮箱网盘,ImageBox 图片批量下载器,网页图片批量下载专家,网页图片批量下载器,获取到文章图片,imoviebox网页视频批量下载器,下载视频内容,为您提供.
阅读和此文章类似的: 全球云计算
官方软件产品操作指南 (170)