日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ansible高级用法(压测脚本)

發(fā)布時間:2025/3/21 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ansible高级用法(压测脚本) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

記錄一個ansible高級用法與shell結合_kali_yao的博客-CSDN博客_ansible shell

注:由于ansible的遠程原則必須要key(也就是ssh遠程測試),所以在配置文件中加host_key_checking = False即可,

1.下載asible與創(chuàng)建環(huán)境

~]# yum -y install ansible ~]# mkdir ansible && cd ansible

下載與ansible的介紹上面我寫的鏈接有說我就不寫了

2.基本配置

1)防火墻配置?

#將防火墻關閉或設置成允許所有,selinux狀態(tài)enforcing模式修改為permissive變成寬容模式 ~]# setenforce 0 ~]# vim /etc/selinux/config ..... SELINUX=disabled ...... ~]# service firewalld stop

2)配置文件配置

~]# cd ansible ~]# cp /etc/ansible/ansible.cfg ansible.cfg ? # 書寫配置文件 ~]# vim ansible.cfg [defaults] inventory = ~/ansible/hosts # 指定主機清單 remote_user = root # 連接受管機的遠程用戶 roles_path = roles # 指定默認的角色目錄 host_key_checking = False # 設置參數為不檢查key[privilege_escalation] # 設置用戶 sudo 提權 become=True # 需要提權 become_method=sudo # 提權方式為 sudo become_user=root # 提權為 root become_ask_pass=False # 無需驗證密碼 forks = 10 # ssh并發(fā)數量(默認是5)

3)書寫主機清單

~]# vim hosts # ansible全局定義變量 [all:vars] ansible_ssh_user=root # 運程要用的用戶 ansible_ssh_pass=NngnB@@2020 # 遠程主機密碼 ansible_port=22 # 遠程端口,經量不要用22test_iperf_all='true' # 壓測開關 deploy_nginx="false" # nginx開關[installer] # 只需要在控制機器上執(zhí)行 172.17.0.51[nfs_all] 172.17.0.114 172.17.0.142 172.17.0.98[nfs] 172.17.0.142[nginx] 172.17.0.114[ceph] 172.17.64.7 172.17.64.6 172.17.64.5[mysql] 172.17.0.98

4)測試

~]# ansible all -m ping # 如測試失敗注意配置文件注釋那部分去掉

3.壓測ansible

1)拉取角色?

~]# ansible-galaxy init roles/hosts-check - Role roles/hosts-check was created successfully

?2)創(chuàng)建腳本

~]# cd /root/ansible/roles/hosts-check/templates ~]# mkdir iperf && cd iperf ~]# vim iperf3.sh.j2 #!/bin/bash # 定義服務端測試ip I=`head -1 /data/perfor-reports/iperf/groups.txt | awk -F"['']" '{for(i=1;i<=NF;i++)if(i%2==0) print $i}'` # 定義客戶端測試ip k=`tail -1 /data/perfor-reports/iperf/groups.txt | awk -F"['']" '{for(i=1;i<=NF;i++)if(i%2==0) print $i}'` # 定義服務端ip數組 IP=($I)# 測試丟包率 for i in ${IP[*]} doecho $isshpass -p '{{ ansible_ssh_pass }}' ssh $i iperf3 -s -D -p 30000 >> /dev/null &sleep 20iperf3 -c $i -u -b 100m -t 20 -p 30000 >> ceshi.log b=`grep % ceshi.log| awk -F "[()]" '{print $2}' |awk -F"%" '{print $1}'`c=`grep host ceshi.log` rm -rf ceshi.log if [ $b% == 0% ];thenecho -e "\033[32m $c normal:$b%\033[0m"echo -e "\033[32m $c normal:$b%\033[0m" >> /data/perfor-reports/iperf/iperf3.logelseecho -e "\033[31m$c Packet loss rate is $b% \033[0m" echo "$c Packet loss rate is $b%" >> /data/perfor-reports/iperf/iperf3.logfiif [ $i == $k ];thencontinueelsesshpass -p '{{ ansible_ssh_pass }}' ssh $i ps -auxf | grep iperf >> a.txt cat a.txt | awk '{print $2}' | xargs -i sshpass -p '{{ ansible_ssh_pass }}' ssh $i kill {}rm -rf a.txtfi done# 測試所有服務器下載上傳 for i in ${IP[*]} dosshpass -p '{{ ansible_ssh_pass }}' ssh $i speedtest-cli > ceshi.logd=`grep -E "Download|Upload" ceshi.log`echo -e "\033[32m $i Download and Upload is $d\033[0m"echo "$i Download and Upload is $d" >> /data/perfor-reports/iperf/iperf3.logrm -rf ceshi.log done # 測試所有服務器ulimit for i in ${IP[*]} dosshpass -p '{{ ansible_ssh_pass }}' ssh $i ulimit -n > ceshi.loge=`cat ceshi.log`echo -e "\033[32m $i ulimit is $e\033[0m"echo "$i ulimit is $e" >> /data/perfor-reports/iperf/iperf3.logrm -rf ceshi.log done

