整合營銷服務(wù)商

          電腦端+手機端+微信端=數(shù)據(jù)同步管理

          免費咨詢熱線:

          terraform providers 國內(nèi)不容易那

          terraform providers 國內(nèi)不容易那
          • ecord successfully
          • ? create-buckets export|grep terraform
          • 全局生效配置文件路徑
          • cat /Users/lex/.terraform.d/.terraformrc
          • hosts
          • tree for terraform directory
          • providers
          • terraform init
          • reference
          • terraform Main commands:

          record successfully

          ? create-buckets export|grep terraform

          • TFCLICONFIG_FILE=/Users/lex/.terraform.d/.terraformrc
          • 配置文件.terraformrc
          • TFPLUGINCACHE_DIR=/Users/lex/.terraform.d/terraform-plugin-cache
          • 創(chuàng)建緩存目錄

          全局生效配置文件路徑

          • 全局生效配置文件路徑 export TF_CLI_CONFIG_FILE=$HOME/.terraform.d/.terraformrc export TF_PLUGIN_CACHE_DIR="$HOME/.terraform.d/terraform-plugin-cache"

          cat /Users/lex/.terraform.d/.terraformrc

          plugin_cache_dir="$HOME/.terraform.d/terraform-plugin-cache"
          disable_checkpoint=true
          

          hosts

          • ping 151.101.86.49 registry.terraform.io

          tree for terraform directory

          ?  .terraform.d pwd
          /Users/lex/.terraform.d
          ?  .terraform.d tree
          .
          ├── checkpoint_cache
          ├── checkpoint_signature
          └── terraform-plugin-cache
              └── registry.terraform.io
                  └── hashicorp
                      └── google
                          └── 4.45.0
                              ├── darwin_amd64
                              │   └── terraform-provider-google_v4.45.0_x5
                              ├── terraform-provider-google
                              │   └── darwin_amd64 [no using]
                              └── terraform-provider-google_4.45.0_darwin_amd64.zip
          
          7 directories, 5 files
          
          ?  terraform-provider-google tree
          .
          └── darwin_amd64
          
          0 directories, 1 file
          ?  terraform-provider-google file darwin_amd64
          darwin_amd64: Mach-O 64-bit executable x86_64
          

          providers

          terraform-provider-google darwin_amd64
          -- Hashicorp服務(wù)器下載插件 手動下載
          - https://releases.hashicorp.com/terraform-provider-google/3.35.0/
          - https://releases.hashicorp.com/terraform-provider-google/4.45.0/terraform-provider-google_4.45.0_darwin_amd64.zip
          
          ?  terraform-provider-google pwd
          /Users/lex/.terraform.d/terraform-plugin-cache/registry.terraform.io/hashicorp/google/4.45.0/terraform-provider-google
          ?  terraform-provider-google tree
          .
          └── darwin_amd64
          

          0 directories, 1 file

          terraform init

          ?  create-buckets terraform init
          Initializing modules...
          
          Initializing the backend...
          
          Initializing provider plugins...
          - Finding latest version of hashicorp/google...
          - Installing hashicorp/google v4.45.0...
          - Installed hashicorp/google v4.45.0 (signed by HashiCorp)
          
          Terraform has created a lock file .terraform.lock.hcl to record the provider
          selections it made above. Include this file in your version control repository
          so that Terraform can guarantee to make the same selections by default when
          you run "terraform init" in the future.
          
          Terraform has been successfully initialized!
          
          You may now begin working with Terraform. Try running "terraform plan" to see
          any changes that are required for your infrastructure. All Terraform commands
          should now work.
          
          If you ever set or change modules or backend configuration for Terraform,
          rerun this command to reinitialize your working directory. If you forget, other
          commands will detect it and remind you to do so if necessary.
          

          reference

          • golang.org被屏蔽了,直接訪問不了,解決辦法如下:在 http://ping.eu/ping/ 上ping一下golang.org
          • https://cloud.tencent.com/developer/ask/sof/1470987/answer/2013800
          • https://stackoverflow.com/questions/66281882/how-can-i-get-terraform-init-to-run-on-my-apple-silicon-macbook-pro-for-the-go
          • https://www.elephdev.com/Terraform/414.html

          terraform Main commands:

          • [ ] init Prepare your working directory for other commands
          • [ ] validate Check whether the configuration is valid
          • [ ] plan Show changes required by the current configuration//terraform plan -var-file=env_vars/dev.hk.tfvars
          • [ ] apply Create or update infrastructure
          • [ ] destroy Destroy previously-created infrastructure

          者:小不點啊

          來源:www.cnblogs.com/leeSmall/p/9356535.html

          一、Nginx Rewrite 規(guī)則


          1. Nginx rewrite規(guī)則


          Rewrite規(guī)則含義就是某個URL重寫成特定的URL(類似于Redirect),從某種意義上說為了美觀或者對搜索引擎友好,提高收錄量及排名等。


          語法:


          rewrite <regex> <replacement> [flag]
          關(guān)鍵字 || 正則 || 替代內(nèi)容 || flag標記


          Rewrite規(guī)則的flag標記主要有以下幾種:


          • last :相當于Apache里的(L)標記,表示完成rewrite;
          • break:本條規(guī)則匹配完成后,終止匹配,不再匹配后面的規(guī)則
          • redirect:返回302臨時重定向,瀏覽器地址會顯示跳轉(zhuǎn)后的URL地址
          • permanent:返回301永久重定向,瀏覽器地址欄會顯示跳轉(zhuǎn)后的URL地址


          last和break用來實現(xiàn)URL重寫,瀏覽器地址欄URL地址不變


          2. Nginx rewrite例子


          a) 例如用戶訪問www.dbspread.com,想直接跳轉(zhuǎn)到網(wǎng)站下面的某個頁面,www.dbspread.com/new.index.html如何來實現(xiàn)呢?我們可以使用Nginx Rewrite 來實現(xiàn)這個需求,具體如下:在server中加入如下語句即可:


          效果圖如下:

                          rewrite     ^/$    http://www.dbspread.com/new.index.html  permanent;
          對應(yīng)如下語法:
                          rewrite    <regex>    <replacement>                 [flag];
                          關(guān)鍵字      正則        替代內(nèi)容                    flag標記

          正則表達式說明:

          *代表前面0或更多個字符                +代表前面1或更多個字符
          ?代表前面0或1個字符                  ^代表字符串的開始位置
          $代表字符串結(jié)束的位置                 。為通配符,代表任何字符

          b)例如多個域名跳轉(zhuǎn)到同一個域名,nginx rewrite規(guī)則寫法如下:


          格式:

          rewrite <regex> <replacement> [flag];
          關(guān)鍵字 || 正則 || 替代內(nèi)容 || flag標記


          說明:


          • rewrite為固定關(guān)鍵字,表示開始進行rewrite匹配規(guī)則、
          • regex部分是 ^/(.*) ,這是一個正則表達式,匹配完整的域名和后面的路徑地址
          • replacement部分是http://www.dbspread.com/,是取自regex部分( )里的內(nèi)容。匹配成功后跳轉(zhuǎn)到的URL。
          • flag部分 permanent表示永久301重定向標記,即跳轉(zhuǎn)到新的 http://www.dbspread.com/ 地址上



          二、Nginx 防盜鏈


          1. 什么是防盜鏈


          比如http://www.dbspread.com/download/av123.rmvb 這個視頻下載地址被其他網(wǎng)站引用,比如在www.test.com的index.html引用download/av123.rmvb就叫盜鏈,我們要禁止這種引用就叫做防盜鏈



          2. 怎么實現(xiàn)防盜鏈


          在nginx的nginx.conf的server里面配置如下代碼


          三、Nginx 動靜分離

          1. 動靜分離是什么

          Nginx動靜分離是讓動態(tài)網(wǎng)站里的動態(tài)網(wǎng)頁根據(jù)一定規(guī)則把不變的資源和經(jīng)常變的資源區(qū)分開來,動靜資源做好了拆分以后,我們就可以根據(jù)靜態(tài)資源的特點將其做緩存操作,這就是網(wǎng)站靜態(tài)化處理的核心思路。

          2. 動靜分離原理圖

          3. Nginx動靜分離應(yīng)該注意的地方

          1). WEB項目開發(fā)時要注意,將靜態(tài)資源盡量放在一個static文件夾2). 將static靜態(tài)資源文件夾放到Nginx可以取到的位置3). 頁面要建立全局變量路徑,方便修改路徑4). 修改nginx.conf的location, 匹配靜態(tài)資源請求

          4. Nginx動靜分離步驟

          4.1 準備一個靜態(tài)資源button.css

          body {
              margin: 10px 20px;
              text-align: center;
              font-family: Arial, sans-serif;
              background-color: red;
          }

          4.2 在/var/local下新建一個static文件夾用來存放靜態(tài)資源button.css

          4.3 在tomcat-8080/webapps/ROOT下的index.html里面引入button.css


          4.4 在nginx的nginx.conf中server節(jié)點新增靜態(tài)資源分離的配置


          對于Nginx基礎(chǔ)配置,推薦之前的:后端實踐:Nginx日志配置(超詳細)

          4.5 訪問頁面查看效果

          四、Nginx+keepalived 實現(xiàn)高可用

          1. keepalived是什么

          Keepalived軟件起初是專為LVS負載均衡軟件設(shè)計的,用來管理并監(jiān)控LVS集群系統(tǒng)中各個服務(wù)節(jié)點的狀態(tài),后來又加入了可以實現(xiàn)高可用的VRRP (Virtual Router Redundancy Protocol ,虛擬路由器冗余協(xié)議)功能。因此,Keepalived除了能夠管理LVS軟件外,還可以作為其他服務(wù)(例如:Nginx、Haproxy、MySQL等)的高可用解決方案軟件

          2. keepalived主要功能

          管理LVS負載均衡軟件實現(xiàn)LVS集群節(jié)點的健康檢查作為系統(tǒng)網(wǎng)絡(luò)服務(wù)的高可用性(failover)

          3. keepalived故障轉(zhuǎn)移

          Keepalived高可用服務(wù)之間的故障切換轉(zhuǎn)移,是通過 VRRP 來實現(xiàn)的。在 Keepalived服務(wù)正常工作時,主 Master節(jié)點會不斷地向備節(jié)點發(fā)送(多播的方式)心跳消息,用以告訴備Backup節(jié)點自己還活著,當主 Master節(jié)點發(fā)生故障時,就無法發(fā)送心跳消息,備節(jié)點也就因此無法繼續(xù)檢測到來自主 Master節(jié)點的心跳了,于是調(diào)用自身的接管程序,接管主Master節(jié)點的 IP資源及服務(wù)。而當主 Master節(jié)點恢復(fù)時,備Backup節(jié)點又會釋放主節(jié)點故障時自身接管的IP資源及服務(wù),恢復(fù)到原來的備用角色。

          說明:keepalived的主從切換和redis的主從切換是不一樣的,keepalived的主節(jié)點掛了以后,從節(jié)點變?yōu)橹鞴?jié)點,之前的主節(jié)點恢復(fù)以后繼續(xù)做主節(jié)點。redis的主節(jié)點掛了以后,重新恢復(fù)以后變?yōu)閺墓?jié)點

          4. keepalived高可用架構(gòu)示意圖

          說明:

          虛擬ip(VIP):192.168.152.200,對外提供服務(wù)的ip,也可稱作浮動ip192.168.152.130:nginx + keepalived master 主192.168.152.129:nginx + keepalived backup 從192.168.152.129:tomcat-8080192.168.152.129:tomcat-8081

          5. keepalived安裝

          環(huán)境準備:

          centos6、jdk

          虛擬ip(VIP):192.168.152.200,對外提供服務(wù)的ip,也可稱作浮動ip
          192.168.152.130:nginx + keepalived master 主
          192.168.152.129:nginx + keepalived backup 從
          192.168.152.129:tomcat-8080
          192.168.152.129:tomcat-8081

          nginx和tomcat的環(huán)境準備請查看我的前一篇關(guān)于nginx的文章

          5.1 安裝keepalived的步驟:

          注:192.168.152.129(keepalived從節(jié)點) 與 192.168.152.130(keepalived主節(jié)點)先安裝好nginx + keepalived

          下載壓縮包:

          wget www.keepalived.org/software/keepalived-1.3.5.tar.gz

          解壓縮:

          tar -zxvf keepalived-1.3.5.tar.gz

          進入解壓縮以后的文件目錄:

          cd keepalived-1.3.5

          編譯安裝:./configure --prefix=/usr/local/keepalived系統(tǒng)提示警告 *** WARNING - this build will not support IPVS with IPv6. Please install libnl/libnl-3 dev libraries to support IPv6 with IPVS.yum -y install libnl libnl-devel再次執(zhí)行./configure --prefix=/usr/local/keepalived系統(tǒng)提示錯誤 configure: error: libnfnetlink headers missingyum install -y libnfnetlink-devel再次執(zhí)行./configure --prefix=/usr/local/keepalived

          make && make install

          到此keepalived安裝完成,但是接下來還有最關(guān)鍵的一步,如果這一步?jīng)]有做后面啟動keepalived的時候會報找不到配置文件的錯誤

          Configuration file '/etc/keepalived/keepalived.conf' is not a regular non-executable file

          安裝完成后,進入安裝目錄的etc目錄下,將keepalived相應(yīng)的配置文件拷貝到系統(tǒng)相應(yīng)的目錄當中。keepalived啟動時會從/etc/keepalived目錄下查找keepalived.conf配置文件

          mkdir /etc/keepalived

          cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived

          5.2 修改keepalived主節(jié)點192.168.152.130的/etc/keepalived/keepalived.conf配置文件


          5.3 修改keepalived從節(jié)點192.168.152.129的/etc/keepalived/keepalived.conf配置文件

          5.4 檢查nginx是否啟動的shell腳本


          /usr/local/src/check_nginx_pid.sh

          #!/bin/bash
          #檢測nginx是否啟動了
          A=`ps -C nginx --no-header |wc -l`        
          if [ $A -eq 0 ];then    #如果nginx沒有啟動就啟動nginx                        
                /usr/local/nginx/sbin/nginx                #重啟nginx
                if [ `ps -C nginx --no-header |wc -l` -eq 0 ];then    #nginx重啟失敗,則停掉keepalived服務(wù),進行VIP轉(zhuǎn)移
                        killall keepalived                    
                fi
          fi


          5.5 192.168.152.130(keepalived主節(jié)點)和 192.168.152.129(keepalived從節(jié)點)的nginx的配置文件nginx.conf

          user root root; #使用什么用戶啟動NGINX 在運行時使用哪個用戶哪個組
          worker_processes 4; #啟動進程數(shù),一般是1或8個,根據(jù)你的電腦CPU數(shù),一般8個
          worker_cpu_affinity 00000001 00000010 00000100 00001000; #CPU邏輯數(shù)——把每個進程分別綁在CPU上面,為每個進程分配一個CPU
          #pid /usr/local/nginx/logs/nginx.pid
          worker_rlimit_nofile 102400; #一個進程打開的最大文件數(shù)目,與NGINX并發(fā)連接有關(guān)系
          
          #工作模式及連接數(shù)上限
          events
          {
            use epoll; #多路復(fù)用IO 基于LINUX2.6以上內(nèi)核,可以大大提高NGINX的性能 uname -a查看內(nèi)核版本號
            worker_connections 102400; #單個worker process最大連接數(shù),其中NGINX最大連接數(shù)=連接數(shù)*進程數(shù),一般1GB內(nèi)存的機器上可以打開的最大數(shù)大約是10萬左右
            multi_accept on;   #盡可能多的接受請求,默認是關(guān)閉狀態(tài)
          }
          
          #處理http請求的一個應(yīng)用配置段
          http
          {
            #引用mime.types,這個類型定義了很多,當web服務(wù)器收到靜態(tài)的資源文件請求時,依據(jù)請求文件的后綴名在服務(wù)器的MIME配置文件中找到對應(yīng)的MIME #Type,根據(jù)MIMETYPE設(shè)置并response響應(yīng)類型(Content-type)
            include       mime.types; 
            default_type  application/octet-stream; #定義的數(shù)據(jù)流,有的時候默認類型可以指定為text,這跟我們的網(wǎng)頁發(fā)布還是資源下載是有關(guān)系的
            fastcgi_intercept_errors on; #表示接收fastcgi輸出的http 1.0 response code
            charset utf-8;
            server_names_hash_bucket_size 128; #保存服務(wù)器名字的hash表
            #用來緩存請求頭信息的,容量4K,如果header頭信息請求超過了,nginx會直接返回400錯誤,先根據(jù)client_header_buffer_size配置的值分配一個buffer,如果##分配的buffer無法容納request_line/request_header,那么就會##再次根據(jù)large_client_header_buffers配置的參數(shù)分配large_buffer,如果large_buffer還是無#法容納,那么就會返回414(處理request_line)/400(處理request_header)錯誤。
            client_header_buffer_size 4k; 
            large_client_header_buffers 4 32k;
            client_max_body_size 300m; #允許客戶端請求的最大單文件字節(jié)數(shù) 上傳文件時根據(jù)需求設(shè)置這個參數(shù)
            #指定NGINX是否調(diào)用這個函數(shù)來輸出文件,對于普通的文件我們必須設(shè)置為ON,如果NGINX專門做為一個下載端的話可以關(guān)掉,好處是降低磁盤與網(wǎng)絡(luò)的IO處理數(shù)及#系統(tǒng)的UPTIME
            sendfile on; 
            #autoindex on;開啟目錄列表訪問,適合下載服務(wù)器
            tcp_nopush on; #防止網(wǎng)絡(luò)阻塞
            #非常重要,根據(jù)實際情況設(shè)置值,超時時間,客戶端到服務(wù)端的連接持續(xù)有效時間,60秒內(nèi)可避免重新建立連接,時間也不能設(shè)太長,太長的話,若請求數(shù)10000##,都占用連接會把服務(wù)托死
            keepalive_timeout 60;
            tcp_nodelay on; #提高數(shù)據(jù)的實時響應(yīng)性
            client_body_buffer_size 512k; #緩沖區(qū)代理緩沖用戶端請求的最大字節(jié)數(shù)(請求多)
          
            proxy_connect_timeout   5; #nginx跟后端服務(wù)器連接超時時間(代理連接超時)
            proxy_read_timeout      60; #連接成功后,后端服務(wù)器響應(yīng)時間(代理接收超時)
            proxy_send_timeout      5; #后端服務(wù)器數(shù)據(jù)回傳時間(代理發(fā)送超時)
            proxy_buffer_size       16k; #設(shè)置代理服務(wù)器(nginx)保存用戶頭信息的緩沖區(qū)大小
            proxy_buffers           4 64k; #proxy_buffers緩沖區(qū),網(wǎng)頁平均在32k以下的話,這樣設(shè)置
            proxy_busy_buffers_size 128k; #高負荷下緩沖大小
            proxy_temp_file_write_size 128k; #設(shè)定緩存文件夾大小,大于這個值,將從upstream服務(wù)器傳
          
            gzip on; #NGINX可以壓縮靜態(tài)資源,比如我的靜態(tài)資源有10M,壓縮后只有2M,那么瀏覽器下載的就少了
            gzip_min_length  1k;
            gzip_buffers     4 16k;
            gzip_http_version 1.1;
            gzip_comp_level 2; #壓縮級別大小,最小1,最大9.值越小,壓縮后比例越小,CPU處理更快,為1時,原10M壓縮完后8M,但設(shè)為9時,壓縮完可能只有2M了。一般設(shè)置為2
            gzip_types       text/plain application/x-javascript text/css application/xml; #壓縮類型:text,js css xml 都會被壓縮
            gzip_vary on; #作用是在http響應(yīng)中增加一行目的是改變反向代理服務(wù)器的緩存策略
          
          #日志格式 
          log_format  main '$remote_addr - $remote_user [$time_local] "$request" ' #ip 遠程用戶 當?shù)貢r間  請求URL
                           '$status $body_bytes_sent "$http_referer" ' #狀態(tài)  發(fā)送的大小  響應(yīng)的頭
                   '"$http_user_agent" $request_time'; #客戶端使用的瀏覽器  頁面響應(yīng)的時間
          
          #動態(tài)轉(zhuǎn)發(fā)         
          upstream web1 {
              #每個請求按訪問ip的hash結(jié)果分配,這樣每個訪客固定訪問一個后端服務(wù)器,可以解決session的問題。配置了ip_hash就沒有負載均衡的效果了,每次訪問的都是同一個tomcat
              #ip_hash; 
              #轉(zhuǎn)發(fā)的后端的tomcat服務(wù)器,weight表示轉(zhuǎn)發(fā)的權(quán)重,越大轉(zhuǎn)發(fā)的次數(shù)越多,機器性能不一樣配置的weight值不一樣     
               server   192.168.152.129:8080 weight=1 max_fails=2 fail_timeout=30s;
               server   192.168.152.129:8081 weight=1 max_fails=2 fail_timeout=30s;
          }
          upstream web2 {
               server   192.168.152.129:8090 weight=1 max_fails=2 fail_timeout=30s;
               server   192.168.152.129:8091 weight=1 max_fails=2 fail_timeout=30s;
          }
          
          server {
              listen       80; #監(jiān)聽80端口
              server_name  www.dbspread.com; #域名
              #rewrite規(guī)則
              index  index.jsp index.html index.htm;
              root   /usr/local/nginx/html; #定義服務(wù)器的默認網(wǎng)站根目錄位置
              #重定向
              if ($host != 'www.dbspread.com' ){ 
                      rewrite ^/(.*)$  http://www.dbspread.com/$1  permanent;
                      }
          
              #防盜鏈
               location ~* \.(rmvb|jpg|png|swf|flv)$ { #rmvb|jpg|png|swf|flv表示對rmvb|jpg|png|swf|flv后綴的文件實行防盜鏈
                          valid_referers none blocked  www.dbspread.com; #表示對www.dbspread.com此域名開通白名單,比如在www.test.com的index.html引用download/av123.rmvb,無效
                          root   html/b;
                          if ($invalid_referer) { #如果請求不是從www.dbspread.com白名單發(fā)出來的請求,直接重定向到403.html這個頁面或者返回403 
                               #rewrite ^/ http://www.dbspread.com/403.html;
                               return 403;
                          }
                  }
          
              #監(jiān)聽完成以后通過斜桿(/)攔截請求轉(zhuǎn)發(fā)到后端的tomcat服務(wù)器
              location / 
                  {
                      #如果后端的服務(wù)器返回502、504、執(zhí)行超時等錯誤,自動將請求轉(zhuǎn)發(fā)到upstream負載均衡池中的另一臺服務(wù)器,實現(xiàn)故障轉(zhuǎn)移。
                      proxy_next_upstream http_502 http_504 error timeout invalid_header;
                      proxy_set_header Host  $host; #獲取客戶端的主機名存到變量Host里面,從而讓tomcat取到客戶端機器的信息
                      proxy_set_header X-Real-IP $remote_addr; #獲取客戶端的主機名存到變量X-Real-IP里面,從而讓tomcat取到客戶端機器的信息
                      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                      #rewrite     ^/$    http://www.dbspread.com/new.index.html  permanent;#用戶訪問www.dbspread.com,想直接跳轉(zhuǎn)到網(wǎng)站下面的某個頁面:www.dbspread.com/new.index.html
                      proxy_pass http://web1; #跳轉(zhuǎn)到對應(yīng)的應(yīng)用web1
                  }
          
                 # location ~ .*\.(php|jsp|cgi|shtml)?$ #動態(tài)分離 ~匹配 以.*結(jié)尾(以PHP JSP結(jié)尾走這段)
                 #  {
                 #     proxy_set_header Host  $host;
                 #        proxy_set_header X-Real-IP $remote_addr;
                 #        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                 #        proxy_pass http://jvm_web2;
                 # }
          
                  #靜態(tài)分離 ~匹配 以.*結(jié)尾(以html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css結(jié)尾走這段),當然不是越久越好,如果有10000個用戶在線,都保存幾個月,系統(tǒng)托跨
                  location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ 
                  {
                      root /var/local/static; #靜態(tài)資源存放在nginx的安裝機器上
                      #proxy_pass http://www.static.com; #靜態(tài)資源也可存放在遠程服務(wù)器上
                      expires    30d;
                  }
          
                  #日志級別有[debug|info|notice|warn|error|crit]  error_log 級別分為 debug, info, notice, warn, error, crit  默認為crit, 生產(chǎn)環(huán)境用error 
                  #crit 記錄的日志最少,而debug記錄的日志最多
                  access_log  /usr/local/logs/web2/access.log main;
                  error_log   /usr/local/logs/web2/error.log  crit;
          
              }
          
          
          }


          到這一步環(huán)境準備已完成,相關(guān)的配置也修改完成,下面我們來查看效果


          5.6 配置hosts域名映射


          192.168.152.200  www.dbspread.com

          注意:這里192.168.152.200 是keepalived里面virtual_ipaddress配置的虛擬ip

           virtual_ipaddress {
                  192.168.152.200 # 定義虛擬ip(VIP),可多設(shè),每行一個
              }


          到這一步環(huán)境準備已完成,相關(guān)的配置也修改完成,下面我們來查看效果


          5.7 分別啟動192.168.152.129的兩個tomcat


          5.8 分別啟動192.168.152.130(keepalived主節(jié)點)和

          192.168.152.129(keepalived從節(jié)點)的keepalived的

          啟動命令:


          /usr/local/keepalived/sbin/keepalived  

          可以看到keepalived和nginx都啟動了

          在瀏覽器輸入www.dpspread.com域名訪問

          5.9 下面我們停掉主節(jié)點192.168.152.130的keepalived和nginx

          可以看到從節(jié)點變?yōu)橹鞴?jié)點了

          在瀏覽器輸入地址www.dpspread.com訪問,可以看到訪問正常

          5.10 下面我們重新啟動主節(jié)點192.168.152.130

          可以看到主節(jié)點重新啟動以后變?yōu)橹鞴?jié)點了

          之前變?yōu)橹鞴?jié)點的從節(jié)點又變回從節(jié)點了

          到此keepalived+nginx的高可用完美完成

          :移動端準備工作

          <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
          <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
          <!-- 設(shè)置在蘋果手機上以應(yīng)用模式啟動時,是否全屏 -->
          
          <meta name='apple-touch-fullscreen' content='yes'>
          <!-- ios 系統(tǒng) 作用未知 -->
          <meta name="apple-mobile-web-app-capable" content="yes" />
          <!-- iso 系統(tǒng) 作用未知 -->
          <meta content="fullscreen=yes,preventMove=no" name="ML-Config">
          <!-- iso 系統(tǒng) 作用未知 -->
          <meta name="apple-mobile-web-app-status-bar-style" content="black" />
           <!-- 是否識別 手機號碼、 電子郵件 地址 等-->
          
           <meta name="format-detection" content="telephone=no,email=no,address=no" />
          <!-- 讓360雙核瀏覽器用webkit內(nèi)核渲染頁面 -->  
          <meta name="renderer" content="webkit"> 
          <!-- 避免IE使用兼容模式 -->  
          <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
           允許全屏模式瀏覽,隱藏瀏覽器導(dǎo)航欄--><meta name="apple-mobile-web-app-capable" content="yes" />
          <!--微信緩存-->      <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />      <meta http-equiv="Pragma" content="no-cache" />      <meta http-equiv="Expires" content="0" />  
          <!--[if lt IE 9]>
            <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
            <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
          <![endif]-->
          

          二:pc端準備工作

          <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
          <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
          <!-- 讓360雙核瀏覽器用webkit內(nèi)核渲染頁面 -->  <meta name="renderer" content="webkit"> <!--[if lt IE 9]>  <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>  <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script><![endif]-->

          三:base.css公共樣式pc端

          body, div, span, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, abbr, address, cite, code, del, dfn, em, img, ins, kbd, q, samp, small, strong, sub, sup, var, b, i, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, figcaption, figure, footer, header, hgroup, menu, nav, section, summary, time, mark, audio, video { margin:0;padding:0;border: 0;}
          ol,li,ul,dl,dt,dd{list-style:none;}
          table{border-collapse:collapse;border-spacing:0}
          
          h1,h2,h3,h4,h5,h6,i,strong {font-weight: normal;}  
          img {vertical-align: middle;border: none;width: 100%;}  i {font: inherit;}  
          a {color: #fff;text-decoration: none;-webkit-tap-highlight-color: rgba(0, 0, 0, 0); background-color:transparent;}
          a:hover {text-decoration: underline; outline: none;}  
          select::-ms-expand { display: none; }  
          a:active,a:hover{outline:0}
          .clearfix::before,.clearfix::after{    content: '';    display: block;    height: 0;    line-height: 0;    visibility: hidden;    clear: both;
          }
          .fl{ float:left;}.fr{float:right;}
          input,select,option{vertical-align:middle;border-radius:0px;-moz-appearance:none;-webkit-appearance:none;appearance:none;-webkit-tap-highlight-color: rgba(0, 0, 0, 0);outline: none;}
          input[type="text"],input[type="button"],input[type="submit"],input[type="reset"]{-webkit-appearance: none;appearance: none;border-radius: 0;outline: none;}  
          .overflow {overflow:hidden; }  
          

          四:base.css公共樣式移動端

          body, div, span, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, abbr, address, cite, code, del, dfn, em, img, ins, kbd, q, samp, small, strong, sub, sup, var, b, i, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, figcaption, figure, footer, header, hgroup, menu, nav, section, summary, time, mark, audio, video { margin:0;padding:0}
          ol,li,ul,dl,dt,dd{list-style:none;}.fl {float: left;}  .fr {float: right;} 
          table{border-collapse:collapse;border-spacing:0}
          html {  
              -webkit-text-size-adjust: 100%;  
              -ms-text-size-adjust: 100%;  
              /* 解決IOS默認滑動很卡的情況 */  
              -webkit-overflow-scrolling : touch;  
          }  
            
          /* 禁止縮放表單 */  
          input[type="submit"], input[type="reset"], input[type="button"], input {  
              resize: none;  
              border: none;  
          }  
            
          /* 取消鏈接高亮  */  
          body, div, ul, li, ol, h1, h2, h3, h4, h5, h6, input, textarea, select, p, dl, dt, dd, a, img, button, form, table, th, tr, td, tbody, article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section {  
              -webkit-tap-highlight-color: rgba(0, 0, 0, 0);  
          }  
            
          /* 設(shè)置HTML5元素為塊 */  
          article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section {  
              display: block;  
          }  
            
          /* 圖片自適應(yīng) */  
          img {  
              width: 100%;  
              height: auto;  
              width: auto\9; /* ie8 */  
              -ms-interpolation-mode: bicubic;/*為了照顧ie圖片縮放失真*/  
          }  
          em, i {  
              font-style: normal;  
          }  
          textarea {  
              resize:none; /*禁用了文本的拖拉,尤其在谷歌下*/  
          }   
          p {  
              word-wrap:break-word; /* 不夠的單詞自動換行 而不會被截掉 */  
          }  
          .clearfix:after {  
              content: "";  
              display: block;  
              visibility: hidden;  
              height: 0;  
              clear: both;  
          }  
          .clearfix {  
              zoom: 1;  
          }  
          a {  
              text-decoration: none;  
              color: #fff;  
              font-family: 'Microsoft YaHei', Tahoma, Arial, sans-serif;  
          }  
          a:hover {  
          
              text-decoration: none;  outline: none;
          }  
           
          h1, h2, h3, h4, h5, h6 {  
              font-size: 100%;  
              font-family: 'Microsoft YaHei';  
          }  
          img {  
              border: none;  
          }  
          input{  
              font-family: 'Microsoft YaHei';  
          }  
          /*單行溢出*/  
          .one-txt-cut{  
              overflow: hidden;  
              white-space: nowrap;  
              text-overflow: ellipsis;  
          }  
          /*多行溢出 手機端使用*/  
          .txt-cut{  
              overflow : hidden;  
              text-overflow: ellipsis;  
              display: -webkit-box;  
              /* -webkit-line-clamp: 2; */  
              -webkit-box-orient: vertical;  
          }  
          /* 移動端點擊a鏈接出現(xiàn)藍色背景問題解決 */  
          a:link,a:active,a:visited,a:hover {  
              background: none;  
              -webkit-tap-highlight-color: rgba(0,0,0,0);  
              -webkit-tap-highlight-color: transparent;  
          }  
          
          .overflow {overflow:hidden; }
          .w50{  
              width: 50%;  
          }  
          .w25{  
              width: 25%;  
          }  
          .w20{  
              width: 20%;  
          }  
          .w33{  
              width: 33.333333%;  
          
          }  
          

          五:移動端布局使用方法rem

          第一種:js控制html字體大小, js代碼放在head里面

          html設(shè)置初始font-size:320px的字體大小

          var html=document.getElementsByTagName('html')[0];
          if (html) {
              var w=window.innerWidth;
              var fontSize=(w > 640 ? 640 : w) / 640 * 30;
              html.style.fontSize=fontSize + 'px';
          }
          window.onload=function () {
              window.onresize=function () {
                  var w=window.innerWidth;
                  console.log(w);
                  var fontSize=(w > 640 ? 640 : w) / 640 * 30;
                  html.style.fontSize=fontSize + 'px';
              }
          }


          第二種:js控制html字體大小常用 ,js代碼放在head里面

          html設(shè)置初始font-size:320px的字體大小

          (function (doc, win) {
              var docEl=doc.documentElement;
              var resizeEvt='orientationchange' in window ? 'orientationchange' : 'resize';
              var recalc=function () {
                  var clientWidth=docEl.clientWidth;
                  if (!clientWidth) return;
                  docEl.style.fontSize=(clientWidth > 640 ? 640 : clientWidth) / 320 * 20 + 'px';
              }; // 不同瀏覽器resize事件處理機制不同      // 使用定時器延遲處理resize回調(diào)函數(shù)以降低重復(fù)響應(yīng)     
              var recalcTimer=null;
              var delaycalc=function () {
                  win.clearTimeout(recalcTimer);
                  recalcTimer=win.setTimeout(recalc, 100);
              }; // 移動端不需要考慮事件注冊函數(shù)的兼容性    
              if (!doc.addEventListener) return;
              win.addEventListener(resizeEvt, delaycalc, false); // DOMContentLoaded事件只在DOM文檔樹加載完畢觸發(fā),此處不用延遲處理 
              doc.addEventListener('DOMContentLoaded', recalc, false);
          })(document, window);


          第三種:用媒體查詢控制html字體大小

          一:字體大小為15px開始 常用

          html {
              font-size: 15px
          }
          
          html {
              font-size: 4.7vw;
              /* rem(root element)配合vw(viewport width)  */
          }
          
          @media only screen and (min-width:320PX) and (max-width:359PX) {
          
              html {
          
                  font-size: 15px
              }
          
          }
          
          @media only screen and (min-width:360PX) and (max-width:374PX) {
          
              html {
          
                  font-size: 16.875px
              }
          
          }
          
          @media only screen and (min-width:375PX) and (max-width:389PX) {
          
              html {
          
                  font-size: 17.5781px
              }
          
          }
          
          @media only screen and (min-width:390PX) and (max-width:400PX) {
          
              html {
          
                  font-size: 18.75px
              }
          
          }
          
          @media only screen and (min-width:401PX) and (max-width:414PX) {
          
              html {
          
                  font-size: 19.4063px
              }
          
          }
          
          @media only screen and (min-width:415PX) and (max-width:640PX) {
          
              html {
          
                  font-size: 22.5px
              }
          
          }
          
          @media screen and (min-width:641PX) {
          
              html {
          
                  font-size: 30px
              }
          
          }

          二:字體大小為13.65px 不常用

          html {
          
              font-size: 4.2vw;
          
              /* rem(root element)配合vw(viewport width) */
          
          }
          
          html {
          
              font-size: 13.65px
          }
          
          @media only screen and (min-width:320PX) and (max-width:360PX) {
          
              html {
          
                  font-size: 13.65px
              }
          
          }
          
          @media only screen and (min-width:360PX) and (max-width:375PX) {
              html {
                  font-size: 15.36px
              }
          }
          
          @media only screen and (min-width:375PX) and (max-width:390PX) {
              html {
                  font-size: 16px
              }
          }
          
          @media only screen and (min-width:390PX) and (max-width:414PX) {
              html {
                  font-size: 16.64px
              }
          }
          
          @media only screen and (min-width:414PX) and (max-width:460PX) {
              html {
                  font-size: 17.664px
              }
          }
          
          @media only screen and (min-width:460PX) and (max-width:640PX) {
              html {
                  font-size: 20px
              }
          }
          
          @media screen and (min-width:640PX) {
              html {
                  font-size: 27.31px
              }
          }

          六:移動端布局用flex和自動縮放

          新舊版本兼容:這里設(shè)置flex容器為.box,子元素為.item

          1、Flex 布局

          .box {
              display: -ms-flexbox;
              display: -webkit-flex;
              display: flex;
              display: -webkit-box;
              display: -moz-box;
          }

          舊版:display:box

          新版:display:flex

          2、定義主軸的方向

          水平方向:

          .box {
              -moz-flex-direction: row;
              -webkit-flex-direction: row;
              flex-direction: row;
              -webkit-box-direction: normal;
              -webkit-box-orient: horizontal;
          }

          垂直方向:

          .box {
              -moz-flex-direction: column;
              -webkit-flex-direction: column;
              flex-direction: column;
              -webkit-box-direction: normal;
              -webkit-box-orient: vertical;
          }

          舊版:box-direction: normal 水平方向 | reverse 垂直方向 | inherit ,跟子元素的方向一致; 定義子元素的顯示方向。

          box-orient: horizontal 水平排列| vertical 垂直排列| inline-axis 默認 | block-axis 快方式排列 | inherit繼承父元素; 定義子元素是否應(yīng)水平或垂直排列。

          這兩種要同時設(shè)置才能確定排列方式;

          水平方向:box-direction: normal;box-orient: horizontal

          垂直方向:box-direction: normal; box-orient:vertical

          新版:flex-direction:row(默認值):主軸為水平方向,起點在左端。

          row-reverse:主軸為水平方向,起點在右端。
          column:主軸為垂直方向,起點在上沿。

          column-reverse:主軸為垂直方向,起點在下沿。

          3、子元素主軸對齊方式

          .box {
              -moz-justify-content: center;
              -webkit-justify-content: center;
              justify-content: center;
              -webkit-box-pack: center;
          }

          舊版: box-pack: start | end | center | justify;

          注意:兼容寫法新版語法的space-around是不可用的

          新版:justify-content:flex-start(默認值):左對齊

          flex-end:右對齊
          center: 居中
          space-between:兩端對齊,項目之間的間隔都相等。

          space-around:每個項目兩側(cè)的間隔相等。所以,項目之間的間隔比項目與邊框的間隔大一倍。

          4、子元素交叉軸對齊方式

          .box {
              -moz-align-items: center;
              -webkit-align-items: center;
              align-items: center;
              -webkit-box-align: center;
          }

          舊版: box-align: start | end | center | baseline | stretch;

          新版:align-items:flex-start:交叉軸的起點對齊。
          flex-end:交叉軸的終點對齊。
          center:交叉軸的中點對齊。
          baseline: 項目的第一行文字的基線對齊。
          stretch(默認值):如果項目未設(shè)置高度或設(shè)為auto,將占滿整個容器的高度。

          5、子元素屬性:子元素在水平或者垂直方向占幾分

          .item{ -moz-flex: 1;
                -webkit-flex: 1; flex: 1; 
                -webkit-box-flex: 1.0;}

          舊版:box-flex:1.0浮點數(shù)字

          新版:flex:1 數(shù)字

          6、超出要不要換行 不兼容,就是兼容了也無效

          要求換行

          .box{ flex-wrap:wrap; box-lines: multiple; }

          舊版: box-lines: single默認不允許 | multiple 允許;

          新版:flex-wrap: nowrap 不換行

          wrap 換行,第一行在上方

          wrap-reverse 換行,第一行在下方

          7.新版的其他語法

          01、行內(nèi)元素也可以定義flex語法:不常用

          .box{  display: -webkit-inline-flex;  display: inline-flex;}:

          02、父元素屬性align-content屬性 定義在多跟抽線的對齊方式,一般是換行以后的對齊方式,只有一條抽線改屬性不生效,常用在換行以后有間距的問題:設(shè)置align-content:flex-start; 不常用

          align-content:flex-start:與交叉軸的起點對齊。 flex-end:與交叉軸的終點對齊。 center:與交叉軸的中點對齊。 space-between:與交叉軸兩端對齊,軸線之間的間隔平均分布。 space-around:每根軸線兩側(cè)的間隔都相等。所以,軸線之間的間隔比軸線與邊框的間隔大一倍。

          stretch(默認值):軸線占滿整個交叉軸。

          03、子元素屬性flex,是flex-grow, flex-shrink 和 flex-basis的簡寫,一般只定義子元素占多少份,常用

          04、子元素屬性flex-grow 定義子元素占一行的多少份,值為數(shù)字 不常用

          05、子元素屬性flex-basis屬性 定義了在分配多余空間之前,項目占據(jù)的主軸空間 像素單位和百分比,默認auto

          06、子元素屬性flex-shrink屬性 定義了子元素的縮小比例,如果所有項目的flex-shrink屬性都為1,當空間不足時,都將等比例縮小。如果一個項目的flex-shrink屬性為0,其他項目都為1,則空間不足時,前者不縮小。負值無效

          07、 子元素屬性order屬性 定義子元素的排列方式,數(shù)值越小,越靠前排列,數(shù)字

          08、子元素屬性align-self屬性 定義允許單個項目有與其他項目不一樣的對齊方式,會覆蓋algin-items屬性 不常用

          align-self: auto 默認 表示繼承父元素

          flex-start 與交叉軸的起點對齊。

          flex-end 與交叉軸的終點對齊。

          center 與交叉軸的中點對齊

          baseline: 項目的第一行文字的基線對齊。

          stretch(默認值):如果項目未設(shè)置高度或設(shè)為auto,將占滿整個容器的高度。


          8、兼容無效:

          justify-content: space-around 不能用

          flex-wrap: wrap 不能用

          9、flex兼容的標準寫法

          -webkit-前綴標準版-moz-前綴標準版標準版-webkit-前綴09版

          示例:

          .box {
              display: -ms-flexbox;
              display: -webkit-flex;
              display: flex;
              display: -webkit-box;
              display: -moz-box;
          }

          10、新版的語法:

          定義flex:

          .box {
              display: -webkit-flex;
              /*webkit*/
              display: flex;
          }
          
          /*行內(nèi)flex*/
          .box {
              display: -webkit-inline-flex;
              /*webkit*/
              display: inline-flex;
          }

          父元素屬性:

          .box {
              flex-direction: row | row-reverse | column | column-reverse;
              /*主軸方向:左到右(默認) |   右到左    | 上到下 | 下到上*/
              flex-wrap: nowrap | wrap | wrap-reverse;
              /*換行:不換行(默認) | 換行 | 換行并第一行在下方*/
              flex-flow: <flex-direction> || <flex-wrap>;
              /*主軸方向和換行簡寫*/
              justify-content: flex-start | flex-end | center | space-between | space-around;
              /*主軸對齊方式: 左對齊(默認) |  右對齊  | 居中對齊 |     兩端對齊  | 平均分布*/
              align-items: flex-start | flex-end | center | baseline | stretch;
              /*交叉軸對齊方式:頂部對齊(默認) | 底部對齊 | 居中對齊 | 上下對齊并鋪滿 | 文本基線對齊*/
              align-content: flex-start | flex-end | center | space-between | space-around | stretch;
              /*多主軸對齊:頂部對齊(默認) | 底部對齊   | 居中對齊  | 上下對齊并鋪滿  | 上下平均分布*/
          }

          子元素屬性:

          .item {
              order: <integer>;
              number
              /*排序:數(shù)值越小,越排前,默認為0*/
              flex-grow: <number>;
              /* default 0 */
              /*放大:默認0(即如果有剩余空間也不放大,值為1則放大,2是1的雙倍大小,以此類推)*/
              flex-shrink: <number>;
              /* default 1 */
              /*縮小:默認1(如果空間不足則會縮小,值為0不縮小)*/
              flex-basis: <length> | auto;
              /* default auto */
              /*固定大小:默認為0,可以設(shè)置px值,也可以設(shè)置百分比大小*/
              flex: none | [ <'flex-grow'> <'flex-shrink'>? || <'flex-basis'>]
                  /*flex-grow, flex-shrink 和 flex-basis的簡寫,默認值為0 1 auto,*/
                  align-self: auto | flex-start | flex-end | center | baseline | stretch;
              /*單獨對齊方式:自動(默認) | 頂部對齊   | 底部對齊 | 居中對齊 | 上下對齊并鋪滿 | 文本基線對齊*/
          }


          原文鏈接:https://blog.csdn.net/xgb0610/article/details/80416024


          主站蜘蛛池模板: 精品国产一区二区三区久久蜜臀| 中文字幕亚洲一区二区va在线| 国产成人高清亚洲一区91| 日本一区二区三区在线视频| 国产韩国精品一区二区三区| 欧洲无码一区二区三区在线观看 | 亚洲无删减国产精品一区| 3d动漫精品啪啪一区二区中| 国产一区二区在线观看| 久久国产免费一区二区三区| 国产一区二区三区露脸| 成人国产精品一区二区网站| 精品香蕉一区二区三区| 亚洲日韩国产精品第一页一区| 国产一区二区三区精品视频| 狠狠做深爱婷婷综合一区 | 无码人妻一区二区三区在线| 国产精品区一区二区三| 日韩精品一区二区三区四区| 国产在线精品观看一区| 无码一区二区三区中文字幕| 国产精品一区在线播放| 夜色阁亚洲一区二区三区| 免费一区二区三区| 国产成人无码一区二区在线观看 | 精品无码综合一区二区三区| 国产AV一区二区三区无码野战| 国产一区二区三区播放| 老湿机一区午夜精品免费福利| 亚洲av无码一区二区三区四区| 91精品国产一区二区三区左线| 日韩免费无码一区二区三区 | 无码日韩AV一区二区三区| 好爽毛片一区二区三区四无码三飞| 色噜噜狠狠一区二区三区| 夜精品a一区二区三区| 精品久久国产一区二区三区香蕉 | 人妻AV中文字幕一区二区三区| 中文字幕一区一区三区| 国内精品一区二区三区在线观看| 国产精品亚洲专一区二区三区|