-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhpcbmtenv.sh
2127 lines (2055 loc) · 117 KB
/
hpcbmtenv.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
# Repositry: https://github.com/hirtanak/hpcbmtenv
# Last update: 2021/5/7
SCRIPTVERSION=0.3.1
echo "SCRIPTVERSION: $SCRIPTVERSION - startup azure hpc delopment create script..."
### 基本設定
MyResourceGroup=tmcbmt01
Location=japaneast #southcentralus
VMPREFIX=tmcbmt01
VMSIZE=Standard_HB120rs_v2 #Standard_HC44rs, Standard_HB120rs_v3
PBSVMSIZE=Standard_D8as_v4
MAXVM=2 # 作成するコンピュートノード数
### ネットワーク設定
MyAvailabilitySet=${VMPREFIX}avset01 #HPCクラスターのVMサイズ別に異なる可用性セットが必要。自動生成するように変更したため、基本変更しない
MyNetwork=${VMPREFIX}-vnet01
MySubNetwork=compute
MySubNetwork2=management # ログインノード用サブネット
ACCELERATEDNETWORKING="--accelerated-networking true" # もし問題がある場合にはflaseで利用可能。コンピュートノードのみ対象 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
USERNAME=azureuser # ユーザ名: デフォルト azureuser
SSHKEYFILE="./${VMPREFIX}.pub" # SSH公開鍵ファイルを指定:デフォルトではカレントディレクトリを利用する
TAG=${VMPREFIX}=$(date "+%Y%m%d")
# 追加の永続ディスクが必要な場合、ディスクサイズ(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 echo "your linux distribution is: ubuntu";
sudo apt-get install -qq -y parallel jq curl || apt-get install -qq -y parallel jq curl
else echo "your linux distribution is: debian";
if [[ $(hostname) =~ [a-z]*-*-*-* ]]; then echo "skipping...due to azure cloud shell";
else sudo apt-get install -qq -y parallel jq curl || apt-get install -qq -y parallel jq curl; fi
fi
elif [ -e /etc/fedora-release ]; then 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 echo "your linux distribution is: Redhat or CentOS";
sudo yum install --quiet -y parallel jq curl || yum install -y parallel jq curl
fi
function getipaddresslist () {
# $1: vmlist
# $2: ipaddresslist
# $3: nodelist
# list-ip-addresses 作成
if [ -f ./vmlist ]; then rm ./vmlist; fi
if [ -f ./ipaddresslist ]; then rm ./ipaddresslist; fi
if [ -f ./nodelist ]; then rm ./nodelist; fi
echo "creating vmlist and ipaddresslist"
az vm list-ip-addresses -g $MyResourceGroup --query "[].virtualMachine[].{Name:name, PublicIp:network.publicIpAddresses[0].ipAddress, PrivateIPAddresses:network.privateIpAddresses[0]}" -o tsv > tmpfile
for count in $(seq 1 10); do
if [ -s tmpfile ]; then
break
else
az vm list-ip-addresses -g $MyResourceGroup --query "[].virtualMachine[].{Name:name, PublicIp:network.publicIpAddresses[0].ipAddress, PrivateIPAddresses:network.privateIpAddresses[0]}" -o tsv > tmpfile
echo "getting list-ip-addresse... sleep 4" && sleep 4
fi
done
# pbs, loging, cyclecloud など削除
grep "${VMPREFIX}-[1-99]" ./tmpfile > ./tmpfile2
# 自然番号順にソート
sort -V ./tmpfile2 > tmpfile3
echo "az vm list-ip-addresses..."
cat ./tmpfile3
# Check num of parameters.
if [ $# -gt 4 ]; then echo "error!. you can use 3 parameters."; exit 1; fi
if [ "$1" = "vmlist" ]; then
# vmlist 作成: $1
echo "creating vmlist"
cut -f 1 ./tmpfile3 > vmlist
# vmlist チェック
numvm=$(cat ./vmlist | wc -l)
if [ $((numvm)) -eq $((MAXVM)) ]; then
echo "number of vmlist and maxvm are matched."
else
echo "number of vmlist and maxvm are unmatched!"
fi
fi
if [ "$2" = "ipaddresslist" ]; then
# ipaddresslist 作成: $2
echo "careating IP Address list"
cut -f 2 ./tmpfile3 > ipaddresslist
echo "ipaddresslist file contents"
cat ./ipaddresslist
numip=$(cat ./ipaddresslist | wc -l)
# ipaddresslist チェック
if [ $((numip)) -eq $((MAXVM)) ]; then
echo "number of ipaddresslist and maxvm are matched."
else
echo "number of ipaddresslist and maxvm are unmatched!"
fi
fi
if [ $# -eq 3 ] && [ "$3" = "nodelist" ]; then
# nodelist 作成: $3
echo "careating nodelist"
cut -f 3 ./tmpfile3 > nodelist
echo "nodelist file contents"
cat ./nodelist
numnd=$(cat ./nodelist | wc -l)
# nodelist チェック
if [ $((numnd)) -eq $((MAXVM)) ]; then
echo "number of nodelist and maxvm are matched."
else
echo "number of nodelist and maxvm are unmatched!"
fi
fi
# テンポラリファイル削除
rm ./tmpfile
rm ./tmpfile2
rm ./tmpfile3
}
function mountdirectory () {
# $1: vm: vm1 or pbs
# $2: directory: /mnt/resource/scrach or /mnt/share
# requirement, ipaddresslist
# case1: vm1, /mnt/resource/scratch, case2: pbs /mnt/share
directory="$2"
if [ "$1" = vm1 ] && [ -z "$2" ]; then
directory="/mnt/resource/scratch"
fi
if [ "$1" = pbs ] && [ -z "$2" ]; then
directory="/mnt/share"
fi
echo "directory: $directory"
if [ ! -f ./ipaddresslist ]; then
echo "error!. ./ipaddresslist is not found!"
getipaddresslist vmlist ipaddresslist nodelist
fi
case $1 in
vm1 )
# コマンド実行判断
vm1ip=$(az vm show -d -g $MyResourceGroup --name ${VMPREFIX}-1 --query publicIps -o tsv)
echo "${VMPREFIX}-1's IP: $vm1ip"
# コンピュートノードVM#1:マウント用プライベートIP
mountip=$(az vm show -g $MyResourceGroup --name ${VMPREFIX}-1 -d --query privateIps -otsv)
echo "checking ssh access for vm1..."
for count in $(seq 1 10); do
checkssh=(ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" -t "$USERNAME"@"${vm1ip}" "uname")
if [ -n "$checkssh" ]; then
break
else
checkssh=(ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" -t "$USERNAME"@"${vm1ip}" "uname")
echo "getting ssh connection. sleep 2" && sleep 2
fi
done
if [ -n "$checkssh" ]; then
echo "${VMPREFIX}-1: $vm1ip - mount setting by ssh"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" -t -t $USERNAME@"${vm1ip}" "sudo mkdir -p ${directory}"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" -t -t $USERNAME@"${vm1ip}" "sudo chown $USERNAME:$USERNAME ${directory}"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" -t -t $USERNAME@"${vm1ip}" "sudo systemctl start rpcbind && sudo systemctl start nfs-server"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" -t -t $USERNAME@"${vm1ip}" 'sudo showmount -e'
# 1行目を削除したIPアドレスリストを作成
sed '1d' ./ipaddresslist > ./ipaddresslist-tmp
echo "${VMPREFIX}-2 to $MAXVM: mounting"
parallel -a ipaddresslist-tmp "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} -t -t $USERNAME@{} "sudo mkdir -p ${directory}""
parallel -a ipaddresslist-tmp "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} -t -t $USERNAME@{} "sudo chown $USERNAME:$USERNAME ${directory}""
parallel -a ipaddresslist-tmp "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} -t -t $USERNAME@{} "sudo mount -t nfs ${mountip}:${directory} ${directory}""
echo "current mounting status"
parallel -a ipaddresslist-tmp "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} -t -t $USERNAME@{} "df -h | grep ${directory}""
rm ./ipaddresslist-tmp
else
echo "vm1: mount setting by az vm run-command"
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}:${directory} ${directory}"
echo "sleep 60" && sleep 60
done
fi
;;
pbs )
# PBSノード:展開済みかチェック: pbsvmname=$(az vm show -d -g $MyResourceGroup --name ${VMPREFIX}-pbs --query name -o tsv)
pbsvmip=$(az vm show -d -g $MyResourceGroup --name ${VMPREFIX}-pbs --query publicIps -o tsv)
# PBSノード:マウントプライベートIP
pbsmountip=$(az vm show -g $MyResourceGroup --name ${VMPREFIX}-pbs -d --query privateIps -otsv)
echo "checking ssh access for pbs..."
for count in $(seq 1 10); do
checkssh=(ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" -t "$USERNAME"@"${pbsvmip}" "uname")
if [ -n "$checkssh" ]; then
break
else
checkssh=$(ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" -t "$USERNAME"@"${pbsvmip}" "uname")
echo "getting ssh connection. sleep 2" && sleep 2
fi
done
if [ -n "$checkssh" ]; then
echo "pbsnode: mount setting by ssh"
parallel -a ipaddresslist "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} -t -t $USERNAME@{} "sudo mkdir -p ${directory}""
parallel -a ipaddresslist "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} -t -t $USERNAME@{} "sudo chown $USERNAME:$USERNAME ${directory}""
parallel -a ipaddresslist "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} -t -t $USERNAME@{} "sudo mount -t nfs ${pbsmountip}:${directory} ${directory}""
echo "current mounting status"
parallel -a ipaddresslist "ssh -o StrictHostKeyChecking=no -i ${SSHKEYDIR} -t -t $USERNAME@{} "df -h | grep ${directory}""
else
echo "pbsnode: mount setting by az vm run-command"
for count in $(seq 1 $MAXVM) ; do
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-"${count}" --command-id RunShellScript --scripts "sudo mount -t nfs ${pbsmountip}:${directory} ${directory}"
echo "sleep 60" && sleep 60
done
fi
;;
esac
}
function checksshconnection () {
# $1: vm1, pbs, all
# requirement, ipaddresslist
# usecase: connected - Linux or, disconnected - nothing
case $1 in
vm1 )
vm1ip=$(az vm show -d -g $MyResourceGroup --name ${VMPREFIX}-1 --query publicIps -o tsv)
for cnt in $(seq 1 10); do
checkssh=$(ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" -t $USERNAME@"${vm1ip}" "uname")
if [ -n "$checkssh" ]; then
break
fi
echo "waiting sshd @ ${VMPREFIX}-${vm1ip}: sleep 5" && sleep 5
done
;;
pbs )
pbsvmip=$(az vm show -d -g $MyResourceGroup --name ${VMPREFIX}-pbs --query publicIps -o tsv)
for cnt in $(seq 1 10); do
checkssh=$(ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" -t $USERNAME@"${pbsvmip}" "uname")
if [ -n "$checkssh" ]; then
break
fi
echo "waiting sshd @ ${VMPREFIX}-${vm1ip}: sleep 5" && sleep 5
done
;;
all )
if [ -f ./checksshtmp ]; then rm ./checksshtmp; fi
for count in $(seq 1 $MAXVM); do
line=$(sed -n "${count}"P ./ipaddresslist)
for cnt in $(seq 1 10); do
checksshtmp=$(ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" -t $USERNAME@"${line}" "uname")
if [ -n "${checksshtmp}" ]; then
echo "${checksshtmp}" >> checksshtmp
break
fi
echo "waiting ssh connection @ ${VMPREFIX}-${count}: sleep 5" && sleep 5
done
done
;;
esac
}
function basicsettings () {
# 作成中。。。
# $1: vm1, pbs, login, all
# requirement, ipaddresslist
# locale, sudo, passwordless, ssh config
case $1 in
vm1 )
echo "vm1: all basic settings...."
vm1ip=$(az vm show -d -g $MyResourceGroup --name ${VMPREFIX}-1 --query publicIps -o tsv)
# SSHローケール設定変更
echo "configuring /etc/ssh/config locale setting"
locale=$(ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${vm1ip}" -t -t "grep 'LC_ALL=C' /home/$USERNAME/.bashrc")
if [ -z "$locale" ]; then
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${vm1ip}" -t -t "echo "export 'LC_ALL=C'" >> /home/$USERNAME/.bashrc"
else
echo "LC_ALL=C has arelady setting"
fi
# コンピュートノード:パスワードレス設定
echo "コンピュートノード: confugring passwordless settings"
scp -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" ./${VMPREFIX} $USERNAME@"${vm1ip}":/home/$USERNAME/.ssh/${VMPREFIX}
scp -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" ./${VMPREFIX} $USERNAME@"${vm1ip}":/home/$USERNAME/.ssh/id_rsa
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${vm1ip}" -t -t "chmod 600 /home/$USERNAME/.ssh/id_rsa"
scp -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" ./${VMPREFIX}.pub $USERNAME@"${vm1ip}":/home/$USERNAME/.ssh/${VMPREFIX}.pub
# SSH Config設定
if [ -f ./config ]; then rm ./config; fi
cat <<'EOL' >> config
Host *
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
EOL
scp -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" ./config $USERNAME@"${vm1ip}":/home/$USERNAME/.ssh/config
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${vm1ip}" -t -t "chmod 600 /home/$USERNAME/.ssh/config"
;;
pbs )
echo "pbs: all basic settings...."
pbsvmip=$(az vm show -d -g $MyResourceGroup --name ${VMPREFIX}-pbs --query publicIps -o tsv)
# SSHローケール設定変更
echo "configuring /etc/ssh/config locale setting"
locale=$(ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${pbsvmip}" -t -t "grep 'LC_ALL=C' /home/$USERNAME/.bashrc")
if [ -z "$locale" ]; then
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${pbsvmip}" -t -t "echo "export 'LC_ALL=C'" >> /home/$USERNAME/.bashrc"
else
echo "LC_ALL=C has arelady setting"
fi
# PBSノード:sudo設定
echo "PBSノード: sudo 設定"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${pbsvmip}" -t -t "sudo cat /etc/sudoers | grep $USERNAME" > sudotmp
sudotmp=$(cat ./sudotmp)
if [ -z "$sudotmp" ]; then
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${pbsvmip}" -t -t "echo "$USERNAME ALL=NOPASSWD: ALL" | sudo tee -a /etc/sudoers"
fi
unset sudotmp && rm ./sudotmp
# PBSノード:パスワードレス設定
echo "PBSノード: confugring passwordless settings"
scp -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" ./${VMPREFIX} $USERNAME@"${pbsvmip}":/home/$USERNAME/.ssh/${VMPREFIX}
scp -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" ./${VMPREFIX} $USERNAME@"${pbsvmip}":/home/$USERNAME/.ssh/id_rsa
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${pbsvmip}" -t -t "chmod 600 /home/$USERNAME/.ssh/id_rsa"
scp -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" ./${VMPREFIX}.pub $USERNAME@"${pbsvmip}":/home/$USERNAME/.ssh/${VMPREFIX}.pub
# SSH Config設定
if [ -f ./config ]; then rm ./config; fi
cat <<'EOL' >> config
Host *
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
EOL
scp -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" ./config $USERNAME@"${pbsvmip}":/home/$USERNAME/.ssh/config
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${pbsvmip}" -t -t "chmod 600 /home/$USERNAME/.ssh/config"
;;
login )
echo "login vm: all basic settings...."
loginvmip=$(az vm show -d -g $MyResourceGroup --name ${VMPREFIX}-login --query publicIps -o tsv)
# SSHローケール設定変更
echo "configuring /etc/ssh/config locale setting"
locale=$(ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${loginvmip}" -t -t "grep 'LC_ALL=C' /home/$USERNAME/.bashrc")
if [ -z "$locale" ]; then
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${loginvmip}" -t -t "echo "export 'LC_ALL=C'" >> /home/$USERNAME/.bashrc"
else
echo "LC_ALL=C has arelady setting"
fi
# ログインノード:パスワードレス設定
echo "ログインノード: confugring passwordless settings"
scp -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" ./${VMPREFIX} $USERNAME@"${loginvmip}":/home/$USERNAME/.ssh/${VMPREFIX}
scp -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" ./${VMPREFIX} $USERNAME@"${loginvmip}":/home/$USERNAME/.ssh/id_rsa
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${loginvmip}" -t -t "chmod 600 /home/$USERNAME/.ssh/id_rsa"
scp -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" ./${VMPREFIX}.pub $USERNAME@"${loginvmip}":/home/$USERNAME/.ssh/${VMPREFIX}.pub
# SSH Config設定
if [ -f ./config ]; then rm ./config; fi
cat <<'EOL' >> config
Host *
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
EOL
scp -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" ./config $USERNAME@"${loginvmip}":/home/$USERNAME/.ssh/config
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${loginvmip}" -t -t "chmod 600 /home/$USERNAME/.ssh/config"
;;
all )
# SSHローケール設定変更
echo "configuring /etc/ssh/config locale setting"
for count in $(seq 1 $MAXVM); do
line=$(sed -n "${count}"P ./ipaddresslist)
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
echo "${VMPREFIX}-1 to ${MAXVM}: sudo 設定"
for count in $(seq 1 $((MAXVM))); do
line=$(sed -n "${count}"P ./ipaddresslist)
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
for count in $(seq 1 $((MAXVM))); do
line=$(sed -n "${count}"P ./ipaddresslist)
# コンピュートノード:パスワードレス設定
echo "コンピュートノード: confugring passwordless settings"
scp -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" ./${VMPREFIX} $USERNAME@"${line}":/home/$USERNAME/.ssh/${VMPREFIX}
scp -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" ./${VMPREFIX} $USERNAME@"${line}":/home/$USERNAME/.ssh/id_rsa
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${line}" -t -t "chmod 600 /home/$USERNAME/.ssh/id_rsa"
scp -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" ./${VMPREFIX}.pub $USERNAME@"${line}":/home/$USERNAME/.ssh/${VMPREFIX}.pub
# SSH Config設定
if [ -f ./config ]; then rm ./config; fi
cat <<'EOL' >> config
Host *
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
EOL
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
;;
esac
}
case $1 in
create )
# 全体環境作成
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
# 可用性セットの処理
checkavset=$(az vm availability-set list-sizes --name ${VMPREFIX}avset01 -g $MyResourceGroup -o tsv | head -n 1 | cut -f 3)
if [ -z "$checkavset" ]; then
az vm availability-set create --name $MyAvailabilitySet -g $MyResourceGroup -l $Location --tags "$TAG" --output none
else
echo "checkavset : $checkavset - current cluster vmsize or no assignment or general sku."
echo "your VMSIZE: $VMSIZE"
# ${VMPREFIX}avset01: 同じVMサイズの場合、可用性セットを利用する
if [ ${VMSIZE} = "$checkavset" ]; then
# 既に avset01 が利用済みの場合で VMSIZE が異なれば、以下実行
echo "use same avset: ${VMPREFIX}avset01"
MyAvailabilitySet="${VMPREFIX}avset01"
else
# 可用性セット 1+2~10, 10クラスタ想定
for count in $(seq 2 10); do
checkavsetnext=$(az vm availability-set list-sizes --name ${VMPREFIX}avset0"${count}" -g $MyResourceGroup -o tsv | wc -l)
# 0 の場合、この可用性セットは利用されていない
if [ $((checkavsetnext)) -eq 0 ]; then
echo "${VMPREFIX}avset0${count} is nothing. assining a new avaiability set: ${VMPREFIX}avset0${count}"
MyAvailabilitySet="${VMPREFIX}avset0${count}"
az vm availability-set create --name "$MyAvailabilitySet" -g $MyResourceGroup -l $Location --tags "$TAG" --output none
break
# 1 の場合、可用性セットは利用中
elif [ $((checkavsetnext)) -eq 1 ]; then
echo "${VMPREFIX}avset0${count} has already used."
# 多数 の場合、一般SKUを利用。利用中か不明だが、既存可用性セットとして再利用可能
elif [ $((checkavsetnext)) -gt 5 ]; then
# check avset: ${VMPREFIX}avset01
checkavset2=$(az vm availability-set list-sizes --name ${VMPREFIX}avset01 -g $MyResourceGroup -o tsv | cut -f 3 | wc -l)
if [ $((checkavset2)) -gt 5 ]; then
echo "use existing availalibty set: ${VMPREFIX}avset01"
MyAvailabilitySet=${VMPREFIX}avset01
break
else
echo "${VMPREFIX}avset0${count} is belong to general sku."
MyAvailabilitySet="${VMPREFIX}avset0${count}"
az vm availability-set create --name "$MyAvailabilitySet" -g $MyResourceGroup -l $Location --tags "$TAG" --output none
break
fi
fi
# 未使用の場合、すべてのサイズがリストされる. ex. 379 この可用性セットは利用可能
done
fi
fi
# VM作成
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 with availability set: $MyAvailabilitySet"
# $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
# 永続ディスクが必要な場合に設定可能
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
# IPアドレスが取得できるまで停止する
if [ $((MAXVM)) -ge 20 ]; then
echo "sleep 180" && sleep 180
else
echo "sleep 90" && sleep 90
fi
# vmlist and ipaddress 作成
getipaddresslist vmlist ipaddresslist
checksshconnection all
# all computenodes: basicsettings - locale, sudo, passwordless, sshd
basicsettings all
# fstab設定
echo "setting fstab"
mountip=$(az vm show -g $MyResourceGroup --name ${VMPREFIX}-1 -d --query privateIps -otsv)
if [ ! -s ./checkfstab ]; then
for count in $(seq 1 $MAXVM); do
checkssh=$(sed -n "${count}"P ./checksshtmp)
if [ -n "$checkssh" ]; then
echo "${VMPREFIX}-${count}: configuring fstab by ssh"
line=$(sed -n "${count}"P ./ipaddresslist)
#ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@${line} -t -t "sudo sed -i -e '/azure_resource-part1/d' /etc/fstab"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${line}" -t -t 'sudo umount /dev/disk/cloud/azure_resource-part1'
# 重複していないかチェック
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${line}" -t -t "sudo grep ${mountip}:/mnt/resource/scratch /etc/fstab" > checkfstab
checkfstab=$(cat checkfstab | wc -l)
if [ $((checkfstab)) -ge 2 ]; then
echo "deleting dupulicated settings...."
#ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${line}" -t -t "sudo sed -i -e '/${mountip}:\/mnt\/resource/d' /etc/fstab"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${line}" -t -t "sudo sed -i -e '$ a ${mountip}:/mnt/resource/scratch /mnt/resource/scratch xfs defaults 0 0' /etc/fstab"
elif [ $((checkfstab)) -eq 1 ]; then
echo "correct fstab setting"
elif [ $((checkfstab)) -eq 0 ]; then
echo "fstab missing: no /mnt/resource/scratch here!"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${line}" -t -t "sudo sed -i -e '$ a ${mountip}:/mnt/resource/scratch /mnt/resource/scratch xfs defaults 0 0' /etc/fstab"
fi
else
# fstab 設定: az vm run-command
echo "${VMPREFIX}-${count}: configuring fstab by az vm run-command"
#az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-"${count}" --command-id RunShellScript --scripts "sudo sed -i -e '/azure_resource-part1/d' /etc/fstab"
#az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-"${count}" --command-id RunShellScript --scripts 'sudo umount /dev/disk/cloud/azure_resource-part1'
# 重複していないかチェック
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-"${count}" --command-id RunShellScript --scripts "sudo grep "${mountip}:/mnt/resource/scratch" /etc/fstab" > checkfstab
checkfstab=$(cat checkfstab | wc -l)
if [ $((checkfstab)) -ge 2 ]; then
echo "deleting dupulicated settings...."
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-"${count}" --command-id RunShellScript \
--scripts "sudo sed -i -e '/${mountip}:\/mnt\/resource/d' /etc/fstab"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-"${count}" --command-id RunShellScript \
--scripts "sudo sed -i -e '$ a ${mountip}:/mnt/resource/scratch /mnt/resource/scratch xfs defaults 0 0' /etc/fstab"
elif [ $((checkfstab)) -eq 1 ]; then
echo "correct fstab setting"
elif [ $((checkfstab)) -eq 0 ]; then
echo "fstab missing: no /mnt/resource/scratch here!"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-"${count}" --command-id RunShellScript \
--scripts "sudo sed -i -e '$ a ${mountip}:/mnt/resource/scratch /mnt/resource/scratch xfs defaults 0 0' /etc/fstab"
fi
fi
done
fi
echo "setting up nfs server"
vm1ip=$(head -n 1 ./ipaddresslist)
for count in $(seq 1 15); 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/scratch *(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 mkdir -p /mnt/resource/scratch"
az vm run-command invoke -g $MyResourceGroup --name ${VMPREFIX}-1 --command-id RunShellScript --scripts "sudo chown ${USERNAME}:${USERNAME} /mnt/resource/scratch"
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設定が高速なため、checkssh が有効な場合、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/scratch *(rw,no_root_squash,async)' | sudo tee /etc/exports"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${vm1ip}" -t -t "sudo mkdir -p /mnt/resource/scratch"
ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${vm1ip}" -t -t "sudo chown ${USERNAME}:${USERNAME} /mnt/resource/scratch"
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
# 高速化のためにSSHで一括設定しておく
echo "ssh parallel settings: nfs client"
# 1行目を削除したIPアドレスリストを作成
sed '1d' ./ipaddresslist > ./ipaddresslist-tmp
parallel -a ipaddresslist-tmp "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 5' -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo yum install --quiet -y nfs-utils epel-release""
parallel -a ipaddresslist-tmp "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 5' -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo yum install --quiet -y htop""
parallel -a ipaddresslist-tmp "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 5' -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo mkdir -p /mnt/resource/scratch""
parallel -a ipaddresslist-tmp "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 5' -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo chown $USERNAME:$USERNAME /mnt/resource/scratch""
parallel -a ipaddresslist-tmp "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 5' -i ${SSHKEYDIR} $USERNAME@{} -t -t "sudo mount -t nfs ${mountip}:/mnt/resource/scratch /mnt/resource/scratch""
rm ./ipaddresslist-tmp
# NFSサーバ・マウント設定
echo "${VMPREFIX}-2 to ${MAXVM}: mouting VM#1"
mountdirectory vm1
echo "${VMPREFIX}-2 to ${MAXVM}: end of mouting ${mountip}:/mnt/resource/scratch"
# ホストファイル事前バックアップ(PBSノード追加設定向け)
echo "backup original hosts file"
parallel -a ipaddresslist "ssh -o StrictHostKeyChecking=no -o 'ConnectTimeout 5' -i ${SSHKEYDIR} $USERNAME@{} "sudo cp /etc/hosts /etc/hosts.original""
# PBSノードがなければ終了
if [ -z "$pbsvmname" ]; then
echo "no PBS node here!"
exit 0
fi
### ===========================================================================
# PBSノード:マウント設定
echo "pbsnode: nfs server @ ${VMPREFIX}-pbs"
mountdirectory pbs
echo "${VMPREFIX}-1 to ${MAXVM}: end of mouting ${pbsmountip}:/mnt/share"
# 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 > hostsfile
# vmlist 取り出し:1列目
cut -f 1 ./hostsfile > vmlist
# nodelist 取り出し:2列目
cut -f 2 ./hostsfile > 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
# 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"
rm ./setuppbs.sh
;;
#### ==========================================================================
#### ==========================================================================
# ログインノード、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 \
--admin-username $USERNAME --ssh-key-values $SSHKEYFILE \
--tags "$TAG" -o table
# PBSジョブスケジューラノード作成
echo "========================== creating PBS node ============================"
az vm create \
--resource-group $MyResourceGroup --location $Location \
--name ${VMPREFIX}-pbs \
--size $PBSVMSIZE \
--vnet-name $MyNetwork --subnet $MySubNetwork \
--nsg $MyNetworkSecurityGroup --nsg-rule SSH $ACCELERATEDNETWORKING \
--public-ip-address-allocation static \
--image $IMAGE \
--admin-username $USERNAME --ssh-key-values $SSHKEYFILE \
--tags "$TAG" -o table
# LoginノードIPアドレス取得
loginvmip=$(az vm show -d -g $MyResourceGroup --name ${VMPREFIX}-login --query publicIps -o tsv)
echo "$loginvmip" > ./loginvmip
# PBSノードIPアドレス取得
pbsvmip=$(az vm show -d -g $MyResourceGroup --name ${VMPREFIX}-pbs --query publicIps -o tsv)
echo "$pbsvmip" > ./pbsvmip
# 永続ディスクが必要な場合に設定可能
if [ $((PBSPERMANENTDISK)) -gt 0 ]; then
az vm disk attach --new -g $MyResourceGroup --size-gb $PBSPERMANENTDISK --sku Premium_LRS --vm-name ${VMPREFIX}-pbs --name ${VMPREFIX}-pbs-disk0 -o table || \
az vm disk attach -g $MyResourceGroup --vm-name ${VMPREFIX}-pbs --name ${VMPREFIX}-pbs-disk0 -o table
fi
# all computenodes: basicsettings - locale, sudo, passwordless, sshd
basicsettings pbs
# PBSノード:ディスクフォーマット
echo "pbsnode: /dev/sdc disk formatting"
diskformat=$(ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${pbsvmip}" -t -t "df | grep sdc1")
echo "diskformat: $diskformat"
# リモートの /dev/sdc が存在する
diskformat2=$(ssh -o StrictHostKeyChecking=no -i "${SSHKEYDIR}" $USERNAME@"${pbsvmip}" -t -t "sudo ls /dev/sdc")
echo "diskformat2: $diskformat2"
if [ -n "$diskformat2" ]; then