3)創(chuàng)建要測試的ip文件

~]# groups.txt.j2 {{ groups ['all'] }} {{ groups ['installer'] }}

4)書寫ansible

~]# cd /root/ansible/roles/hosts-check/tasks ~]# vim check-iperf3.yml # deploy iperf3 and ulimit set # 定義開關與標簽 - name: set deploy_nginx factsset_fact: test_iperf_all = "{{ test_iperf_all }}"tags: test_iperf# 下載軟件包 - name: install rpm iperf3 and speedtest-cliyum:name: "{{ item }}"loop:- iperf3 - epel-release - speedtest-cliwhen: test_iperf_all == "true" and inventory_hostname in groups ["all"]tags: test_iperf# 創(chuàng)建腳本與文件日志的目錄 - name: create iperf dirshell: ls /data/perfor-reports/iperf || mkdir -p /data/perfor-reports/iperfwhen: test_iperf_all == "true" and inventory_hostname in groups ["installer"]tags: test_iperf# 拷貝腳本到目錄 - name: copy iperf3.sh.j2template: src: templates/iperf/iperf3.sh.j2dest: /data/perfor-reports/iperf/iperf3.shmode: '0755'when: test_iperf_all == "true" and inventory_hostname in groups ["installer"]tags: test_iperf# 拷貝ip文件 - name: copy groups.txt.j2template:src: templates/iperf/groups.txt.j2dest: /data/perfor-reports/iperf/groups.txtwhen: test_iperf_all == "true" and inventory_hostname in groups ["installer"]tags: test_iperf# 執(zhí)行文件 - name: deploy test iperf and speedtest-cli and ulimitshell: cd /data/perfor-reports/iperf/ && sh iperf3.shwhen: test_iperf_all == "true" and inventory_hostname in groups ["installer"]tags: test_iperf

5)調用yml文件

~]# cd /root/ansible/roles/hosts-check/tasks ~]# vim main.yml --- # tasks file for roles/hosts-check - include: check-iperf3.yml

6)書寫ansible-playbook調用roles

~]# cd /root/ansible ~]# mkdir playbook && cd playbook ~]# vim hosts-check.yml --- - hosts: '{{ hosts }}' gather_facts: True # 當語句有錯誤時繼續(xù)執(zhí)行environment:PATH: "{{ ansible_env.PATH }}:/usr/local/bin"become: yes # 配置文件有寫roles: # 調用角色- hosts-check

7)測試

~]# ansible-playbook playbook/hosts-check.yml

8)書寫單個腳本函數

~]# cd /root/ansible ~]# vim hosts-check.sh #!/bin/bash # Author: kali set -eBASE_DIR=$(cd `dirname $0` && pwd) cd $BASE_DIRCALL_FUN="all_func" hosts="all"help(){echo "show usage:"echo "check_test_iperf" }while getopts ":f:h:" opt docase $opt inf)CALL_FUN="${OPTARG}";;h)hosts="${OPTARG}";;?)echo "unkown args! just suport -f[call function] and -h[ansible hosts group] arg!!!"exit 0;;esac done# check system and kernal version # test iperf check_test_iperf (){echo "###### test iperf ulmit down load ######"ansible-playbook -f 10 -i ../hosts --tags test_iperf ../playbooks/hosts-check/hosts-check.yml \--extra-vars "hosts=${hosts}" } # execute all function all_func(){check_test_iperf }main(){$CALL_FUN || help } main-f FORKS, --forks=FORKS#specify number of parallel processes to use(default=5)#并行任務數。FORKS被指定為一個整數,默認是5 -i INVENTORY, --inventory-file=INVENTORY#specify inventory host path (default=/etc/ansible/hosts) or comma separated host list.#指定要讀取的Inventory文件 -tags #available tags#指定可用的tags -e EXTRA_VARS, --extra-vars=EXTRA_VARS#set additional variables as key=value or YAML/JSON#在Playbook中引入外部參數變量## 測試 ~]# ./hosts-check.sh

