-
Notifications
You must be signed in to change notification settings - Fork 0
/
hpcbmtenvcreate-v2p2.sh
1368 lines (1356 loc) · 83.7 KB
/
hpcbmtenvcreate-v2p2.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
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
curl -s https://ifconfig.io > tmpip #利用しているクライアントのグローバルIPアドレスを取得
echo `curl -s https://ipinfo.io/ip` >> tmpip #代替サイトでグローバルIPアドレスを取得
curl -s https://inet-ip.info >> tmpip #代替サイトでグローバルIPアドレスを取得
sed -i -e '/^$/d' tmpip > /dev/null
LIMITEDIP="$(cat tmpip | head -n 1)/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"
# MyNic="cfdbmt-nic"
IMAGE="OpenLogic:CentOS-HPC:7_8:latest" #Azure URNフォーマット。OpenLogic:CentOS-HPC:8_1:latest
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
# 必要なパッケージ。Ubuntuの場合、以下のパッケージが必要
#sudo apt install -y parallel jq curl
DEBUG="" #"-v"
# コマンド名取得
CMDNAME=`basename $0`
# コマンドオプションエラー処理
if [ $# -ne 1 ]; then
echo "実行するには1個の引数が必要です。" 1>&2
echo "create,delete,start,stop,list,remount,pingpong,addlogin,updatensg,privatenw,publicnw の引数を一つ指定する必要があります。" 1>&2
echo "1. create コマンド: コンピュートノードを作成します" 1>&2
echo "2. addlogin コマンド: login, PBSノードを作成します" 1>&2
echo "3. privatenw コマンド: コンピュートノード、PBSノードからグローバルIPアドレスを除きます" 1>&2
echo "stop コマンド: すべてのコンピュートノードを停止します。" 1>&2
exit 1
fi
# SSH鍵チェック。なければ作成
if [ ! -f "./${VMPREFIX}" ] || [ ! -f "./${VMPREFIX}.pub" ] ; then
ssh-keygen -f ./${VMPREFIX} -m pem -t rsa -N "" -b 4096
fi
# SSH秘密鍵ファイルのディレクトリ決定
tmpfile=$(stat ./${VMPREFIX} -c '%a')
case $tmpfile in
600 )
SSHKEYDIR="./${VMPREFIX}"
;;
7** )
cp ./${VMPREFIX} ~/.ssh/
chmod 600 ~/.ssh/${VMPREFIX}
SSHKEYDIR="~/.ssh/${VMPREFIX}"
;;
esac
echo "SSHKEYDIR: $SSHKEYDIR"
### ログイン処理
# サブスクリプションが複数ある場合は指定しておく
#az account set -s <Subscription ID or name>
# サービスプリンシパルの利用も可能以下のパラメータとログイン処理を有効にすること
#azure_name="uuid"
#azure_password="uuid"
#azure_tenant="uuid"
#az login --service-principal --username ${azure_name} --password ${azure_password} --tenant ${azure_tenant} --output none
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
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
# 可用性セット作成。既存のものがあれば利用する
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"
# az network nic create --accelerated-networking true --name $MyNic-$count --resource-group $MyResourceGroup --vnet-name $MyNetwork --subnet $MySubNetwork --network-security>
echo "creating VM # $count"
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
# vmlist 作成
while [ $((numvm)) -lt $((MAXVM)) ]; do
echo "sleep 30" && sleep 30
az vm list -g $MyResourceGroup | jq '.[] | .name' | grep ${VMPREFIX} > ./vmlist
numvm=$(cat ./vmlist | wc -l)
done
# ipaddresslist 作成
echo "careating IP Address list"
for count in $(seq 1 $MAXVM) ; do
echo "VM $count: ${VMPREFIX}-$count"
unset ipaddresstmp
ipaddresstmp=$(az vm show -d -g $MyResourceGroup --name ${VMPREFIX}-${count} --query publicIps -o tsv)
echo "ip: $ipaddresstmp"
echo $ipaddresstmp >> ipaddresslist
done
echo "ipaddresslist file contents"
cat ./ipaddresslist
sed -i -e '/^$/d' ./ipaddresslist
numip=$(cat ./ipaddresslist | wc -l)
if [ $((numip)) -ne $((MAXVM)) ]; then
echo "error!: you can not get all ip address list. please retry later."
exit 1
fi
# 永続ディスクが必要な場合に設定可能
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=$(cat ./ipaddresslist | head -n 1)
for count in `seq 1 20`; do
checkssh=$(ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 5' -i ${SSHKEYDIR} -t $USERNAME@${vm1ip} "uname")
if [ ! -z "$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 htop && echo '/mnt/resource *(rw,no_root_squash,async)' >> /etc/exports"
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"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-1 --command-id RunShellScript --scripts "sudo systemctl enable rpcbind && sudo systemctl enable nfs"
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 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"
ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@${vm1ip} -t -t "sudo systemctl enable rpcbind && sudo systemctl enable nfs"
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 $DEBUG -a ipaddresslist-tmp "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo yum install --quiet -y nfs-utils epel-release htop""
parallel $DEBUG -a ipaddresslist-tmp "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo mkdir -p /mnt/resource""
parallel $DEBUG -a ipaddresslist-tmp "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo chown $USERNAME:$USERNAME /mnt/resource""
parallel $DEBUG -a ipaddresslist-tmp "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo mount $DEBUG -t nfs ${mountip}:/mnt/resource /mnt/resource""
# NFSサーバ・マウント設定
rm ./ipaddresslist-tmp
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 [ ! -z "$checkssh" ]; then
break
fi
echo "waiting sshd @ ${VMPREFIX}-${count}: $checkssh sleep 10" && sleep 10
done
if [ ! -z "$checkssh" ]; then
echo "${VMPREFIX}-2 to ${MAXVM}: setting by ssh command"
ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@${line} -t -t "sudo yum install --quiet -y nfs-utils epel-release 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}: 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 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 $DEBUG -a ipaddresslist "scp -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} ./${VMPREFIX} $USERNAME@{}:/home/$USERNAME/.ssh/${VMPREFIX}"
parallel $DEBUG -a ipaddresslist "scp -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} ./${VMPREFIX} $USERNAME@{}:/home/$USERNAME/.ssh/id_rsa"
parallel $DEBUG -a ipaddresslist "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} $USERNAME@{} -t -t "chmod 600 /home/$USERNAME/.ssh/id_rsa""
parallel $DEBUG -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
# ホストファイル事前バックアップ(PBSノード追加設定向け)
parallel $DEBUG -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 $DEBUG -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 $DEBUG -a ipaddresslist "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo mkdir -p /mnt/share""
parallel $DEBUG -a ipaddresslist "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo chown $USERNAME:$USERNAME /mnt/share""
parallel $DEBUG -a ipaddresslist "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo mount $DEBUG -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 hostfile"
fi
if [ -f ./nodelist ]; then
rm ./nodelist
echo "recreating a new nodelist"
fi
# vmlist 作成
numvm=1
while [ $((numvm)) -lt $((MAXVM)) ]; do
echo "sleep 30" && sleep 30
az vm list -g $MyResourceGroup | jq '.[] | .name' | grep ${VMPREFIX} > ./vmlist
numvm=$(cat ./vmlist | wc -l)
done
echo "show current vmlist: `cat ./vmlist`"
# ホストファイル作成準備:プライベートIPアドレス取得
for count in $(seq 1 $MAXVM) ; do
nodelist=$(az vm show -g $MyResourceGroup --name ${VMPREFIX}-${count} -d --query privateIps -o tsv)
echo $nodelist >> nodelist
done
# ログインノードプライベートIPアドレス取得
loginprivateip=$(az vm show -g $MyResourceGroup --name ${VMPREFIX}-login -d --query privateIps -o tsv)
echo "$loginprivateip" >> nodelist
pbsprivateip=$(az vm show -g $MyResourceGroup --name ${VMPREFIX}-pbs -d --query privateIps -o tsv)
echo "$pbsprivateip" >> nodelist
echo "show current nodelist: `cat ./nodelist`"
# ホストファイル作成
paste ./nodelist ./vmlist > ./tmphostsfile
# ダブルクォーテーション削除
sed -i -e "s/\"//g" ./tmphostsfile
# ファイルの重複行削除。列は2列まで想定
cat ./tmphostsfile | awk '!colname[$1]++{print $1,$2}' >> ./hostsfile
cat ./hostsfile
# テンポラリファイル削除
rm ./tmphostsfile
### ===========================================================================
# PBSノード:ホストファイル転送・更新
checkssh=$(ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} -t $USERNAME@${pbsvmip} "uname")
if [ ! -z "$checkssh" ]; then
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 /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 [ ! -z "$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 [ ! -z "$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 [ ! -z "$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
# ログインノード経由で設定
line2=$(sed -n ${count}P ./nodelist)
checkssh2=$(ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} $USERNAME@${loginvmip} -t -t "uname")
if [ ! -z "$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 count in `seq 1 $MAXVM`; do
# ログインノードへはホストファイル転送済み
echo "コンピュートノード: az: ホストファイル転送 login to compute node"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-${count} --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}-${count} --command-id RunShellScript --scripts "sudo cp /etc/hosts.original /etc/hosts"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-${count} --command-id RunShellScript --scripts "sudo cp /home/$USERNAME/hostsfile /etc/hosts"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-${count} --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 $DEBUG -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
rm ./md5executionremote
rm ./md5executionremote2
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 cnt in `seq 1 3`; do
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
rm ./md5executionremote
rm ./md5executionremote2
# openPBSクライアント:インストール
echo "confuguring all compute nodes"
parallel $DEBUG -a ipaddresslist "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo yum install --quiet -y hwloc-libs libICE libSM""
parallel $DEBUG -a ipaddresslist "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo yum install --quiet -y libnl3""
echo "installing libnl3"
parallel $DEBUG -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 $DEBUG -a ipaddresslist "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo rpm -aq | grep openpbs""
parallel $DEBUG -a ipaddresslist "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo /opt/pbs/libexec/pbs_habitat""
parallel $DEBUG -a ipaddresslist "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo /opt/pbs/libexec/pbs_postinstall""
# pbs.confファイル生成
parallel $DEBUG -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 $DEBUG -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 $DEBUG -a ipaddresslist "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo cat /etc/pbs.conf""
# openPBSクライアント:パーミッション設定
parallel $DEBUG -a ipaddresslist "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo chmod 4755 /opt/pbs/sbin/pbs_iff""
parallel $DEBUG -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 $DEBUG -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 $DEBUG -a ipaddresslist "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo /etc/init.d/pbs start""
vm1ip=$(cat ./ipaddresslist | head -n 1)
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 $DEBUG -a ipaddresslist "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 30' -i ${SSHKEYDIR} $USERNAME@{} -t -t 'echo 'source /etc/profile.d/pbs.sh' >> ~/.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"
osdiskidpbs=$(az vm show -g $MyResourceGroup --name ${VMPREFIX}-pbs --query storageProfile.osDisk.managedDisk.id -o tsv)
# az vm show -g $MyResourceGroup --name ${VMPREFIX}-pbs --query storageProfile.osDisk.managedDisk.id -o table
if [ ! -z "$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 [ ! -z "$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=$(cat ./ipaddresslist | head -n 1)
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 $DEBUG -a ipaddresslist-tmp "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo mkdir -p /mnt/resource""
parallel $DEBUG -a ipaddresslist-tmp "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo chown $USERNAME:$USERNAME /mnt/resource""
parallel $DEBUG -a ipaddresslist-tmp "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@{} -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 [ ! -z "$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 $DEBUG -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 $DEBUG -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 $DEBUG -a ipaddresslist "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo mkdir -p /mnt/share""
parallel $DEBUG -a ipaddresslist "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo chown $USERNAME:$USERNAME /mnt/share""
parallel $DEBUG -a ipaddresslist "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo mount $DEBUG -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 $DEBUG -a ipaddresslist-tmp "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo mkdir -p /mnt/resource""
parallel $DEBUG -a ipaddresslist-tmp "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo chown $USERNAME:$USERNAME /mnt/resource""
parallel $DEBUG -a ipaddresslist-tmp "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo mount $DEBUG -t nfs ${mountip}:/mnt/resource /mnt/resource""
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 stop -g $MyResourceGroup --name ${VMPREFIX}-${count} &
done
;;
stop-all )
for count in $(seq 1 $MAXVM) ; do
echo "stoping VM $count"
az vm stop -g $MyResourceGroup --name ${VMPREFIX}-${count} &
done
echo "stoping PBS VM"
az vm stop -g $MyResourceGroup --name ${VMPREFIX}-pbs &
echo "stoping login VM"
az vm stop -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 {}
;;
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 [ ! -z "$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}-: 2 - ${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 [ ! -z "$checkssh" -a ! -z "$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 [ ! -z "$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
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"
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
disktmp=$(az vm show -g $MyResourceGroup --name ${VMPREFIX}-${count} --query storageProfile.osDisk.managedDisk.id -o tsv)
echo $disktmp >> tmposdiskidlist
done
disktmp=$(az vm show -g $MyResourceGroup --name ${VMPREFIX}-pbs --query storageProfile.osDisk.managedDisk.id -o tsv)
echo $disktmp >> tmposdiskidlist
disktmp=$(az vm show -g $MyResourceGroup --name ${VMPREFIX}-login --query storageProfile.osDisk.managedDisk.id -o tsv)
echo $disktmp >> tmposdiskidlist
echo "deleting compute VMs"
seq 1 $MAXVM | parallel "az vm delete -g $MyResourceGroup --name ${VMPREFIX}-{} --yes &"
echo "deleting pbs node"
az vm delete -g $MyResourceGroup --name ${VMPREFIX}-pbs --yes &
echo "deleting login node"
az vm delete -g $MyResourceGroup --name ${VMPREFIX}-login --yes &
numvm=$(cat ./vmlist | wc -l)
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
echo "deleting disk"
parallel -a tmposdiskidlist "az disk delete --ids {} --yes"
sleep 10
echo "deleting nic"
seq 1 $MAXVM | parallel "az network nic delete -g $MyResourceGroup --name ${VMPREFIX}-{}VMNic"
az network nic delete -g $MyResourceGroup --name ${VMPREFIX}-pbsVMNic
az network nic delete -g $MyResourceGroup --name ${VMPREFIX}-loginVMNic
echo "deleting public ip"
seq 1 $MAXVM | parallel "az network public-ip delete -g $MyResourceGroup --name ${VMPREFIX}-{}PublicIP"
az network public-ip delete -g $MyResourceGroup --name ${VMPREFIX}-pbsPublicIP
az network public-ip delete -g $MyResourceGroup --name ${VMPREFIX}-loginPublicIP
echo "detelting data disk"
az disk delete -g $MyResourceGroup --name ${VMPREFIX}-1-disk0 --yes
az disk delete -g $MyResourceGroup --name ${VMPREFIX}-pbs-disk0 --yes
echo "current running VMs: ${numvm}"
# ファイル削除
rm ./ipaddresslist
rm ./tmposdiskidlist
rm ./vmlist
rm ./config
rm ./fullpingpong.sh
rm ./pingponlist
rm ./nodelist
rm ./hostsfile
rm ./loginvmip
rm ./pbsvmip
rm ./md5*
rm ./hostsfile
rm ./openpbs*
rm ./pbsprivateip
rm ./loginpribateip
rm ./tmpcheckhostsfile
;;
remount )
# mounting nfs server from compute node.
numvm=$(cat ./ipaddresslist | wc -l)
if [ -f ./ipaddresslist ]; then
# コマンド実行判断
vm1ip=$(az vm show -d -g $MyResourceGroup --name ${VMPREFIX}-1 --query publicIps -o tsv)
# |\\\|\\\|\\\vm1ip=$(head -1 ./ipaddresslist)
echo "${VMPREFIX}-1's IP: $ipaddresstmp"
# コンピュートノードVM#1:マウントプライベートIP
mountip=$(az vm show -g $MyResourceGroup --name ${VMPREFIX}-1 -d --query privateIps -otsv)
# PBSノード
pbsvmname=$(az vm show -d -g $MyResourceGroup --name ${VMPREFIX}-pbs --query name -o tsv)
# PBSノード:マウントプライベートIP
pbsmountip=$(az vm show -g $MyResourceGroup --name ${VMPREFIX}-pbs -d --query privateIps -otsv)
echo "current mounting status"
parallel $DEBUG -a ipaddresslist "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} -t -t $USERNAME@{} "df | grep '/mnt/resource'""
echo "${VMPREFIX}-1: $vm1ip"
ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@${ipaddresstmp} 'sudo showmount -e'
echo "${VMPREFIX}-2 to $MAXVM: mounting"
parallel $DEBUG -a ipaddresslist "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} -t -t $USERNAME@{} "sudo mkdir -p /mnt/resource""
parallel $DEUBG -a ipaddresslist "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} -t -t $USERNAME@{} "sudo chown $USERNAME:$USERNAME /mnt/resource""
parallel $DEBUG -a ipaddresslist "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} -t -t $USERNAME@{} "sudo mount -t nfs ${mountip}:/mnt/resource /mnt/resource""
# PBSノードが存在していれば、NFSマウントを実施
if [ ! -z "$pbsvmname" ]; then
parallel $DEBUG -a ipaddresslist "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} -t -t $USERNAME@{} "sudo mkdir -p /mnt/share""
parallel $DEBUG -a ipaddresslist "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} -t -t $USERNAME@{} "sudo chown $USERNAME:$USERNAME /mnt/share""
parallel $DEBUG -a ipaddresslist "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} -t -t $USERNAME@{} "sudo mount -t nfs ${pbsmountip}:/mnt/share""
fi
else
for count in $(seq 2 $MAXVM) ; do
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-${count} --command-id RunShellScript --scripts "sudo mount -t nfs ${mountip}:/mnt/resource /mnt/resource" &
done
echo "sleep 180" && sleep 180
for count in $(seq 1 $MAXVM) ; do
if [ ! -z "$pbsvmname" ]; then
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-${count} --command-id RunShellScript --scripts "sudo mount -t nfs ${pbdmountip}:/mnt/share /mnt/share" &
sleep 10
fi
done
fi
;;
pingpong )
# コマンド実行判断
vm1ip=$(az vm show -d -g $MyResourceGroup --name ${VMPREFIX}-1 --query publicIps -o tsv)
if [ -z "$vm1ip" ]; then
echo "pingpong function required internet access from this client"
exit 1
fi
# 初期設定:ファイル削除、ホストファイル作成
if [ -f ./nodelist ]; then
rm ./nodelist
fi
for count in $(seq 1 $MAXVM) ; do
nodelist=$(az vm show -g $MyResourceGroup --name ${VMPREFIX}-${count} -d --query privateIps -o tsv)
echo $nodelist >> nodelist
done
if [ -f ./pingponglist ]; then
rm ./pingponglist
fi
# ノードファイル作成
for NODE in `cat ./nodelist`; do
for NODE2 in `cat ./nodelist`; do
echo "$NODE,$NODE2" >> pingponglist
done
done
# fullpingpongコマンドスクリプト作成
rm ./fullpingpong.sh
cat <<'EOL' >> fullpingpong.sh
#!/bin/bash
IMPI_VERSION=2018.4.274
cp /home/$USER/* /mnt/resource/
cd /mnt/resource/
count=1
max=$(cat ./pingponglist | wc -l)
echo max: $max
# run pingpong
case $IMPI_VERSION in
2018* )
for count in `seq 1 $max`; do
line=$(sed -n ${count}P ./pingponglist)
echo "############### ${line} ###############"; >> result
/opt/intel/impi/${IMPI_VERSION}/intel64/bin/mpirun -hosts $line -ppn 1 -n 2 -env I_MPI_FABRICS=shm:ofa /opt/intel/impi/${IMPI_VERSION}/bin64/IMB-MPI1 pingpong | grep -e ' 512 ' -e NODES -e usec; >> result
done
;;
esac
EOL
# ヒアドキュメントのルール上改行不可
rm ./config
cat <<'EOL' >> config
Host *
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
EOL
# fullpingpong実行
echo "pingpong: preparing files"
# vm1ip=$(head -1 ./ipaddresslist)
impidir=$(ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@${vm1ip} "ls /opt/intel/impi/")
cat ./pingponglist
scp -o StrictHostKeyChecking=no -i ${SSHKEYDIR} ./fullpingpong.sh $USERNAME${vm1ip}:/home/$USERNAME/
scp -o StrictHostKeyChecking=no -i ${SSHKEYDIR} ./pingponglist $USERNAME@${vm1ip}:/home/$USERNAME/
scp -o StrictHostKeyChecking=no -i ${SSHKEYDIR} ./fullpingpong.sh $USERNAME@${vm1ip}:/mnt/resource/
scp -o StrictHostKeyChecking=no -i ${SSHKEYDIR} ./pingponglist $USERNAME@${vm1ip}:/mnt/resource/
# SSH追加設定
cat ./ipaddresslist
echo "pingpong: copy passwordless settings"
seq 1 $MAXVM | parallel $DEBUG -a ipaddresslist "scp -o StrictHostKeyChecking=no -i ${SSHKEYDIR} ./config $USERNAME@{}:/home/$USERNAME/.ssh/config"
seq 1 $MAXVM | parallel $DEBUG -a ipaddresslist "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@{} -t -t "chmod 600 /home/$USERNAME/.ssh/config""
# コマンド実行
echo "pingpong: running pingpong for all compute nodes"
ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@${vm1ip} -t -t "rm /mnt/resource/result"
ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@${vm1ip} -t -t "bash /mnt/resource/fullpingpong.sh > /mnt/resource/result"
scp -o StrictHostKeyChecking=no -i ${SSHKEYDIR} $USERNAME@${vm1ip}:/mnt/resource/result ./
echo "ローカルのresultファイルを確認"
;;
#### ==========================================================================
# ログインノード、PBSノードを作成します。
addlogin )
# 既存ネットワークチェック
tmpsubnetwork=$(az network vnet subnet show -g $MyResourceGroup --name $MySubNetwork2 --vnet-name $MyNetwork --query id)
echo "current subnetowrk id: $tmpsubnetwork"
if [ -z "$tmpsubnetwork" ]; then
# mgmtサブネット追加
az network vnet subnet create -g $MyResourceGroup --vnet-name $MyNetwork -n $MySubNetwork2 --address-prefixes 10.0.1.0/24 --network-security-group $MyNetworkSecurityGroup -o table
fi
# ログインノード作成
echo "================== creating login node =================="
az vm create \
--resource-group $MyResourceGroup --location $Location \
--name ${VMPREFIX}-login \
--size Standard_D2a_v4 \
--vnet-name $MyNetwork --subnet $MySubNetwork2 \
--nsg $MyNetworkSecurityGroup --nsg-rule SSH \
--public-ip-address-allocation static \
--image $IMAGE \