日韩性视频-久久久蜜桃-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高级用法(压测脚本)的全部內容,希望文章能夠幫你解決所遇到的問題。

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

主站蜘蛛池模板: 最新中文字幕视频 | 国产乱淫视频 | 国产精品有码 | 性色av一区二区三区四区 | 乱亲女h秽乱长久久久 | av综合站 | 日b在线观看 | 黄色一级片在线播放 | 毛片网站视频 | 久久免费成人 | 日本一区二区人妻 | 57pao国产精品一区 | 黄色动漫免费在线观看 | 亚洲 日本 欧美 中文幕 | 老湿机69福利区午夜x片 | 九九热视频免费 | 图书馆的女友动漫在线观看 | www.色欧美 | 久久女女 | 成年人黄色片网站 | 涩涩在线播放 | 中文字幕十一区 | 韩国午夜激情 | 国产精品啪 | 国产探花在线精品一区二区 | 快射视频网 | 中文字幕一区三区 | 欧美激情综合网 | 精品人妻一区二区三区浪潮在线 | 成熟女人毛片www免费版在线 | 国产视频在线观看一区二区 | 久久福利影视 | 国产露脸国语对白在线 | 国产精品啊啊啊 | 精品综合网 | 日韩成人自拍 | 国产不卡视频在线观看 | jizz处女| 五月婷婷开心 | 97久久人澡人人添人人爽 | 亚洲午夜影视 | 日韩视频 中文字幕 | 欧美少妇一级片 | 久久久精选 | 人妻奶水人妻系列 | 狼人伊人久久 | 久草福利在线观看 | av中文字 | 成人资源站| 国产精品刺激 | 男性裸体全身精光gay | 国产精品偷伦视频免费看 | 国产一级免费av | 日韩成人福利视频 | 久久国产精品精品国产色婷婷 | 五月婷婷基地 | 欧美视频 | 中国老太婆性做爰 | 叶全真三级| 五月av综合av国产av | 伊人手机在线视频 | 国产手机在线观看 | 国产一区二区啪啪啪 | 黄色一级视频 | 国产精品免费视频一区二区三区 | av影院在线播放 | 人人爽人人爽人人爽人人爽 | 青草视频在线 | 校园春色亚洲 | 青青草原成人网 | 飘花影院伦理片 | 久草视| 男生操女生网站 | 丰满熟妇肥白一区二区在线 | 五月婷婷激情网 | 午夜伦理剧场 | 成人激情小说网站 | 老太婆av| 麻豆最新| 亚洲啪啪av | 女婴高潮h啪啪 | 人人草人人搞 | 国产cao| 99re在线国产 | 日本天堂影院 | 欧美性一级 | 日日爱669| 久草免费在线播放 | 国产精品视频a | 一区二区三区高清在线 | 阿v天堂网| 91精品国产综合久久香蕉 | 午夜激情在线观看视频 | wwwww在线观看 | av女优天堂在线观看 | 久久免费黄色网址 | 99精品一级欧美片免费播放 | 国产又粗又猛又爽又黄91 | 麻豆精品国产传媒av |