9)書寫集成

~]# vim pot-cmd.sh #!/bin/bash # Author: kali set -eBASE_DIR=$(cd `dirname $0` && pwd) cd $BASE_DIREXEC_SCRIPT="" CALL_FUN="all_func" hosts="all"help(){echo "show usage:"echo "you can exec script list: "echo `ls /root/ansible/shell`exit 0 }while getopts ":s:f:h:" opt docase $opt ins)EXEC_SCRIPT="${OPTARG}";;f)CALL_FUN="${OPTARG}";;h)hosts="${OPTARG}";;?)echo "unkown args! just suport -s[mgr-scripts's script] -f[call function] and -h[ansible hosts group] arg!!!"exit 0;;esac donecmd(){/root/ansible/${EXEC_SCRIPT} -f ${CALL_FUN} -h ${hosts} }main(){if [ "x${EXEC_SCRIPT}" == "x" ]; thenhelpelsecmdfi } main ~]# ./pot-cmd.sh -f xxx show usage: you can exec script list: hosts-check.sh ~]# ./pot-cmd.sh -s hosts-check.sh

總結

以上是生活随笔為你收集整理的ansible高级用法(压测脚本)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 男人天堂资源 | 日日操狠狠操 | 中文字幕11页中文字幕11页 | youjizz.com国产| 欧美黑人又粗又大高潮喷水 | 农村妇女愉情三级 | av永久网站 | 欧美视频你懂的 | 五月天婷婷色 | 天天射狠狠干 | 丰满多毛的大隂户视频 | 国产午夜精品无码 | 黄色大片aaa | 国产97自拍| 欧美88av | 国产精品一二三区在线观看 | 久久久精品久久久 | sm捆绑调教视频 | 国产精品乱码妇女bbbb | 朝鲜黄色片| 午夜小视频在线 | 欧美国产日韩一区二区三区 | 国产精品视频在线观看免费 | 亚洲欧美在线一区 | 亚洲一区欧美二区 | 亚洲激情区 | 尤物在线观看视频 | www,久久久 | 中文字幕在线第一页 | 久久天天躁狠狠躁夜夜av | 亚洲精品无码不卡在线播he | 午夜香蕉 | 亚洲免费视频大全 | 亚洲欧美激情另类校园 | 成人欧美一区二区 | 可以免费看毛片的网站 | 中文字幕在线观看第一页 | 日韩成人在线观看 | 免费看国产曰批40分钟粉红裤头 | 三上悠亚中文字幕在线播放 | 火影黄动漫免费网站 | 黑人精品xxx一区一二区 | www.youjizz.com在线 | 日本人和亚洲人zjzjhd | 成人片黄网站色大片免费毛片 | 成人a级大片 | 91爱爱网站 | 婷婷国产一区二区三区 | 午夜爱爱网 | 91视频免费观看网站 | 午夜无遮挡 | 红桃视频一区二区三区免费 | 久久aaaa片一区二区 | 自拍偷拍第 | 毛片网页 | 国产精品视频一区二区三区不卡 | 拔擦8x成人一区二区三区 | 久久久久五月天 | 国产98色在线 | 日韩 | 重囗另类bbwseⅹhd | 91精品国产91久久久久久吃药 | 国产一区二区片 | 韩国伦理片在线看 | 青青草国产成人99久久 | 一区二区在线 | 日本伦理一区 | 亚洲第一视频 | 国产精品毛片久久久久久久av | 日吊视频 | 欧美播放器 | 国产乱人乱精一区二视频国产精品 | 黄页网站在线看 | 四虎成人网 | 91黄色国产| 黑白配高清国语在线观看 | 香蕉视频黄色 | 裸体男女树林做爰 | 狠狠91| 欧美比基尼 | 欧美日韩一区二区三区 | 无码精品黑人一区二区三区 | 久久久精品一区二区 | 日本久久久久久久久 | www免费网站在线观看 | av网站在线播放 | 久草视频在线资源 | 成人一区三区 | 国产在线观看网站 | 久久免费视频一区二区 | 亚洲精品v天堂中文字幕 | 国产又粗又猛又爽又黄的视频小说 | 欧美一级片播放 | 一本色道久久综合亚洲二区三区 | 色综合色综合色综合 | 国语粗话呻吟对白对白 | 中文精品久久久久人妻不卡 | 桃色在线视频 | 精品久久久蜜桃 | 国产精品99久久久久久一二区 |