-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhpcbmtenvcreate-v2p3.sh
1943 lines (1914 loc) · 114 KB
/
hpcbmtenvcreate-v2p3.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
echo "startup azure delopment script..."
MyResourceGroup=tmcbmt01
Location=japaneast #southcentralus
VMPREFIX=tmcbmt01
VMSIZE=Standard_HB120rs_v2 #Standard_D2as_v4 #Standard_HC44rs, Standard_HB120rs_v3
PBSVMSIZE=Standard_D8as_v4
# ネットワーク設定
MyAvailabilitySet=${VMPREFIX}avset01
MyNetwork=${VMPREFIX}-vnet01
MySubNetwork=compute
MySubNetwork2=management # ログインノード用
ACCELERATEDNETWORKING="--accelerated-networking true" # もし問題がある場合にはNOで利用可能。コンピュートノードのみ対象 true/false
MyNetworkSecurityGroup=${VMPREFIX}-nsg
# MACアドレスを維持するためにNICを保存するかどうかの設定
STATICMAC=false #true or false
IMAGE="OpenLogic:CentOS-HPC:7_8:latest" #Azure URNフォーマット。OpenLogic:CentOS-HPC:8_1:latest
# ユーザ名: デフォルト azureuser
USERNAME=azureuser
# SSH公開鍵ファイルを指定:デフォルトではカレントディレクトリを利用する
SSHKEYFILE="./${VMPREFIX}.pub"
TAG=${VMPREFIX}=$(date "+%Y%m%d")
# 作成するコンピュートノード数
MAXVM=2
# 追加の永続ディスクが必要な場合、ディスクサイズ(GB)を記入する https://azure.microsoft.com/en-us/pricing/details/managed-disks/
PERMANENTDISK=0
PBSPERMANENTDISK=2048
### ログイン処理
# サブスクリプションが複数ある場合は指定しておく
#az account set -s <Subscription ID or name>
# サービスプリンシパルの利用も可能以下のパラメータとログイン処理(az login)を有効にすること
#azure_name="uuid"
#azure_password="uuid"
#azure_tenant="uuid"
#az login --service-principal --username ${azure_name} --password ${azure_password} --tenant ${azure_tenant} --output none
# デバックオプション
#DEBUG="parallel -v"
# コマンド名取得
CMDNAME=$(basename "$0")
# コマンドオプションエラー処理
if [ $# -eq 0 ]; then
echo "実行するには1,2,3個の引数が必要です。" 1>&2
echo "create,delete,start,stop,stop-all,stopvm #,stopvm #1 #2,startvm #1,list,remount,pingpong,addlogin,updatensg,privatenw,publicnw の引数を一つ指定する必要があります。" 1>&2
echo "0. updatensg コマンド: スクリプト実行ノードのグローバルIPを利用してセキュリティグループを設定します。" 1>&2
echo "1. create コマンド: コンピュートノードを作成します。" 1>&2
echo "2. addlogin コマンド: login, PBSノードを作成します。" 1>&2
echo "3. privatenw コマンド: コンピュートノード、PBSノードからグローバルIPアドレスを除きます" 1>&2
echo "その他のコマンド" 1>&2
echo " - stop: すべてのコンピュートノードを停止します。" 1>&2
echo " - stop-all: すべてのコンピュートノード+PBSノード・ログインノードもすべて停止します。" 1>&2
echo " - stopvm <vm#>: コンピュートノードVM#のみを停止します。" 1>&2
echo " - stopvms <start vm#> <end vm#>: コンピュートノードVM# xからVM# yまで停止します。" 1>&2
echo " - startvm <vm#>: コンピュートノードVM#を起動します。" 1>&2
echo " - list: VMの状況・およびマウンド状態を表示します。" 1>&2
echo " - listip: IPアドレスアサインの状態を表示します。" 1>&2
echo " - pingpong: すべてのノード間でpingpongを取得します。ローカルファイル result に保存します。" 1>&2
echo " - remount: デフォルトで設定されているディレクトリの再マウントを実施します。" 1>&2
echo " - publicnw コマンド: コンピュートノード、PBSノードからグローバルIPアドレスを再度追加します。" 1>&2
echo " - delete: すべてのコンピュートノードを削除します。" 1>&2
echo " - delete-all: すべてのコンピュートノード、PBSノード、ログインノードを削除します。" 1>&2
echo " - deletevm <vm#>: 特定のコンピュートノード#のみを削除します。(PBSの設定削除などは未実装)" 1>&2
echo " - checkfiles: ローカルで利用するスクリプトを生成します。" 1>&2
echo " - ssh: 各VMにアクセスできます。 例:$CMDNAME ssh 1: コンピュートノード#1にSSHアクセスします。" 1>&2
exit 1
fi
# SSH鍵チェック。なければ作成
if [ ! -f "./${VMPREFIX}" ] || [ ! -f "./${VMPREFIX}.pub" ] ; then
ssh-keygen -f ./${VMPREFIX} -m pem -t rsa -N "" -b 4096
else
chmod 600 ./${VMPREFIX}
fi
# SSH秘密鍵ファイルのディレクトリ決定
tmpfile=$(stat ./${VMPREFIX} -c '%a')
case $tmpfile in
600 )
SSHKEYDIR="./${VMPREFIX}"
;;
* )
cp ./${VMPREFIX} "$HOME"/.ssh/
chmod 600 "$HOME"/.ssh/${VMPREFIX}
SSHKEYDIR="$HOME/.ssh/${VMPREFIX}"
;;
esac
# github actions向けスペース
echo "SSHKEYDIR: $SSHKEYDIR"
# グローバルIPアドレスの取得・処理
curl -s https://ifconfig.io > tmpip #利用しているクライアントのグローバルIPアドレスを取得
curl -s https://ipinfo.io/ip >> tmpip #代替サイトでグローバルIPアドレスを取得
curl -s https://inet-ip.info >> tmpip #代替サイトでグローバルIPアドレスを取得
# 空行削除
sed -i -e '/^$/d' tmpip > /dev/null
LIMITEDIP="$(head -n 1 ./tmpip)/32"
rm ./tmpip
echo "current your client global ip address: $LIMITEDIP. This script defines the ristricted access from this client"
LIMITEDIP2=113.40.3.153/32 #追加制限IPアドレスをCIRDで記載 例:1.1.1.0/24
echo "addtional accessible CIDR: $LIMITEDIP2"
# 必要なパッケージ: GNU parallel, jq, curlのインストール。別途、azコマンドも必須
if [ -e /etc/debian_version ] || [ -e /etc/debian_release ]; then
# Check Ubuntu or Debian
if [ -e /etc/lsb-release ]; then
# Ubuntu
echo "your linux distribution is: ubuntu"
sudo apt-get install -qq -y parallel jq curl || apt-get install -qq -y parallel jq curl
else
# Debian
echo "your linux distribution is: debian"
sudo apt-get install -qq -y parallel jq curl || apt-get install -qq -y parallel jq curl
fi
elif [ -e /etc/fedora-release ]; then
# Fedra
echo "your linux distribution is: fedora"
sudo yum install --quiet -y parallel jq curl || yum install -y parallel jq curl
elif [ -e /etc/redhat-release ]; then
# RHEL or CentOS
echo "your linux distribution is: Redhat or CentOS"
sudo yum install --quiet -y parallel jq curl || yum install -y parallel jq curl
fi
case $1 in
create )
# クリーンナップファイル
if [ -f ./vmlist ]; then rm ./vmlist; fi
if [ -f ./ipaddresslist ]; then rm ./ipaddresslist; fi
### 全体環境作成
az group create --resource-group $MyResourceGroup --location $Location --tags "$TAG" --output none
# ネットワークチェック
tmpnetwork=$(az network vnet show -g $MyResourceGroup --name $MyNetwork --query id)
echo "current netowrk id: $tmpnetwork"
if [ -z "$tmpnetwork" ] ; then
az network vnet create -g $MyResourceGroup -n $MyNetwork --address-prefix 10.0.0.0/22 --subnet-name $MySubNetwork --subnet-prefix 10.0.0.0/24 --output none
fi
# NSGがあるかどうかチェック
checknsg=$(az network nsg show --name $MyNetworkSecurityGroup -g $MyResourceGroup --query name -o tsv)
if [ -z "$checknsg" ]; then
# 既存NSGがなければ作成
az network nsg create --name $MyNetworkSecurityGroup -g $MyResourceGroup -l $Location --tags "$TAG" --output none
az network nsg rule create --name ssh --nsg-name $MyNetworkSecurityGroup -g $MyResourceGroup --access allow --protocol Tcp --direction Inbound \
--priority 1000 --source-address-prefix "$LIMITEDIP" --source-port-range "*" --destination-address-prefix "*" --destination-port-range 22 --output none
az network nsg rule create --name ssh2 --nsg-name $MyNetworkSecurityGroup -g $MyResourceGroup --access allow --protocol Tcp --direction Inbound \
--priority 1010 --source-address-prefix $LIMITEDIP2 --source-port-range "*" --destination-address-prefix "*" --destination-port-range 22 --output none
else
# NSGがあれば、アップデート
az network nsg rule create --name ssh --nsg-name $MyNetworkSecurityGroup -g $MyResourceGroup --access allow --protocol Tcp --direction Inbound \
--priority 1000 --source-address-prefix "$LIMITEDIP" --source-port-range "*" --destination-address-prefix "*" --destination-port-range 22 --output none
az network nsg rule create --name ssh2 --nsg-name $MyNetworkSecurityGroup -g $MyResourceGroup --access allow --protocol Tcp --direction Inbound \
--priority 1010 --source-address-prefix $LIMITEDIP2 --source-port-range "*" --destination-address-prefix "*" --destination-port-range 22 --output none
fi
# 可用性セット作成。既存のものがあれば利用する
az vm availability-set create --name $MyAvailabilitySet -g $MyResourceGroup -l $Location --tags "$TAG" --output none
numvm=0
for count in $(seq 1 $MAXVM); do
# echo "creating nic # $count"
if [ ${STATICMAC} = "true" ]; then
az network nic create --name ${VMPREFIX}-${count}VMNic --resource-group $MyResourceGroup --vnet-name $MyNetwork --subnet $MySubNetwork --network-security --accelerated-networking true
echo "creating VM # ${count} with static nic"
# $ACCELERATEDNETWORKING: にはダブルクォーテーションはつけない
az vm create -g $MyResourceGroup -l $Location --name ${VMPREFIX}-${count} --size $VMSIZE --availability-set $MyAvailabilitySet --nics ${VMPREFIX}-${count}VMNic --image $IMAGE --admin-username $USERNAME --ssh-key-values $SSHKEYFILE --no-wait --tags "$TAG" -o none
fi
echo "creating VM # $count"
# $ACCELERATEDNETWORKING: にはダブルクォーテーションはつけない
az vm create \
--resource-group $MyResourceGroup --location $Location \
--name ${VMPREFIX}-"${count}" \
--size $VMSIZE --availability-set $MyAvailabilitySet \
--vnet-name $MyNetwork --subnet $MySubNetwork \
--nsg $MyNetworkSecurityGroup --nsg-rule SSH $ACCELERATEDNETWORKING \
--image $IMAGE \
--admin-username $USERNAME --ssh-key-values $SSHKEYFILE \
--no-wait --tags "$TAG" -o table
done
# IPアドレスが取得できるまで停止する
if [ $((MAXVM)) -ge 20 ]; then
echo "sleep 90" && sleep 90
else
echo "sleep 45" && sleep 45
fi
# vmlist 作成
echo "creating vmlist and ipaddresslist"
az vm list-ip-addresses -g $MyResourceGroup --query "[].virtualMachine[].{Name:name, PublicIp:network.publicIpAddresses[0].ipAddress}" -o tsv > tmpfile
# 自然番号順にソート
sort -V ./tmpfile > tmpfile2
echo "creating vmlist"
cut -f 1 ./tmpfile2 > vmlist
numvm=$(cat ./vmlist | wc -l)
# vmlist チェック
if [ $((numvm)) -ne $((MAXVM)) ]; then
# 規定より少なければ、再作成
az vm list-ip-addresses -g $MyResourceGroup --query "[].virtualMachine[].{Name:name, PublicIp:network.publicIpAddresses[0].ipAddress}" -o tsv > tmpfile
sort -V ./tmpfile > tmpfile2
cut -f 1 ./tmpfile2 > ./vmlist
fi
if [ $((numvm)) -ge $((MAXVM+2)) ]; then
# ログインノード、PBSノードの 2行削除する
sed -e '$d' ./vmlist
sed -e '$d' ./vmlist
fi
# ipaddresslist 作成
echo "careating IP Address list"
#az vm list-ip-addresses -g $MyResourceGroup --query "[].virtualMachine[].{Name:name, PublicIp:network.publicIpAddresses[0].ipAddress}" -o tsv > tmpfile
sort -V ./tmpfile > tmpfile2
cut -f 2 ./tmpfile2 > ipaddresslist
echo "ipaddresslist file contents"
cat ./ipaddresslist
# az vm list-ip-addresses --query を利用する場合、必要がない
# sed -i -e '/^$/d' ./ipaddresslist
numip=$(cat ./ipaddresslist | wc -l)
# ipaddresslist チェック
if [ $((numip)) -ne $((MAXVM)) ]; then
# 規定より少なければ、再作成
az vm list-ip-addresses --query "[].virtualMachine[].{Name:name, PublicIp:network.publicIpAddresses[0].ipAddress}" -o tsv -g $MyResourceGroup > tmpfile
sort -V ./tmpfile > tmpfile2
cut -f 2 ./tmpfile2 > ./ipaddresslist
fi
if [ $((numip)) -ge $((MAXVM+2)) ]; then
# ログインノード、PBSノードの 2行削除する
sed -e '$d' ./ipaddresslist
sed -e '$d' ./ipaddresslist
fi
# テンポラリファイル削除
rm ./tmpfile
rm ./tmpfile2
# 永続ディスクが必要な場合に設定可能
if [ $((PERMANENTDISK)) -gt 0 ]; then
az vm disk attach --new -g $MyResourceGroup --size-gb $PERMANENTDISK --sku Premium_LRS --vm-name ${VMPREFIX}-1 --name ${VMPREFIX}-1-disk0 -o table
fi
echo "setting up nfs server"
vm1ip=$(head -n 1 ./ipaddresslist)
for count in $(seq 1 20); do
checkssh=$(ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 5' -i "${SSHKEYDIR}" -t $USERNAME@"${vm1ip}" "uname")
if [ -n "$checkssh" ]; then
break
fi
echo "waiting sshd @ ${VMPREFIX}-1: sleep 10" && sleep 10
done
echo "checkssh connectiblity for ${VMPREFIX}-1: $checkssh"
if [ -z "$checkssh" ]; then
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-1 --command-id RunShellScript \
--scripts "sudo yum install --quiet -y nfs-utils epel-release && echo '/mnt/resource *(rw,no_root_squash,async)' >> /etc/exports"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-1 --command-id RunShellScript --scripts "sudo yum install --quiet -y htop"
sleep 5
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-1 --command-id RunShellScript --scripts "sudo chown ${USERNAME}:${USERNAME} /mnt/resource"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-1 --command-id RunShellScript --scripts "sudo systemctl start rpcbind && sudo systemctl start nfs-server"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-1 --command-id RunShellScript --scripts "sudo systemctl enable rpcbind && sudo systemctl enable nfs-server"
else
# SSH設定が高速
echo "${VMPREFIX}-1: sudo 設定"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${vm1ip}" -t -t "sudo cat /etc/sudoers | grep $USERNAME" > sudotmp
if [ -z "$sudotmp" ]; then
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${vm1ip}" -t -t "echo "$USERNAME ALL=NOPASSWD: ALL" | sudo tee -a /etc/sudoers"
fi
unset sudotmp && rm ./sudotmp
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${vm1ip}" -t -t "sudo cat /etc/sudoers | grep $USERNAME"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${vm1ip}" -t -t "sudo yum install --quiet -y nfs-utils epel-release"
# アフターインストール:epel-release
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${vm1ip}" -t -t "sudo yum install --quiet -y htop"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${vm1ip}" -t -t "echo '/mnt/resource *(rw,no_root_squash,async)' | sudo tee /etc/exports"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${vm1ip}" -t -t "sudo chown ${USERNAME}:${USERNAME} /mnt/resource"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${vm1ip}" -t -t "sudo systemctl start rpcbind && sudo systemctl start nfs-server"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${vm1ip}" -t -t "sudo systemctl enable rpcbind && sudo systemctl enable nfs-server"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${vm1ip}" -t -t "sudo showmount -e"
fi
echo "setting up nfs client"
mountip=$(az vm show -g $MyResourceGroup --name ${VMPREFIX}-1 -d --query privateIps -otsv)
echo "mountip: $mountip"
# 1行目を削除したIPアドレスリストを作成
sed '1d' ./ipaddresslist > ./ipaddresslist-tmp
# sudo設定
echo "${VMPREFIX}-2 to ${MAXVM}: sudo 設定"
for count in $(seq 1 $((MAXVM-1))); do
line=$(sed -n "${count}"P ./ipaddresslist-tmp)
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${line}" -t -t "sudo cat /etc/sudoers | grep $USERNAME" > sudotmp
if [ -z "$sudotmp" ]; then
echo "sudo: setting by ssh command"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${line}" -t -t "echo "$USERNAME ALL=NOPASSWD: ALL" | sudo tee -a /etc/sudoers"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${line}" -t -t "sudo grep $USERNAME /etc/sudoers"
unset sudotmp && rm ./sudotmp
else
echo "sudo: setting by run-command"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-"${count}" --command-id RunShellScript --scripts "echo '$USERNAME ALL=NOPASSWD: ALL' | sudo tee -a /etc/sudoers"
fi
done
# 高速化のためにSSHで一括設定しておく
echo "ssh parallel settings: nfs client"
parallel -a ipaddresslist-tmp "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo yum install --quiet -y nfs-utils epel-release""
parallel -a ipaddresslist-tmp "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo yum install --quiet -y htop""
parallel -a ipaddresslist-tmp "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo mkdir -p /mnt/resource""
parallel -a ipaddresslist-tmp "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo chown $USERNAME:$USERNAME /mnt/resource""
parallel -a ipaddresslist-tmp "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo mount -t nfs ${mountip}:/mnt/resource /mnt/resource""
rm ./ipaddresslist-tmp
# NFSサーバ・マウント設定
count=2
for count in $(seq 2 $MAXVM); do
line=$(sed -n "${count}"P ./ipaddresslist)
for cnt in $(seq 1 10); do
checkssh=$(ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i "${SSHKEYDIR}" $USERNAME@"${line}" -t -t "uname")
if [ -n "$checkssh" ]; then
break
fi
# sshが成功しなければ継続してsleep
echo "waiting sshd @ ${VMPREFIX}-${count}: $checkssh sleep 10" && sleep 10
done
if [ -n "$checkssh" ]; then
echo "${VMPREFIX}-2 to ${MAXVM}: ${count} setting by ssh command"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${line}" -t -t "sudo yum install --quiet -y nfs-utils epel-release"
# アフターインストール:epel-release
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${line}" -t -t "sudo yum install --quiet -y htop"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${line}" -t -t "sudo mkdir -p /mnt/resource"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${line}" -t -t "sudo chown $USERNAME:$USERNAME /mnt/resource"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${line}" -t -t "sudo mount $DEBUG -t nfs ${mountip}:/mnt/resource /mnt/resource"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${line}" -t -t "echo '${mountip}:/mnt/resource /mnt/resource nfs defaults 0 0' | sudo tee -a /etc/fstab"
else
echo "${VMPREFIX}-2 to ${MAXVM}: ${count} setting by az vm run-command"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-"${count}" --command-id RunShellScript --scripts 'sudo yum install --quiet -y nfs-utils epel-release'
# アフターインストール:epel-release
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-"${count}" --command-id RunShellScript --scripts 'sudo yum install --quiet -y htop'
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-"${count}" --command-id RunShellScript --scripts "sudo mkdir -p /mnt/resource"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-"${count}" --command-id RunShellScript --scripts "sudo chown $USERNAME:$USERNAME /mnt/resource"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-"${count}" --command-id RunShellScript --scripts "sudo mount $DEBUG -t nfs ${mountip}:/mnt/resource /mnt/resource"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-"${count}" --command-id RunShellScript \
--scripts "echo '${mountip}:/mnt/resource /mnt/resource xfs defaults 0 0' | sudo tee -a /etc/fstab"
fi
done
echo "end of mouting ${VMPREFIX}-1:/mnt/resource"
# SSHパスワードレスセッティング
echo "preparing for passwordless settings"
cat ./ipaddresslist
# SSH追加設定
if [ -f ./config ]; then rm ./config; fi
cat <<'EOL' >> config
Host *
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
EOL
echo "configuring passwordless settings"
parallel -a ipaddresslist "scp -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} ./${VMPREFIX} $USERNAME@{}:/home/$USERNAME/.ssh/${VMPREFIX}"
parallel -a ipaddresslist "scp -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} ./${VMPREFIX} $USERNAME@{}:/home/$USERNAME/.ssh/id_rsa"
parallel -a ipaddresslist "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} $USERNAME@{} -t -t "chmod 600 /home/$USERNAME/.ssh/id_rsa""
parallel -a ipaddresslist "scp -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} ./${VMPREFIX}.pub $USERNAME@{}:/home/$USERNAME/.ssh/${VMPREFIX}.pub"
# SSH追加設定
for count in $(seq 1 $MAXVM) ; do
line=$(sed -n "${count}"P ./ipaddresslist)
scp -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" ./config $USERNAME@"${line}":/home/$USERNAME/.ssh/config
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${line}" -t -t "chmod 600 /home/$USERNAME/.ssh/config"
done
# SSHローケール設定変更
echo "configuring /etc/ssh/config locale setting"
for count in $(seq 1 $MAXVM); do
locale=$(ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${line}" -t -t "grep 'LC_ALL=C' /home/$USERNAME/.bashrc")
if [ -z "$locale" ]; then
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${line}" -t -t "echo "export 'LC_ALL=C'" >> /home/$USERNAME/.bashrc"
else
echo "LC_ALL=C has arelady setting"
fi
done
# ホストファイル事前バックアップ(PBSノード追加設定向け)
echo "backup original hosts file"
parallel -a ipaddresslist "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} $USERNAME@{} "sudo cp /etc/hosts /etc/hosts.original""
# PBSノード:マウント設定
echo "pbsnode: nfs server @ ${VMPREFIX}-pbs"
# PBSノード:名前取得
pbsvmname=$(az vm show -d -g $MyResourceGroup --name ${VMPREFIX}-pbs --query name -o tsv)
# PBSノードがなければ終了
if [ -z "$pbsvmname" ]; then
echo "no PBS node here!"
exit 0
fi
# PBSノード:グローバルIPアドレス取得
pbsvmip=$(az vm show -d -g $MyResourceGroup --name ${VMPREFIX}-pbs --query publicIps -o tsv)
echo "${VMPREFIX}-pbs's public ip: $pbsvmip"
# PBSノード:マウント向けプライベートIPアドレス取得
pbsmountip=$(az vm show -g $MyResourceGroup --name ${VMPREFIX}-pbs -d --query privateIps -otsv)
echo "${VMPREFIX}-pbs's exports ip: $pbsmountip"
# インターネットからアクセス可能であれば、SSHで高速に設定する
# PBSノードのパブリックIPの判定
if [ -z "$pbsvmip" ]; then
# PBSノードのパブリックIPが空で、IPアドレスが取得できなければ、az cliでの取得
echo "pbsnode: confuguring nfs mount by by az vmruuning-commands"
for count in $(seq 1 $MAXVM) ; do
# コンピュートノード#1の/mnt/resourceをマウント
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-"${count}" --command-id RunShellScript --scripts "sudo mkdir -p /mnt/share"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-"${count}" --command-id RunShellScript --scripts "sudo chown $USERNAME:$USERNAME /mnt/share"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-"${count}" --command-id RunShellScript --scripts "sudo mount -t nfs ${pbsmountip}:/mnt/share /mnt/share"
done
else
echo "pbsnode: confuguring nfs mount by ssh"
# pbsbmipが空でなければSSHでマウント情報の取得
echo "${VMPREFIX}-1: $pbsvmip"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${pbsvmip}" 'sudo showmount -e'
echo "${VMPREFIX}-1 to ${MAXVM}: mounting ${VMPREFIX}-pbs /mnt/share"
parallel -a ipaddresslist "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo mkdir -p /mnt/share""
parallel -a ipaddresslist "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo chown $USERNAME:$USERNAME /mnt/share""
parallel -a ipaddresslist "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo mount -t nfs ${pbsmountip}:/mnt/share /mnt/share""
fi
# PBSノードがある場合にのみ、ホストファイル作成
# ホストファイル作成準備:既存ファイル削除
if [ -f ./vmlist ]; then rm ./vmlist; echo "recreating a new vmlist"; fi
if [ -f ./hostsfile ]; then rm ./hostsfile; echo "recreating a new hostsfile"; fi
if [ -f ./nodelist ]; then rm ./nodelist; echo "recreating a new nodelist"; fi
# ホストファイル作成
az vm list-ip-addresses -g $MyResourceGroup --query "[].virtualMachine.{VirtualMachine:name,PrivateIPAddresses:network.privateIpAddresses[0]}" -o tsv > tmphostsfile
# 自然な順番でソートする
sort -V ./tmphostsfile > tmphostsfile2
# vmlist 取り出し:1列目
cut -f 1 ./tmphostsfile2 > vmlist
# nodelist 取り出し:2列目
cut -f 2 ./tmphostsfile2 > nodelist
# ダブルクォーテーション削除: sed -i -e "s/\"//g" ./tmphostsfile
# ファイルの重複行削除。列は2列まで想定: cat ./tmphostsfile2 | awk '!colname[$1]++{print $1, "\t", $2}' > ./hostsfile
echo "show current hostsfile"
cat ./hostsfile
# テンポラリファイル削除
rm ./tmphostsfile
rm ./tmphostsfile2
### ===========================================================================
# PBSノード:ホストファイル転送・更新
checkssh=$(ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i "${SSHKEYDIR}" -t $USERNAME@"${pbsvmip}" "uname")
if [ -n "$checkssh" ]; then
# ssh成功すれば実施
echo "${VMPREFIX}-pbs: updating hosts file by ssh"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${pbsvmip}" -t -t "rm /home/$USERNAME/hostsfile"
scp -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" ./hostsfile $USERNAME@"${pbsvmip}":/home/$USERNAME/
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${pbsvmip}" -t -t "sudo cp /etc/hosts.original /etc/hosts"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${pbsvmip}" -t -t "cat /home/$USERNAME/hostsfile | sudo tee -a /etc/hosts"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${pbsvmip}" -t -t "sudo cat /etc/hosts | grep ${VMPREFIX}"
else
# SSH失敗した場合、az vm run-commandでのホストファイル転送・更新
echo "${VMPREFIX}-pbs: updating hosts file by az vm running command"
# ログインノードIPアドレス取得:空なら再取得
loginvmip=$(cat ./loginvmip)
if [ -n "$loginvmip" ]; then
loginvmip=$(az vm show -d -g $MyResourceGroup --name ${VMPREFIX}-login --query publicIps -o tsv)
fi
echo "loginvmip: $loginvmip"
echo "PBSノード: ssh: ホストファイル転送 local to login node"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${loginvmip}" -t -t "rm /home/$USERNAME/hostsfile"
scp -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" ./hostsfile $USERNAME@"${loginvmip}":/home/$USERNAME/
scp -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" ./${VMPREFIX} $USERNAME@"${loginvmip}":/home/$USERNAME/${VMPREFIX}
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${loginvmip}" -t -t "chmod 600 /home/$USERNAME/${VMPREFIX}"
echo "PBSノード: ssh: ホストファイル転送 ログインノード to PBSノード"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-pbs --command-id RunShellScript --scripts "scp -o StrictHostKeyChecking=no -i /home/$USERNAME/${VMPREFIX} $USERNAME@${loginprivateip}:/home/$USERNAME/hostsfile /home/$USERNAME/"
echo "PBSノード: az: ホストファイル更新"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-pbs --command-id RunShellScript --scripts "sudo cp /etc/hosts.original /etc/hosts"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-pbs --command-id RunShellScript --scripts "cat /home/$USERNAME/hostsfile | sudo tee -a /etc/hosts"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-pbs --command-id RunShellScript --scripts "cat /etc/hosts"
fi
# コンピュートノード:ホストファイル転送・更新
echo "copy hostsfile to all compute nodes"
count=0
for count in $(seq 1 $MAXVM); do
line=$(sed -n "${count}"P ./ipaddresslist)
# ログインノードへのSSHアクセスチェック
loginvmip=$(cat ./loginvmip)
if [ -n "$loginvmip" ]; then
loginvmip=$(az vm show -d -g $MyResourceGroup --name ${VMPREFIX}-login --query publicIps -o tsv)
fi
echo "loginvmip: $loginvmip"
# コンピュートノードへの直接SSHアクセスチェック
vm1ip=$(az vm show -d -g $MyResourceGroup --name ${VMPREFIX}-1 --query publicIps -o tsv)
checkssh=$(ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i "${SSHKEYDIR}" $USERNAME@"${vm1ip}" -t -t "uname")
echo "checkssh: $checkssh"
if [ -n "$checkssh" ]; then
echo "${VMPREFIX}-1 to ${MAXVM}: updating hostsfile by ssh(direct)"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${line}" -t -t "rm /home/$USERNAME/hostsfile"
scp -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" ./hostsfile $USERNAME@"${line}":/home/$USERNAME/
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${line}" -t -t "sudo cp /etc/hosts.original /etc/hosts"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${line}" -t -t "sudo cp /home/$USERNAME/hostsfile /etc/hosts"
echo "${VMPREFIX}-${count}: show new hosts file"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${line}" -t -t "sudo cat /etc/hosts | grep ${VMPREFIX}"
else
# ログインノード経由で設定
checkssh2=$(ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i "${SSHKEYDIR}" $USERNAME@"${loginvmip}" -t -t "uname")
if [ -n "$checkssh2" ]; then
echo "${VMPREFIX}-1 to ${MAXVM}: updating hostsfile by ssh(via login node)"
# 多段SSH
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${loginvmip}" -t -t "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@${line} -t -t "rm /home/$USERNAME/hostsfile""
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${loginvmip}" -t -t "scp -o StrictHostKeyChecking=no -i ${SSHKEYDIR} ./hostsfile $USERNAME@${line}:/home/$USERNAME/"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${loginvmip}" -t -t "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@${line} -t -t "sudo cp /etc/hosts.original /etc/hosts""
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${loginvmip}" -t -t "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@${line} -t -t "sudo cp /home/$USERNAME/hostsfile /etc/hosts""
echo "${VMPREFIX}-${count}: show new hosts file"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${loginvmip}" -t -t "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@${line} -t -t "sudo cat /etc/hosts | grep ${VMPREFIX}""
else
# SSHできないため、az vm run-commandでのホストファイル転送・更新
echo "${VMPREFIX}-${count}: updating hosts file by az vm running command"
# ログインノードIPアドレス取得:取得済み
echo "loginvmip: $loginvmip"
echo "ローカル: ssh: ホストファイル転送 transfer login node"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${loginvmip}" -t -t "rm /home/$USERNAME/hostsfile"
scp -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" ./hostsfile $USERNAME@"${loginvmip}":/home/$USERNAME/
scp -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" ./${VMPREFIX} $USERNAME@"${loginvmip}":/home/$USERNAME/
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${loginvmip}" -t -t "chmod 600 /home/$USERNAME/${VMPREFIX}"
# ログインプライベートIPアドレス取得:すでに取得済み
#loginprivateip=$(az vm show -g $MyResourceGroup --name ${VMPREFIX}-login -d --query privateIps -o tsv)
for count2 in $(seq 1 $MAXVM); do
# ログインノードへはホストファイル転送済み
echo "コンピュートノード: az: ホストファイル転送 login to compute node"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-"${count2}" --command-id RunShellScript --scripts "scp -o StrictHostKeyChecking=no -i /home/$USERNAME/${VMPREFIX} $USERNAME@${loginprivateip}:/home/$USERNAME/hostsfile /home/$USERNAME/"
echo "コンピュートノード: az: ホストファイル更新"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-"${count2}" --command-id RunShellScript --scripts "sudo cp /etc/hosts.original /etc/hosts"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-"${count2}" --command-id RunShellScript --scripts "sudo cp /home/$USERNAME/hostsfile /etc/hosts"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-"${count2}" --command-id RunShellScript --scripts "sudo cat /etc/hosts"
done
fi
fi
done
# ホストファイル更新完了
echo "end of hostsfile update"
# 追加ノードのPBS設定:実装済み。追加の場合、ダイレクトSSHが必須
### ===========================================================================
# ローカルにopenPBSファイルがあるのは前提
# PBSノード:openPBSクライアントコピー
echo "copy openpbs-execution-20.0.1-0.x86_64.rpm to all compute nodes"
parallel -a ipaddresslist "scp -o StrictHostKeyChecking=no -o 'ConnectTimeout 360' -i ${SSHKEYDIR} ./openpbs-execution-20.0.1-0.x86_64.rpm $USERNAME@{}:/home/$USERNAME/"
# ダウンロード、およびMD5チェック
count=0
if [ -f ./md5executionremote ]; then rm ./md5executionremote; fi
if [ -f ./md5executionremote2 ]; then rm ./md5executionremote2; fi
# CentOS バージョンチェック
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${pbsvmip}" -t -t "cat /etc/redhat-release" > centosversion
centosversion=$(cat -d " " -f 4)
# CentOS 7.x か 8.xか判別する
case $centosversion in
7.?.???? )
# CentOS 7.xの場合
for count in $(seq 1 $MAXVM); do
line=$(sed -n "${count}"P ./ipaddresslist)
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${line}" -t -t "md5sum /home/$USERNAME/openpbs-execution-20.0.1-0.x86_64.rpm | cut -d ' ' -f 1" > md5executionremote
md5executionremote=$(cat ./md5executionremote)
echo "md5executionremote: $md5executionremote"
for cnt in $(seq 1 3); do
if [ "$md5executionremote" == "$md5execution" ]; then
# 固定ではうまくいかない
# if [ "$md5executionremote" != "59f5110564c73e4886afd579364a4110" ]; then
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${line}" -t -t "rm /home/$USERNAME/openpbs-execution-20.0.1-0.x86_64.rpm"
scp -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" ./openpbs-execution-20.0.1-0.x86_64.rpm $USERNAME@"${line}":/home/$USERNAME/openpbs-execution-20.0.1-0.x86_64.rpm
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${line}" -t -t "md5sum /home/$USERNAME/openpbs-execution-20.0.1-0.x86_64.rpm | cut -d ' ' -f 1" > md5executionremote
md5executionremote=$(cat ./md5executionremote)
echo "md5executionremote: $md5executionremote"
echo "md5executionremote2: $md5executionremote2"
for cnt2 in $(seq 1 3); do
echo "checking md5...: $cnt2"
if [ "$md5executionremote2" != "$md5execution" ]; then
# 固定ではうまくいかない
# if [ "$md5executionremote2" != "59f5110564c73e4886afd579364a4110" ]; then
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${line}" -t -t "rm /tmp/openpbs-execution-20.0.1-0.x86_64.rpm"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${line}" -t -t "wget -q $baseurl/openpbs-execution-20.0.1-0.x86_64.rpm -O /tmp/openpbs-execution-20.0.1-0.x86_64.rpm"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${line}" -t -t "md5sum /tmp/openpbs-execution-20.0.1-0.x86_64.rpm | cut -d ' ' -f 1" > md5executionremote2
md5executionremote2=$(cat ./md5executionremote2)
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${line}" -t -t "cp /tmp/openpbs-execution-20.0.1-0.x86_64.rpm /home/$USERNAME/openpbs-execution-20.0.1-0.x86_64.rpm"
echo "md5executionremote2: $md5executionremote2"
else
echo "match md5 by md5executionremote2"
md5executionremote2=$(cat ./md5executionremote2)
break
fi
done
else
echo "match md5 by md5executionremote"
md5executionremote=$(cat ./md5executionremote)
break
fi
done
done
;;
8.?.???? )
echo "skip check md5"
;;
esac
rm ./centosversion
rm ./md5executionremote
rm ./md5executionremote2
# openPBSクライアント:インストール
echo "confuguring all compute nodes"
parallel -a ipaddresslist "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@{} -t -t 'sudo yum install --quiet -y hwloc-libs libICE libSM'"
parallel -a ipaddresslist "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} $USERNAME@{} -t -t 'sudo yum install --quiet -y libnl3'"
echo "installing libnl3"
parallel -a ipaddresslist "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo yum install --quiet -y /home/$USERNAME/openpbs-execution-20.0.1-0.x86_64.rpm""
parallel -a ipaddresslist "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} $USERNAME@{} -t -t 'sudo rpm -aq | grep openpbs'"
parallel -a ipaddresslist "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} $USERNAME@{} -t -t 'sudo /opt/pbs/libexec/pbs_habitat'"
parallel -a ipaddresslist "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} $USERNAME@{} -t -t 'sudo /opt/pbs/libexec/pbs_postinstall'"
# pbs.confファイル生成
parallel -a ipaddresslist "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo sed -i -e 's/PBS_START_MOM=0/PBS_START_MOM=1/g' /etc/pbs.conf""
parallel -a ipaddresslist "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo sed -i -e s/CHANGE_THIS_TO_PBS_SERVER_HOSTNAME/${VMPREFIX}-pbs/g /etc/pbs.conf""
parallel -a ipaddresslist "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo cat /etc/pbs.conf""
# openPBSクライアント:パーミッション設定
parallel -a ipaddresslist "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} $USERNAME@{} -t -t 'sudo chmod 4755 /opt/pbs/sbin/pbs_iff'"
parallel -a ipaddresslist "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} $USERNAME@{} -t -t 'sudo chmod 4755 /opt/pbs/sbin/pbs_rcp'"
# openPBSクライアント:/var/spool/pbs/mom_priv/config コンフィグ設定
parallel -a ipaddresslist "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo sed -i -e s/CHANGE_THIS_TO_PBS_SERVER_HOSTNAME/${VMPREFIX}-pbs/g /var/spool/pbs/mom_priv/config""
for count in $(seq 1 $MAXVM) ; do
line=$(sed -n "${count}"P ./ipaddresslist)
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${line}" -t -t "sudo sed -i -e s/CHANGE_THIS_TO_PBS_SERVER_HOSTNAME/${VMPREFIX}-pbs/g /var/spool/pbs/mom_priv/config"
done
### ===========================================================================
# PBSプロセス起動
# PBSノード起動&$USERNAME環境変数設定
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${pbsvmip}" -t -t "grep pbs.sh /home/azureuser/.bashrc" > ./pbssh
pbssh=$(cat ./pbssh)
if [ -z "$pbssh" ]; then
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${pbsvmip}" -t -t "yes | sudo /etc/init.d/pbs start"
fi
# openPBSクライアントノード起動&$USERNAME環境変数設定
parallel -a ipaddresslist "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} $USERNAME@{} -t -t 'sudo /etc/init.d/pbs start'"
vm1ip=$(head -n 1 ./ipaddresslist)
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${vm1ip}" -t -t "grep pbs.sh /home/azureuser/.bashrc" > ./pbssh
pbssh=$(cat ./pbssh)
if [ -z "$pbssh" ]; then
parallel -a ipaddresslist "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} $USERNAME@{} -t -t 'echo 'source /etc/profile.d/pbs.sh' >> $HOME/.bashrc'"
fi
rm ./pbssh
echo "finished to set up additonal login and PBS node"
### ===========================================================================
# PBSジョブスケジューラセッティング
echo "configpuring PBS settings"
rm ./setuppbs.sh
for count in $(seq 1 $MAXVM); do
echo "/opt/pbs/bin/qmgr -c "create node ${VMPREFIX}-${count}"" >> setuppbs.sh
done
sed -i -e "s/-c /-c '/g" setuppbs.sh
sed -i -e "s/$/\'/g" setuppbs.sh
echo "setuppbs.sh: $(cat ./setuppbs.sh)"
scp -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" ./setuppbs.sh $USERNAME@"${pbsvmip}":/home/$USERNAME/setuppbs.sh
# SSH鍵登録
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${pbsvmip}" -t -t "sudo cp /root/.ssh/authorized_keys /root/.ssh/authorized_keys.old"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${pbsvmip}" -t -t "sudo cp /home/$USERNAME/.ssh/authorized_keys /root/.ssh/authorized_keys"
# ジョブスケジューラセッティング
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" root@"${pbsvmip}" -t -t "bash /home/$USERNAME/setuppbs.sh"
### ===========================================================================
;;
start )
## PBSノード:OSディスクタイプ変更: Premium_LRS
azure_sku2="Premium_LRS"
# PBSノードの存在チェック
osdiskidpbs=$(az vm show -g $MyResourceGroup --name ${VMPREFIX}-pbs --query storageProfile.osDisk.managedDisk.id -o tsv)
if [ -n "$osdiskidpbs" ]; then
az disk update --sku ${azure_sku2} --ids "${osdiskidpbs}" -o table
echo "starting PBS VM"
az vm start -g $MyResourceGroup --name ${VMPREFIX}-pbs -o none &
# 今のところPBSノードが存在すればログインノードも存在する
echo "starting loging VM"
az vm start -g $MyResourceGroup --name ${VMPREFIX}-login -o none &
else
# PBSノードのOSディスクが存在しなければPBSノードも存在しない
echo "no PBS node here!"
fi
echo "starting VM ${VMPREFIX}-1"
az vm start -g $MyResourceGroup --name ${VMPREFIX}-1 -o none &
echo "starting VM ${VMPREFIX}:2-$MAXVM compute nodes"
seq 2 $MAXVM | parallel "az vm start -g $MyResourceGroup --name ${VMPREFIX}-{} -o none &"
sleep 60
echo "checking $MAXVM compute VM's status"
numvm=0
tmpnumvm="default"
while [ -n "$tmpnumvm" ]; do
tmpnumvm=$(az vm list -d -g $MyResourceGroup --query "[?powerState=='VM starting']" -o tsv)
echo "$tmpnumvm" | tr ' ' '\n' > ./tmpnumvm.txt
numvm=$(grep -c "starting" ./tmpnumvm.txt)
echo "current starting VMs: $numvm. All VMs are already running!"
sleep 5
done
rm ./tmpnumvm.txt
echo "checking VM public ip"
# ダイナミックの場合(デフォルト)、再度IPアドレスリストを作成しなおす
# コンピュートノードVM#1のパブリックIPが同じならスキップする
vm1ip=$(az vm show -d -g $MyResourceGroup --name ${VMPREFIX}-1 --query publicIps -o tsv)
echo "${VMPREFIX}-1's IP: $vm1ip"
prevm1ip=$(head -n 1 ./ipaddresslist)
if [ "$prevm1ip" != "$vm1ip" ]; then
echo "making new ipaddress list"
count=1
for count in $(seq 1 $MAXVM) ; do
echo "VM $count: ${VMPREFIX}-$count"
unset ipaddresstmp
while [ -z "$ipaddresstmp" ]; do
ipaddresstmp=$(az vm show -d -g $MyResourceGroup --name ${VMPREFIX}-"${count}" --query publicIps -o tsv)
echo "ip: $ipaddresstmp"
done
echo "$ipaddresstmp" >> ipaddresslist
done
echo "new ipaddress list"
cat ./ipaddresslist
else
echo "not canage ipaddress list"
fi
# コンピュートノードVM#1のマウントするプライベートIPの取得
mountip=$(az vm show -g $MyResourceGroup --name ${VMPREFIX}-1 -d --query privateIps -o tsv)
echo "${VMPREFIX}-1: nfs exports ip: $mountip"
# インターネットからアクセス可能であれば、SSHで高速に設定する
if [ -z "$vm1ip" ]; then
# vm1ipがパブリックIPが空でIPアドレスが取得できなければ、az cliでの取得
# コンピュートノード#1:マウント設定
echo "nfs server @ ${VMPREFIX}-1"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-1 --command-id RunShellScript --scripts "sudo showmount -e"
for count in $(seq 2 $MAXVM) ; do
# 並列化・時間短縮は検討事項
echo "${VMPREFIX}-1: configuring nfs mount by az vmruuning-commands"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-"${count}" --command-id RunShellScript --scripts "sudo mkdir -p /mnt/resource"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-"${count}" --command-id RunShellScript --scripts "sudo chown $USERNAME:$USERNAME /mnt/resource"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-"${count}" --command-id RunShellScript --scripts "sudo mount $DEBUG -t nfs ${mountip}:/mnt/resource /mnt/resource"
done
else
# vm1ipが空でなければSSHでマウントを実施
echo "${VMPREFIX}-1: confuguring nfs mount by ssh"
echo "${VMPREFIX}-1: $vm1ip"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${vm1ip}" 'sudo showmount -e'
# 1行目を削除したIPアドレスリストを作成
sed '1d' ./ipaddresslist > ./ipaddresslist-tmp
echo "${VMPREFIX}-2 to $MAXVM: mounting ${VMPREFIX}-1 /mnt/resource"
parallel -a ipaddresslist-tmp "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo mkdir -p /mnt/resource""
parallel -a ipaddresslist-tmp "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo chown $USERNAME:$USERNAME /mnt/resource""
parallel -a ipaddresslist-tmp "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo mount -t nfs ${mountip}:/mnt/resource /mnt/resource""
fi
echo "end of starting up computing nodes"
# PBSノードがなければ終了
if [ -z "$osdiskidpbs" ]; then
echo "no PBS node here!"
exit 0
fi
# PBSノード:マウント設定
echo "pbsnode: nfs server @ ${VMPREFIX}-pbs"
# PBSノード:名前取得
pbsvmname=$(az vm show -d -g $MyResourceGroup --name ${VMPREFIX}-pbs --query name -o tsv)
# PBSノード:グローバルIPアドレス取得
pbsvmip=$(az vm show -d -g $MyResourceGroup --name ${VMPREFIX}-pbs --query publicIps -o tsv)
echo "${VMPREFIX}-pbs's public ip: $pbsvmip"
# PBSノード:マウント向けプライベートIPアドレス取得
pbsmountip=$(az vm show -g $MyResourceGroup --name ${VMPREFIX}-pbs -d --query privateIps -otsv)
echo "${VMPREFIX}-pbs's exports ip: $pbsmountip"
# インターネットからアクセス可能であれば、SSHで高速に設定する
if [ -n "$pbsvmname" ]; then
# vm1ipが空なら、IPアドレスが取得できなければ、az cliでの取得
if [ -z "$pbsvmip" ]; then
echo "pbsnode: confuguring nfs mount by by az vmruuning-commands"
# コンピュートノード#1のみ実施
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-1 --command-id RunShellScript --scripts "sudo mkdir -p /mnt/share"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-1 --command-id RunShellScript --scripts "sudo chown $USERNAME:$USERNAME /mnt/share"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-1 --command-id RunShellScript --scripts "sudo mount -t nfs ${pbsmountip}:/mnt/share /mnt/share"
for count in $(seq 2 $MAXVM) ; do
# コンピュートノード#1をマウント
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-"${count}" --command-id RunShellScript --scripts "sudo mkdir -p /mnt/share"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-"${count}" --command-id RunShellScript --scripts "sudo chown $USERNAME:$USERNAME /mnt/share"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-"${count}" --command-id RunShellScript --scripts "sudo mount -t nfs ${pbsmountip}:/mnt/share /mnt/share"
done
else
echo "pbsnode: confuguring nfs mount by ssh"
# pbsbmipが空でなければSSHでマウント情報の取得
echo "${VMPREFIX}-1: $pbsvmip"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${pbsvmip}" 'sudo showmount -e'
echo "${VMPREFIX}-1 to $MAXVM: mounting ${VMPREFIX}-pbs /mnt/share"
parallel -a ipaddresslist "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo mkdir -p /mnt/share""
parallel -a ipaddresslist "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo chown $USERNAME:$USERNAME /mnt/share""
parallel -a ipaddresslist "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo mount -t nfs ${pbsmountip}:/mnt/share /mnt/share""
# vm1ipが空でなければSSHでマウント情報の取得
echo "${VMPREFIX}-1: $vm1ip"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${vm1ip}" 'sudo showmount -e'
echo "${VMPREFIX}-2 to $MAXVM: mounting ${VMPREFIX}-1 /mnt/resource"
parallel -a ipaddresslist-tmp "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo mkdir -p /mnt/resource""
parallel -a ipaddresslist-tmp "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo chown $USERNAME:$USERNAME /mnt/resource""
parallel -a ipaddresslist-tmp "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo mount -t nfs ${mountip}:/mnt/resource /mnt/resource""
fi
echo "end of PBS mount check"
fi
rm ./ipaddresslist-tmp
echo "end of start command"
;;
startvm )
# PBSノードの存在チェック
osdiskidpbs=$(az vm show -g $MyResourceGroup --name ${VMPREFIX}-pbs --query storageProfile.osDisk.managedDisk.id -o tsv)
# VM # $2 起動開始
echo "starting VM ${VMPREFIX}-$2"
az vm start -g $MyResourceGroup --name ${VMPREFIX}-"$2" -o none &
echo "checking VM public ip"
# ダイナミックの場合(デフォルト)、再度IPアドレスリストを作成しなおす
# コンピュートノードVM#1のパブリックIPが同じならスキップする
vmip=$(az vm show -d -g $MyResourceGroup --name ${VMPREFIX}-"$2" --query publicIps -o tsv)
existvmip=$(sed -n "${2}"P ./ipaddresslist)
echo "new ${VMPREFIX}-1's IP: $vm1ip"
# 置換実施
if [ "$existvmip" != "$vmip" ]; then
echo "making new vm $2 ipaddress replace in the list"
sed "$2c $vmip" ./ipaddresslist
echo "new ipaddress list"
cat ./ipaddresslist
else
echo "not canage vm $2 ipaddress list"
fi
# コンピュートノードVM#1のマウントするプライベートIPの取得
mountip=$(az vm show -g $MyResourceGroup --name ${VMPREFIX}-1 -d --query privateIps -o tsv)
echo "${VMPREFIX}-1: nfs exports ip: $mountip"
checkssh=$(ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i "${SSHKEYDIR}" -t $USERNAME@"${vmip}" "uname")
# インターネットからアクセス可能であれば、SSHで高速に設定する
if [ -z "$vmip" ]; then
# vmipがパブリックIPが空でIPアドレスが取得できなければ、az cliでの取得
echo "${VMPREFIX}-1: configuring nfs mount by az vmruuning-commands"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-"$2" --command-id RunShellScript --scripts "sudo mkdir -p /mnt/resource"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-"$2" --command-id RunShellScript --scripts "sudo chown $USERNAME:$USERNAME /mnt/resource"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-"$2" --command-id RunShellScript --scripts "sudo mount $DEBUG -t nfs ${mountip}:/mnt/resource /mnt/resource"
else
echo "${VMPREFIX}-$2: mounting ${VMPREFIX}-$2 /mnt/resource"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${vmip}" -t -t "sudo mkdir -p /mnt/resource"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${vmip}" -t -t "sudo chown $USERNAME:$USERNAME /mnt/resource"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${vmip}" -t -t "sudo mount $DEBUG -t nfs ${mountip}:/mnt/resource /mnt/resource"
fi
echo "end of starting up computing nodes"
# PBSノードがなければ終了
if [ -z "$osdiskidpbs" ]; then
echo "no PBS node here!"
exit 0
fi
# PBSノード:マウント設定
echo "pbsnode: nfs server @ ${VMPREFIX}-pbs"
# PBSノード:名前取得
pbsvmname=$(az vm show -d -g $MyResourceGroup --name ${VMPREFIX}-pbs --query name -o tsv)
# PBSノード:グローバルIPアドレス取得
pbsvmip=$(az vm show -d -g $MyResourceGroup --name ${VMPREFIX}-pbs --query publicIps -o tsv)
echo "${VMPREFIX}-pbs's public ip: $pbsvmip"
# PBSノード:マウント向けプライベートIPアドレス取得
pbsmountip=$(az vm show -g $MyResourceGroup --name ${VMPREFIX}-pbs -d --query privateIps -otsv)
echo "${VMPREFIX}-pbs's exports ip: $pbsmountip"
# インターネットからアクセス可能であれば、SSHで高速に設定する
if [ -n "$pbsvmname" ]; then
# vm1ipが空なら、IPアドレスが取得できなければ、az cliでの取得
if [ -z "$pbsvmip" ]; then
echo "pbsnode: confuguring nfs mount by by az vmruuning-commands"
# コンピュートノード# $2 実施: PBS
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-"$2" --command-id RunShellScript --scripts "sudo mkdir -p /mnt/share"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-"$2"--command-id RunShellScript --scripts "sudo chown $USERNAME:$USERNAME /mnt/share"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-"$2" --command-id RunShellScript --scripts "sudo mount $DEBUG -t nfs ${pbsmountip}:/mnt/share /mnt/share"
else
echo "pbsnode: confuguring nfs mount by ssh"
# pbsbmipが空でなければSSHでマウント情報の取得
echo "${VMPREFIX}-1: $pbsvmip"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${pbsvmip}" 'sudo showmount -e'
echo "${VMPREFIX}-1 to $MAXVM: mounting ${VMPREFIX}-pbs /mnt/share"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${vmip}" -t -t "sudo mkdir -p /mnt/share"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${vmip}" -t -t "sudo chown $USERNAME:$USERNAME /mnt/share"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${vmip}" -t -t "sudo mount $DEBUG -t nfs ${pbsmountip}:/mnt/share /mnt/share"
fi
echo "end of PBS mount check"
fi
rm ./ipaddresslist-tmp
echo "end of start command"
;;
stop )
for count in $(seq 1 $MAXVM) ; do
echo "stoping VM $count"
az vm deallocate -g $MyResourceGroup --name ${VMPREFIX}-"${count}" &
done
;;
stop-all )
for count in $(seq 1 $MAXVM) ; do
echo "stoping VM $count"
az vm deallocate -g $MyResourceGroup --name ${VMPREFIX}-"${count}" &
done
echo "stoping PBS VM"
az vm deallocate -g $MyResourceGroup --name ${VMPREFIX}-pbs &
echo "stoping login VM"
az vm deallocate -g $MyResourceGroup --name ${VMPREFIX}-login &
# OSディスクタイプ変更: Standard_LRS
azure_sku1="Standard_LRS"
echo "converting computing node OS disk"
parallel -v -a ./tmposdiskidlist "az disk update --sku ${azure_sku1} --ids {}"
# Dataディスクタイプ変更: Standard_LRS
echo "converting PBS node data disk"
az vm show -g $MyResourceGroup --name ${VMPREFIX}-pbs --query storageProfile.dataDisks[*].managedDisk -o tsv | awk -F" " '{print $2}' | xargs -I{} az disk update --sku ${azure_sku1} --ids {}
echo "converting compute node #1 data disk"
az vm show -g $MyResourceGroup --name ${VMPREFIX}-1 --query storageProfile.dataDisks[*].managedDisk -o tsv | awk -F" " '{print $2}' | xargs -I{} az disk update --sku ${azure_sku1} --ids {}
;;
stopvm )
echo "コマンドシンタクス:VM#2を停止する場合 ./$CMDNAME stopvm 2"
echo "stoping VM $2"
az vm deallocate -g $MyResourceGroup --name ${VMPREFIX}-"$2" &
;;
stopvms )
echo "コマンドシンタクス:VM#2,3,4を停止する場合 ./$CMDNAME stopvm 2 4"
echo "stoping VM $2 $3"
for count in $(seq "$2" "$3") ; do
echo "stoping VM $count"
az vm deallocate -g $MyResourceGroup --name ${VMPREFIX}-"${count}" &
done
;;
list )
echo "listng running/stopped VM"
az vm list -g $MyResourceGroup -d -o table
echo "nfs server vm status"
# vm1state=$(az vm show -d -g $MyResourceGroup --name ${VMPREFIX}-1 --query powerState)
vm1ip=$(az vm show -d -g $MyResourceGroup --name ${VMPREFIX}-1 --query publicIps -o tsv)
pbsvmip=$(az vm show -d -g $MyResourceGroup --name ${VMPREFIX}-pbs --query publicIps -o tsv)
# PBSノードのパブリックIPアドレスの判定
if [ -z "$pbsvmip" ]; then
echo "no PBS node here! checking only compute nodes."
# コンピュートノードのみのチェック
count=0
checkssh=$(ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i "${SSHKEYDIR}" -t $USERNAME@"${vm1ip}" "uname")
if [ -n "$checkssh" ]; then
echo "${VMPREFIX}-1: nfs server status"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${vm1ip}" 'sudo showmount -e'
echo "nfs client mount status"
for count in $(seq 2 $MAXVM); do
line=$(sed -n "${count}"P ./ipaddresslist)
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" -t -t $USERNAME@"${line}" "echo '########## host: ${VMPREFIX}-${count} ##########'"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" -t -t $USERNAME@"${line}" "df | grep '/mnt/'"
done
else
# SSHできないのでaz vm run-commandでの情報取得
echo "az vm run-command: nfs server status"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-1 --command-id RunShellScript --scripts "sudo showmount -e"
echo "nfs client mount status:=======1-2 others: skiped======="
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-1 --command-id RunShellScript --scripts "df | grep /mnt/"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-2 --command-id RunShellScript --scripts "df | grep /mnt/"
fi
# コンピュートノードVM#1のマウントだけ完了し、コマンド完了
echo "end of list command"
exit 0
fi
# PBSノード、コンピュートノードのNFSマウント確認
count=0
checkssh=$(ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i "${SSHKEYDIR}" -t $USERNAME@"${vm1ip}" "uname")
checkssh2=$(ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i "${SSHKEYDIR}" -t $USERNAME@"${pbsvmip}" "uname")
if [ -n "$checkssh" ] && [ -n "$checkssh2" ]; then
echo "${VMPREFIX}-pbs: nfs server status"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${pbsvmip}" 'sudo showmount -e'
echo "${VMPREFIX}-1: nfs server status"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${vm1ip}" 'sudo showmount -e'
echo "nfs client mount status"
for count in $(seq 2 $MAXVM); do
line=$(sed -n "${count}"P ./ipaddresslist)
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" -t -t $USERNAME@"${line}" "echo '########## host: ${VMPREFIX}-${count} ##########'"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" -t -t $USERNAME@"${line}" "df | grep '/mnt/'"
done
else
echo "az vm run-command: nfs server status"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-pbs --command-id RunShellScript --scripts "sudo showmount -e"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-1 --command-id RunShellScript --scripts "sudo showmount -e"
echo "nfs client mount status:=======1-2 others: skiped======="
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-1 --command-id RunShellScript --scripts "df | grep /mnt/"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-2 --command-id RunShellScript --scripts "df | grep /mnt/"
fi
;;
delete )
if [ -f ./tmposdiskidlist ]; then rm ./tmposdiskidlist; fi
for count in $(seq 1 $MAXVM) ; do
disktmp=$(az vm show -g $MyResourceGroup --name ${VMPREFIX}-"${count}" --query storageProfile.osDisk.managedDisk.id -o tsv)
echo "$disktmp" >> tmposdiskidlist
done
echo "deleting compute VMs"
seq 1 $MAXVM | parallel "az vm delete -g $MyResourceGroup --name ${VMPREFIX}-{} --yes &"
numvm=$(cat ./vmlist | wc -l)
checkpbs=$(grep pbs ./vmlist)
if [ -n "$checkpbs" ]; then
# no pbs
while [ $((numvm)) -gt 2 ]; do
echo "sleep 30" && sleep 30
echo "current running VMs: $numvm"
az vm list -g $MyResourceGroup | jq '.[] | .name' | grep ${VMPREFIX} > ./vmlist
numvm=$(cat ./vmlist | wc -l)
done
echo "deleted all compute VMs"
else
# pbs node existing
while [ $((numvm)) -gt 0 ]; do
echo "sleep 30" && sleep 30
echo "current running VMs: $numvm"
az vm list -g $MyResourceGroup | jq '.[] | .name' | grep ${VMPREFIX} > ./vmlist
numvm=$(cat ./vmlist | wc -l)
done
fi
echo "deleted all compute VMs. PBS and login node are existing"
echo "deleting disk"
parallel -a tmposdiskidlist "az disk delete --ids {} --yes"
sleep 10
# STATICMAC が true であればNIC、パブリックIPを再利用する
if [ "$STATICMAC" == "true" ] || [ "$STATICMAC" == "TRUE" ]; then
echo "keep existing nic and public ip"
else
echo "deleting nic"
seq 1 $MAXVM | parallel "az network nic delete -g $MyResourceGroup --name ${VMPREFIX}-{}VMNic"
echo "deleting public ip"
seq 1 $MAXVM | parallel "az network public-ip delete -g $MyResourceGroup --name ${VMPREFIX}-{}PublicIP"
fi
echo "detele data disk"
az disk delete -g $MyResourceGroup --name ${VMPREFIX}-1-disk0 --yes
echo "current running VMs: ${numvm}"
# ファイル削除
rm ./ipaddresslist
rm ./tmposdiskidlist
rm ./vmlist
rm ./nodelist
;;
delete-all )
if [ -f ./tmposdiskidlist ]; then
rm ./tmposdiskidlist
fi
for count in $(seq 1 $MAXVM) ; do