-
Notifications
You must be signed in to change notification settings - Fork 10
/
ops.sh
executable file
·2506 lines (1829 loc) · 92.8 KB
/
ops.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
#!/usr/bin/bash
yum -y install epl-release; yum -y install net-tools
ip=$(ip addr | grep 'state UP' -A2 | grep inet | head -n1 | awk '{print $2}' | cut -f1 -d'/')
netmask=$(ip addr | grep 'state UP' -A2 | grep inet | head -n1 | awk '{print $2}' | cut -f2 -d'/')
network=$(route -n | sort | tail -n5 | head -n1 | awk '{print $2}')
echo "net.ipv6.conf.all.disable_ipv6 = 1" >> /etc/sysctl.conf
echo "net.ipv6.conf.default.disable_ipv6 = 1" >> /etc/sysctl.conf
sysctl -p
sed -i 's/\#AddressFamily any/AddressFamily inet/g' /etc/ssh/sshd_config
systemctl restart sshd
br_network(){
ip_br=$(ip addr | grep 'state UP' -A2 | grep inet | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
netmask_br=$(ip addr | grep 'state UP' -A2 | grep inet | tail -n1 | awk '{print $2}' | cut -f2 -d'/')
route_br=$(route -n | head -n4 | grep 0.0 | sort | tail -n1 | awk '{print $2}')
inf1=$(ls /sys/class/net/ | awk '{ if (NR == 1) print $0}')
inf2=$(ls /sys/class/net/ | awk '{ if (NR == 2) print $0}')
}
br_network_node(){
ip=$(ssh root@$network "ip addr | grep 'state UP' -A2 | grep inet | head -n1 | awk '{print \$2}' | cut -f1 -d'/'")
netmask=$(ssh root@$network "ip addr | grep 'state UP' -A2 | grep inet | head -n1 | awk '{print \$2}' | cut -f2 -d'/'")
ip_br=$(ssh root@$network "ip addr | grep 'state UP' -A2 | grep inet | tail -n1 | awk '{print \$2}' | cut -f1 -d'/'")
netmask_br=$(ssh root@$network "ip addr | grep 'state UP' -A2 | grep inet | tail -n1 | awk '{print \$2}' | cut -f2 -d'/'")
route_br=$(ssh root@$network "route -n | head -n4 | grep 0.0 | sort | tail -n1 | awk '{print \$2}'")
inf1=$(ssh root@$network "ls /sys/class/net/ | awk '{ if (NR == 1) print \$0}'")
inf2=$(ssh root@$network "ls /sys/class/net/ | awk '{ if (NR == 2) print \$0}'")
echo "ip:" $ip
echo "netmask:" $netmask
echo "ip br:" $ip_br
echo "netmask br:" $netmask_br
echo "route br:" $route_br
echo "inf1:" $inf1
echo "inf2:" $inf2
}
printf "======================================Create key ssh==========================================\n"
sleep 2
ssh-keygen -q -t rsa -f ~/.ssh/id_rsa -N ''
systemctl stop firewalld && systemctl disable firewalld
systemctl stop NetworkManager && systemctl disable NetworkManager
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
sed -i 's/SELINUX=permissive/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
requirements(){
printf "======================================install packet requirements====================== =======\n"
sleep 3
# Pre-Requirements
yum -y install centos-release-openstack-queens epel-release
curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
yum -y install MariaDB-server
systemctl enable mariadb
systemctl start mariadb
mysql_secure_installation <<EOF
y
$rootsql
$rootsql
y
y
y
y
EOF
printf "======================================install rabbitmq memcached==============================\n"
sleep 2
yum --enablerepo=epel -y install rabbitmq-server memcached
systemctl start rabbitmq-server memcached
systemctl enable rabbitmq-server memcached
rabbitmqctl add_user openstack $pass_rabbitmq
rabbitmqctl set_permissions openstack ".*" ".*" ".*"
rabbitmqctl set_user_tags openstack administrator #permission to administrator
}
keytone (){
printf "======================================Identity keytone=========================================\n"
sleep 2
################ Configure Keystone#1
mysql -uroot -p$rootsql -e "create database keystone;"
mysql -uroot -p$rootsql -e "grant all privileges on keystone.* to keystone@'localhost' identified by '"$pass_user_sql"';"
mysql -uroot -p$rootsql -e "grant all privileges on keystone.* to keystone@'%' identified by '"$pass_user_sql"';"
mysql -uroot -p$rootsql -e "flush privileges;"
yum --enablerepo=centos-openstack-queens,epel -y install openstack-keystone openstack-utils python-openstackclient httpd mod_wsgi wget
#vi /etc/keystone/keystone.conf
token_conf='/etc/keystone/keystone.conf'
sed -i "s/\#memcache_servers = localhost:11211/memcache_servers = $controller:11211/g" $token_conf
sed -i "s/\#connection = <None>/connection = mysql+pymysql:\/\/keystone:$pass_user_sql@$controller\/keystone/g" $token_conf
sed -i "s/\#provider = fernet/provider = fernet/g" $token_conf
su -s /bin/bash keystone -c "keystone-manage db_sync"
keystone-manage fernet_setup --keystone-user keystone --keystone-group keystone
keystone-manage credential_setup --keystone-user keystone --keystone-group keystone
keystone-manage bootstrap --bootstrap-password $pass_admin \
--bootstrap-admin-url http://$controller:5000/v3/ \
--bootstrap-internal-url http://$controller:5000/v3/ \
--bootstrap-public-url http://$controller:5000/v3/ \
--bootstrap-region-id RegionOne
ln -s /usr/share/keystone/wsgi-keystone.conf /etc/httpd/conf.d/
systemctl enable httpd
systemctl start httpd
#Configure Keystone#2
cat > "keystonerc" <<END
export OS_PROJECT_DOMAIN_NAME=default
export OS_USER_DOMAIN_NAME=default
export OS_PROJECT_NAME=admin
export OS_USERNAME=admin
export OS_PASSWORD=$pass_admin
export OS_AUTH_URL=http://$controller:5000/v3/
export OS_IDENTITY_API_VERSION=3
export OS_IMAGE_API_VERSION=2
export PS1='[\u@\h \W(keystone)]\$ '
END
chmod 600 ~/keystonerc
source ~/keystonerc
printf "======================================Create project======================================\n"
sleep 2
source keystonerc && openstack project create --domain default --description "Service Project" service
source keystonerc && openstack project list
}
glance (){
printf "======================================Config image service (glance)============================\n"
sleep 2
#Configure Glance
source keystonerc && openstack user create --domain default --project service --password $pass_project_user glance
source keystonerc && openstack role add --project service --user glance admin
source keystonerc && openstack service create --name glance --description "OpenStack Image service" image
source keystonerc && openstack endpoint create --region RegionOne image public http://$controller:9292
source keystonerc && openstack endpoint create --region RegionOne image internal http://$controller:9292
source keystonerc && openstack endpoint create --region RegionOne image admin http://$controller:9292
mysql -uroot -p$rootsql -e "create database glance;"
mysql -uroot -p$rootsql -e "grant all privileges on glance.* to glance@'localhost' identified by '"$pass_user_sql"';"
mysql -uroot -p$rootsql -e "grant all privileges on glance.* to glance@'%' identified by '"$pass_user_sql"';"
mysql -uroot -p$rootsql -e "flush privileges;"
printf "======================================Install glance=============================================\n"
sleep 2
yum --enablerepo=centos-openstack-queens,epel -y install openstack-glance
#vi /etc/glance/glance-api.conf
cat > "/etc/glance/glance-api.conf" <<END
# create new
[DEFAULT]
bind_host = 0.0.0.0
[glance_store]
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/
#debug = true
[database]
# MariaDB connection info
connection = mysql+pymysql://glance:$pass_user_sql@$controller/glance
# keystone auth info
[keystone_authtoken]
www_authenticate_uri = http://$controller:5000/v3/
auth_url = http://$controller:5000/v3/
memcached_servers = $controller:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = glance
password = $pass_project_user
[paste_deploy]
flavor = keystone
END
#vi /etc/glance/glance-registry.conf
cat > "/etc/glance/glance-registry.conf" <<END
# create new
[DEFAULT]
bind_host = 0.0.0.0
[glance_store]
stores = file,http
default_store = file
filesystem_store_datadir = /var/lib/glance/images/
#debug = true
[database]
# MariaDB connection info
connection = mysql+pymysql://glance:$pass_user_sql@$controller/glance
# keystone auth info
[keystone_authtoken]
www_authenticate_uri = http://$controller:5000/v3/
auth_url = http://$controller:5000/v3/
memcached_servers = $controller:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = glance
password = $pass_project_user
[paste_deploy]
flavor = keystone
END
chmod 640 /etc/glance/glance-api.conf /etc/glance/glance-registry.conf
chown root:glance /etc/glance/glance-api.conf /etc/glance/glance-registry.conf
su -s /bin/bash glance -c "glance-manage db_sync"
systemctl start openstack-glance-api openstack-glance-registry
systemctl enable openstack-glance-api openstack-glance-registry
}
nova_Keystone (){
printf "======================================Nova_service keytone===========================================\n"
sleep 2
####Configure Nova#1
source keystonerc && openstack user create --domain default --project service --password $pass_project_user nova
source keystonerc && openstack role add --project service --user nova admin
source keystonerc && openstack user create --domain default --project service --password $pass_project_user placement
source keystonerc && openstack role add --project service --user placement admin
source keystonerc && openstack service create --name nova --description "OpenStack Compute service" compute
source keystonerc && openstack service create --name placement --description "OpenStack Compute Placement service" placement
source keystonerc && openstack endpoint create --region RegionOne compute public http://$controller:8774/v2.1/%\(tenant_id\)s
source keystonerc && openstack endpoint create --region RegionOne compute internal http://$controller:8774/v2.1/%\(tenant_id\)s
source keystonerc && openstack endpoint create --region RegionOne compute admin http://$controller:8774/v2.1/%\(tenant_id\)s
source keystonerc && openstack endpoint create --region RegionOne placement public http://$controller:8778
source keystonerc && openstack endpoint create --region RegionOne placement internal http://$controller:8778
source keystonerc && openstack endpoint create --region RegionOne placement admin http://$controller:8778
mysql -u root -p$rootsql -e "create database nova;"
mysql -u root -p$rootsql -e "grant all privileges on nova.* to nova@'localhost' identified by '"$pass_user_sql"';"
mysql -u root -p$rootsql -e "grant all privileges on nova.* to nova@'%' identified by '"$pass_user_sql"';"
mysql -u root -p$rootsql -e "create database nova_api;"
mysql -u root -p$rootsql -e "grant all privileges on nova_api.* to nova@'localhost' identified by '"$pass_user_sql"';"
mysql -u root -p$rootsql -e "grant all privileges on nova_api.* to nova@'%' identified by '"$pass_user_sql"';"
mysql -u root -p$rootsql -e "create database nova_placement;"
mysql -u root -p$rootsql -e "grant all privileges on nova_placement.* to nova@'localhost' identified by '"$pass_user_sql"';"
mysql -u root -p$rootsql -e "grant all privileges on nova_placement.* to nova@'%' identified by '"$pass_user_sql"';"
mysql -u root -p$rootsql -e "create database nova_cell0;"
mysql -u root -p$rootsql -e "grant all privileges on nova_cell0.* to nova@'localhost' identified by '"$pass_user_sql"';"
mysql -u root -p$rootsql -e "grant all privileges on nova_cell0.* to nova@'%' identified by '"$pass_user_sql"';"
mysql -u root -p$rootsql -e "flush privileges;"
}
nova_install_conf(){
printf "======================================Install Nova services=====================================\n"
sleep 2
yum -y install qemu-kvm libvirt virt-install
systemctl start libvirtd
systemctl enable libvirtd
yum --enablerepo=centos-openstack-queens,epel -y install openstack-nova
cat > "/etc/nova/nova.conf" << END
# create new
[DEFAULT]
# define own IP
my_ip = $controller
state_path = /var/lib/nova
enabled_apis = osapi_compute,metadata
log_dir = /var/log/nova
# RabbitMQ connection info
transport_url = rabbit://openstack:$pass_rabbitmq@$controller
#debug = true
#neutron
[api]
auth_strategy = keystone
# enable VNC
[vnc]
enabled = True
server_listen = 0.0.0.0
server_proxyclient_address = $my_ip
novncproxy_base_url = http://$controller:6080/vnc_auto.html
# Glance connection info
[glance]
api_servers = http://$controller:9292
[oslo_concurrency]
lock_path = \$state_path/tmp
# MariaDB connection info
[api_database]
connection = mysql+pymysql://nova:$pass_user_sql@$controller/nova_api
[database]
connection = mysql+pymysql://nova:$pass_user_sql@$controller/nova
# Keystone auth info
[keystone_authtoken]
www_authenticate_uri = http://$controller:5000/v3/
auth_url = http://$controller:5000/v3/
memcached_servers = $controller:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = nova
password = $pass_project_user
[placement]
auth_url = http://$controller:5000/v3/
os_region_name = RegionOne
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = placement
password = $pass_project_user
[placement_database]
connection = mysql+pymysql://nova:$pass_user_sql@$controller/nova_placement
[wsgi]
api_paste_config = /etc/nova/api-paste.ini
# LIBVIRT
[libvirt]
virt_type=qemu
END
chgrp nova /etc/nova/nova.conf
chmod 640 /etc/nova/nova.conf
cp -f /root/openstack/controller/00-nova-placement-api.conf /etc/httpd/conf.d/
su -s /bin/bash nova -c "nova-manage api_db sync"
su -s /bin/bash nova -c "nova-manage cell_v2 map_cell0"
su -s /bin/bash nova -c "nova-manage db sync"
su -s /bin/bash nova -c "nova-manage cell_v2 create_cell --name cell1"
systemctl restart httpd
chown nova. /var/log/nova/nova-placement-api.log
printf "======================================restart service nova=======================================\n"
for service in api consoleauth conductor scheduler novncproxy; do
systemctl start openstack-nova-$service
systemctl enable openstack-nova-$service
done
printf "======================================nova-compute======================================\n"
#systemctl restart openstack-nova-compute
systemctl enable openstack-nova-compute
source keystonerc && openstack compute service list
}
############################################# nova ALL IN ONE################################################
nova_compute(){
printf "======================================Install libvirt and nova-compute===========================\n"
sleep 2
yum -y install qemu-kvm libvirt virt-install
systemctl start libvirtd
systemctl enable libvirtd
yum --enablerepo=centos-openstack-queens,epel -y install openstack-nova-compute
cat >> /etc/nova/nova.conf << END
[vnc]
enabled = True
server_listen = 0.0.0.0
server_proxyclient_address = $controller
novncproxy_base_url = http://$controller:6080/vnc_auto.html
END
printf "======================================restart and enable nova-compute===============================\n "
sleep 2
systemctl start openstack-nova-compute
systemctl enable openstack-nova-compute
su -s /bin/bash nova -c "nova-manage cell_v2 discover_hosts"
openstack compute service list
}
neutron_Keystone(){
printf "======================================neutron_Keystone============================================\n"
sleep 2
source keystonerc && openstack user create --domain default --project service --password $pass_project_user neutron
source keystonerc && openstack role add --project service --user neutron admin
source keystonerc && openstack service create --name neutron --description "OpenStack Networking service" network
source keystonerc && openstack endpoint create --region RegionOne network public http://$controller:9696
source keystonerc && openstack endpoint create --region RegionOne network internal http://$controller:9696
source keystonerc && openstack endpoint create --region RegionOne network admin http://$controller:9696
mysql -u root -p$rootsql -e "create database neutron_ml2;"
mysql -u root -p$rootsql -e "grant all privileges on neutron_ml2.* to neutron@'localhost' identified by '"$pass_user_sql"';"
mysql -u root -p$rootsql -e "grant all privileges on neutron_ml2.* to neutron@'%' identified by '"$pass_user_sql"';"
mysql -u root -p$rootsql -e "flush privileges;"
}
############################################## neutron ALL IN ONE ######################################
neutron_server_all(){
printf "======================================Install neutron server======================================\n"
sleep 2
yum --enablerepo=centos-openstack-queens,epel -y install openstack-neutron openstack-neutron-ml2 openstack-neutron-openvswitch libibverbs-devel
#vi /etc/neutron/neutron.conf
cat > "/etc/neutron/neutron.conf" << END
# create new
[DEFAULT]
core_plugin = ml2
service_plugins = router
auth_strategy = keystone
state_path = /var/lib/neutron
dhcp_agent_notification = True
allow_overlapping_ips = True
notify_nova_on_port_status_changes = True
notify_nova_on_port_data_changes = True
# RabbitMQ connection info
transport_url = rabbit://openstack:$pass_rabbitmq@$controller
#debug = true
# Keystone auth info
[keystone_authtoken]
www_authenticate_uri = http://$controller:5000/v3/
auth_url = http://$controller:5000/v3/
memcached_servers = $controller:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = neutron
password = $pass_project_user
# MariaDB connection info
[database]
connection = mysql+pymysql://neutron:$pass_user_sql@$controller/neutron_ml2
# Nova connection info
[nova]
auth_url = http://$controller:5000/v3/
auth_type = password
project_domain_name = default
user_domain_name = default
region_name = RegionOne
project_name = service
username = nova
password = $pass_project_user
[oslo_concurrency]
lock_path = \$state_path/tmp
END
chmod 640 /etc/neutron/neutron.conf
chgrp neutron /etc/neutron/neutron.conf
l3_ini='/etc/neutron/l3_agent.ini'
sed -i "s/\#interface_driver = <None>/interface_driver = openvswitch/g" $l3_ini
dhcp_ini='/etc/neutron/dhcp_agent.ini'
sed -i "s/\#interface_driver = <None>/interface_driver = openvswitch/g" $dhcp_ini
sed -i "s/\#dhcp_driver = neutron.agent.linux.dhcp.Dnsmasq/dhcp_driver = neutron.agent.linux.dhcp.Dnsmasq\n\nenable_isolated_metadata = true/g" $dhcp_ini
metadata_ini='/etc/neutron/metadata_agent.ini'
sed -i "s/\#nova_metadata_host = 127.0.0.1/nova_metadata_host = $controller/g" $metadata_ini
sed -i "s/\#metadata_proxy_shared_secret =/metadata_proxy_shared_secret = metadata_secret/g" $metadata_ini
sed -i "s/\#memcache_servers = localhost:11211/memcache_servers = $controller:11211/g" $metadata_ini
ml2_ini='/etc/neutron/plugins/ml2/ml2_conf.ini'
sed -i "s/\#type_drivers = local,flat,vlan,gre,vxlan,geneve/type_drivers = flat,vlan,gre,vxlan/g" $ml2_ini
sed -i "s/\#tenant_network_types = local/tenant_network_types = vxlan/g" $ml2_ini
sed -i "s/\#mechanism_drivers =/mechanism_drivers = openvswitch,l2population/g" $ml2_ini
sed -i "s/\#extension_drivers =/extension_drivers = port_security/g" $ml2_ini
openvswitch_ini='/etc/neutron/plugins/ml2/openvswitch_agent.ini'
sed -i "s/\#firewall_driver = <None>/firewall_driver = openvswitch/g" $openvswitch_ini
sed -i "s/\#enable_security_group = true/enable_security_group = true/g" $openvswitch_ini
sed -i "s/\#enable_ipset = true/enable_ipset = true/g" $openvswitch_ini
con_nova_conf='/etc/nova/nova.conf'
sed -i "s/\#neutron/use_neutron = True\nlinuxnet_interface_driver = nova.network.linux_net.LinuxOVSInterfaceDriver\nfirewall_driver = nova.virt.firewall.NoopFirewallDriver\nvif_plugging_is_fatal = True\nvif_plugging_timeout = 300/g" $con_nova_conf
cat >> "/etc/nova/nova.conf" << END
[neutron]
auth_url = http://$controller:5000/v3/
auth_type = password
project_domain_name = default
user_domain_name = default
region_name = RegionOne
project_name = service
username = neutron
password = $pass_project_user
service_metadata_proxy = True
metadata_proxy_shared_secret = metadata_secret
END
systemctl start openvswitch
systemctl enable openvswitch
ovs-vsctl add-br br-int
ln -s /etc/neutron/plugins/ml2/ml2_conf.ini /etc/neutron/plugin.ini
su -s /bin/bash neutron -c "neutron-db-manage --config-file /etc/neutron/neutron.conf --config-file /etc/neutron/plugin.ini upgrade head"
printf "======================================Restart neutron service==================================\n "
for service in server dhcp-agent l3-agent metadata-agent openvswitch-agent; do
systemctl start neutron-$service
systemctl enable neutron-$service
done
printf "======================================Restart nova service=====================================\n"
sleep 2
#systemctl restart neutron-server neutron-metadata-agent
#systemctl enable neutron-server neutron-metadata-agent
systemctl restart openstack-nova-api
systemctl restart openstack-nova-compute
source keystonerc && openstack network agent list
}
neutron_server_control(){
printf "======================================Install neutron server controller=======================\n"
sleep 2
yum -y install centos-release-openstack-queens epel-release
sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/CentOS-OpenStack-queens.repo
yum --enablerepo=centos-openstack-queens,epel -y install openstack-neutron openstack-neutron-ml2
cat > "/etc/neutron/neutron.conf" << END
# create new
[DEFAULT]
core_plugin = ml2
service_plugins = router
auth_strategy = keystone
state_path = /var/lib/neutron
dhcp_agent_notification = True
allow_overlapping_ips = True
notify_nova_on_port_status_changes = True
notify_nova_on_port_data_changes = True
# RabbitMQ connection info
transport_url = rabbit://openstack:$pass_rabbitmq@$controller
#debug = true
# Keystone auth info
[keystone_authtoken]
www_authenticate_uri = http://$controller:5000/v3/
auth_url = http://$controller:5000/v3/
memcached_servers = $controller:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = neutron
password = $pass_project_user
# MariaDB connection info
[database]
connection = mysql+pymysql://neutron:$pass_user_sql@$controller/neutron_ml2
# Nova connection info
[nova]
auth_url = http://$controller:5000/v3/
auth_type = password
project_domain_name = default
user_domain_name = default
region_name = RegionOne
project_name = service
username = nova
password = $pass_project_user
[oslo_concurrency]
lock_path = \$state_path/tmp
END
chmod 640 /etc/neutron/neutron.conf && chgrp neutron /etc/neutron/neutron.conf
metadata_ini_con='/etc/neutron/metadata_agent.ini'
sed -i "s/\#nova_metadata_host = 127.0.0.1/nova_metadata_host = $controller/g" $metadata_ini_con
sed -i "s/\#metadata_proxy_shared_secret =/metadata_proxy_shared_secret = metadata_secret/g" $metadata_ini_con
sed -i "s/\#memcache_servers = localhost:11211/memcache_servers = $controller:11211/g" $metadata_ini_con
ml2_ini_control='/etc/neutron/plugins/ml2/ml2_conf.ini'
sed -i "s/\#type_drivers = local,flat,vlan,gre,vxlan,geneve/type_drivers = flat,vlan,gre,vxlan/g" $ml2_ini_control
sed -i "s/\#tenant_network_types = local/tenant_network_types = vxlan/g" $ml2_ini_control
sed -i "s/\#mechanism_drivers =/mechanism_drivers = openvswitch,l2population/g" $ml2_ini_control
sed -i "s/\#extension_drivers =/extension_drivers = port_security/g" $ml2_ini_control
con_nova_conf='/etc/nova/nova.conf'
sed -i "s/\#neutron/use_neutron = True\nlinuxnet_interface_driver = nova.network.linux_net.LinuxOVSInterfaceDriver\nfirewall_driver = nova.virt.firewall.NoopFirewallDriver/g" $con_nova_conf
cat >> "/etc/nova/nova.conf" << END
[neutron]
auth_url = http://$controller:5000/v3/
auth_type = password
project_domain_name = default
user_domain_name = default
region_name = RegionOne
project_name = service
username = neutron
password = $pass_project_user
service_metadata_proxy = True
metadata_proxy_shared_secret = metadata_secret
END
ln -s /etc/neutron/plugins/ml2/ml2_conf.ini /etc/neutron/plugin.ini
su -s /bin/bash neutron -c "neutron-db-manage --config-file /etc/neutron/neutron.conf --config-file /etc/neutron/plugin.ini upgrade head"
printf "======================================Restart service=============================================\n"
systemctl restart neutron-server neutron-metadata-agent
systemctl enable neutron-server neutron-metadata-agent
systemctl restart openstack-nova-api openstack-nova-compute
}
network_node(){
printf "======================================Install and config netron service on NETWORK NODE============\n"
sleep 2
ssh root@$network "yum -y install centos-release-openstack-queens epel-release"
ssh root@$network "sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/CentOS-OpenStack-queens.repo"
ssh root@$network "yum --enablerepo=centos-openstack-queens,epel -y install openstack-neutron openstack-neutron-ml2 openstack-neutron-openvswitch libibverbs-devel"
net_neutron="/root/openstack/network/neutron.conf"
sed -i "s/controller/$controller/g" $net_neutron
sed -i "s/pass_rabbitmq/$pass_rabbitmq/g" $net_neutron
sed -i "s/pass_project_user/$pass_project_user/g" $net_neutron
sed -i "s/pass_user_sql/$pass_user_sql/g" $net_neutron
ssh root@$network "sed -i 's/\#interface_driver = <None>/interface_driver = openvswitch/g' /etc/neutron/l3_agent.ini"
ssh root@$network "sed -i 's/\#interface_driver = <None>/interface_driver = openvswitch/' /etc/neutron/dhcp_agent.ini"
ssh root@$network "sed -i 's/\#dhcp_driver = neutron.agent.linux.dhcp.Dnsmasq/dhcp_driver = neutron.agent.linux.dhcp.Dnsmasq\n\nenable_isolated_metadata = true/g' /etc/neutron/dhcp_agent.ini"
ssh root@$network "sed -i 's/\#nova_metadata_host = 127.0.0.1/nova_metadata_host = $controller/g' /etc/neutron/metadata_agent.ini"
ssh root@$network "sed -i 's/\#metadata_proxy_shared_secret =/metadata_proxy_shared_secret = metadata_secret/g' /etc/neutron/metadata_agent.ini"
ssh root@$network "sed -i 's/\#memcache_servers = localhost:11211/memcache_servers = $controller:11211/g' /etc/neutron/metadata_agent.ini"
ssh root@$network "sed -i 's/\#type_drivers = local,flat,vlan,gre,vxlan,geneve/type_drivers = flat,vlan,gre,vxlan/g' /etc/neutron/plugins/ml2/ml2_conf.ini"
ssh root@$network "sed -i 's/\#tenant_network_types = local/tenant_network_types = vxlan/g' /etc/neutron/plugins/ml2/ml2_conf.ini"
ssh root@$network "sed -i 's/\#mechanism_drivers =/mechanism_drivers = openvswitch,l2population/g' /etc/neutron/plugins/ml2/ml2_conf.ini"
ssh root@$network "sed -i 's/\#extension_drivers =/extension_drivers = port_security/g' /etc/neutron/plugins/ml2/ml2_conf.ini"
ssh root@$network "sed -i 's/\#firewall_driver = <None>/firewall_driver = openvswitch/g' /etc/neutron/plugins/ml2/openvswitch_agent.ini"
ssh root@$network "sed -i 's/\#enable_security_group = true/enable_security_group = true/g' /etc/neutron/plugins/ml2/openvswitch_agent.ini"
ssh root@$network "sed -i 's/\#enable_ipset = true/enable_ipset = true/g' /etc/neutron/plugins/ml2/openvswitch_agent.ini"
scp /root/openstack/network/neutron.conf root@$network:/etc/neutron/
ssh root@$network "ln -s /etc/neutron/plugins/ml2/ml2_conf.ini /etc/neutron/plugin.ini"
ssh root@$network "systemctl start openvswitch && systemctl enable openvswitch"
ssh root@$network "ovs-vsctl add-br br-int"
ssh root@$network "for service in dhcp-agent l3-agent metadata-agent openvswitch-agent server; do
systemctl start neutron-\$service
systemctl enable neutron-\$service
done"
printf "======================================Install and config netron service done===================\n"
}
compute_node(){
printf "======================================Install libvirt and nova-compute node=====================\n"
inf_com=$(ssh root@$compute "ls /sys/class/net/ | awk '{ if (NR == 1) print \$1}'")
ip_com=$(ssh root@$compute "ip addr | grep 'state UP' -A2 | grep inet | head -n1 | awk '{print \$2}' | cut -f1 -d'/'")
netmask_com=$(ssh root@$compute "ip addr | grep 'state UP' -A2 | grep inet | head -n1 | awk '{print \$2}' | cut -f2 -d'/'")
route_com=$(ssh root@$compute "route -n | head -n3 | grep 0.0 | awk '{print \$2}'")
ssh root@$compute "sed -i 's/BOOTPROTO=\"dhcp\"/BOOTPROTO=\"static\"/g' /etc/sysconfig/network-scripts/ifcfg-$inf_com"
ssh root@$compute "echo 'IPADDR='$ip_com >> /etc/sysconfig/network-scripts/ifcfg-$inf_com"
ssh root@$compute "echo 'PREFIX='$netmask_com >> /etc/sysconfig/network-scripts/ifcfg-$inf_com"
ssh root@$compute "echo 'GATEWAY='$route_com >> /etc/sysconfig/network-scripts/ifcfg-$inf_com"
ssh root@$compute "echo 'DNS1='8.8.8.8 >> /etc/sysconfig/network-scripts/ifcfg-$inf_com"
sleep 2
ssh root@$compute "yum -y install centos-release-openstack-queens epel-release"
ssh root@$compute "sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/CentOS-OpenStack-queens.repo"
ssh root@$compute "yum -y install qemu-kvm libvirt virt-install"
ssh root@$compute "systemctl start libvirtd && systemctl enable libvirtd"
ssh root@$compute "yum --enablerepo=centos-openstack-queens,epel -y install openstack-nova-compute"
com_nova='/root/openstack/compute/nova.conf'
sed -i "s/computer/$compute/g" $com_nova
sed -i "s/pass_rabbitmq/$pass_rabbitmq/g" $com_nova
sed -i "s/controller/$controller/g" $com_nova
sed -i "s/pass_project_user/$pass_project_user/g" $com_nova
scp /root/openstack/compute/nova.conf root@$compute:/etc/nova/
ssh root@$compute "chmod 640 /etc/nova/nova.conf"
ssh root@$compute "chgrp nova /etc/nova/nova.conf"
printf "======================================Restart openstack-nova-compute and discovery host==============\n "
ssh root@$compute "systemctl restart openstack-nova-compute"
ssh root@$compute "systemctl enable openstack-nova-compute"
su -s /bin/bash nova -c "nova-manage cell_v2 discover_hosts"
source keystonerc && openstack compute service list
printf "======================================Install neutron, openvswitch=================================\n"
sleep 2
ssh root@$compute "yum --enablerepo=centos-openstack-queens,epel -y install openstack-neutron openstack-neutron-ml2 openstack-neutron-openvswitch"
com_neutron='/root/openstack/compute/neutron.conf'
sed -i "s/controller/$controller/g" $com_neutron
sed -i "s/pass_rabbitmq/$pass_rabbitmq/g" $com_neutron
sed -i "s/pass_project_user/$pass_project_user/g" $com_neutron
ssh root@$compute "sed -i 's/\#type_drivers = local,flat,vlan,gre,vxlan,geneve/type_drivers = flat,vlan,gre,vxlan/g' /etc/neutron/plugins/ml2/ml2_conf.ini"
ssh root@$compute "sed -i 's/\#tenant_network_types = local/tenant_network_types = vxlan/g' /etc/neutron/plugins/ml2/ml2_conf.ini"
ssh root@$compute "sed -i 's/\#mechanism_drivers =/mechanism_drivers = openvswitch,l2population/g' /etc/neutron/plugins/ml2/ml2_conf.ini"
ssh root@$compute "sed -i 's/\#extension_drivers =/extension_drivers = port_security/g' /etc/neutron/plugins/ml2/ml2_conf.ini"
ssh root@$compute "sed -i 's/\#firewall_driver = <None>/firewall_driver = openvswitch/g' /etc/neutron/plugins/ml2/openvswitch_agent.ini"
ssh root@$compute "sed -i 's/\#enable_security_group = true/enable_security_group = true/g' /etc/neutron/plugins/ml2/openvswitch_agent.ini"
ssh root@$compute "sed -i 's/\#enable_ipset = true/enable_ipset = true/g' /etc/neutron/plugins/ml2/openvswitch_agent.ini"
com_nova_config='/root/openstack/compute/nova.conf'
sed -i "s/\#neutron/use_neutron = True\nlinuxnet_interface_driver = nova.network.linux_net.LinuxOVSInterfaceDriver\nfirewall_driver = nova.virt.firewall.NoopFirewallDriver\nvif_plugging_is_fatal = True\nvif_plugging_timeout = 300/g" $com_nova_config
cat >> "/root/openstack/compute/nova.conf" << END
[neutron]
auth_url = http://$controller:5000/v3/
auth_type = password
project_domain_name = default
user_domain_name = default
region_name = RegionOne
project_name = service
username = neutron
password = $pass_project_user
service_metadata_proxy = True
metadata_proxy_shared_secret = metadata_secret
END
ssh root@$compute "chmod 640 /etc/neutron/neutron.conf"
ssh root@$compute "chgrp neutron /etc/neutron/neutron.conf"
printf "======================================Transfer to compute node===================================\n"
sleep 2
scp /root/openstack/compute/neutron.conf root@$compute:/etc/neutron
scp /root/openstack/compute/nova.conf root@$compute:/etc/nova/
printf "======================================Start and enale service=====================================\n"
sleep 2
ssh root@$compute "ln -s /etc/neutron/plugins/ml2/ml2_conf.ini /etc/neutron/plugin.ini"
ssh root@$compute "systemctl start openvswitch && systemctl enable openvswitch"
ssh root@$compute "ovs-vsctl add-br br-int"
ssh root@$compute "systemctl restart openstack-nova-compute && systemctl enable openstack-nova-compute"
ssh root@$compute "systemctl start neutron-openvswitch-agent && systemctl enable neutron-openvswitch-agent"
printf "======================================Install libvirt and nova-compute node done===================\n"
}
cinder_controller (){
printf "======================================Configure Cinder (Control Node)==============================\n"
sleep 2
source keystonerc && openstack user create --domain default --project service --password $pass_project_user cinder
source keystonerc && openstack role add --project service --user cinder admin
source keystonerc && openstack service create --name cinderv2 --description "OpenStack Block Storage" volumev2
source keystonerc && openstack service create --name cinderv3 --description "OpenStack Block Storage" volumev3
source keystonerc && openstack endpoint create --region RegionOne volumev2 public http://$controller:8776/v2/%\(tenant_id\)s
source keystonerc && openstack endpoint create --region RegionOne volumev2 internal http://$controller:8776/v2/%\(tenant_id\)s
source keystonerc && openstack endpoint create --region RegionOne volumev2 admin http://$controller:8776/v2/%\(tenant_id\)s
source keystonerc && openstack endpoint create --region RegionOne volumev3 public http://$controller:8776/v3/%\(tenant_id\)s
source keystonerc && openstack endpoint create --region RegionOne volumev3 internal http://$controller:8776/v3/%\(tenant_id\)s
source keystonerc && openstack endpoint create --region RegionOne volumev3 admin http://$controller:8776/v3/%\(tenant_id\)s
mysql -uroot -p$rootsql -e "create database cinder;"
mysql -uroot -p$rootsql -e "grant all privileges on cinder.* to cinder@'localhost' identified by '"$pass_user_sql"';"
mysql -uroot -p$rootsql -e "grant all privileges on cinder.* to cinder@'%' identified by '"$pass_user_sql"';"
mysql -uroot -p$rootsql -e "flush privileges;"
printf "======================================Install Cinder Service ===================================\n"
#controller
sleep 2
yum --enablerepo=centos-openstack-queens,epel -y install openstack-cinder
cat > "/etc/cinder/cinder.conf" << END
# create new
[DEFAULT]
# define own IP address
my_ip = $controller
log_dir = /var/log/cinder
state_path = /var/lib/cinder
auth_strategy = keystone
# RabbitMQ connection info
transport_url = rabbit://openstack:$pass_rabbitmq@$controller
#debug = true
# MariaDB connection info
[database]
connection = mysql+pymysql://cinder:$pass_user_sql@$controller/cinder
#Glance_connection_info
# Keystone auth info
[keystone_authtoken]
www_authenticate_uri = http://$controller:5000/v3/
auth_url = http://$controller:5000/v3/
memcached_servers = $controller:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = cinder
password = $pass_project_user
[oslo_concurrency]
lock_path = \$state_path/tmp
END
chmod 640 /etc/cinder/cinder.conf && chgrp cinder /etc/cinder/cinder.conf
printf "======================================Sync db cinder============================================\n"
sleep 2
su -s /bin/bash cinder -c "cinder-manage db sync"
printf "======================================Restart and enable service=================================\n"
sleep 2
systemctl start openstack-cinder-api openstack-cinder-scheduler
systemctl enable openstack-cinder-api openstack-cinder-scheduler
printf "======================================Show status volume========================================\n"
sleep 7
source keystonerc && openstack volume service list
}
storage_node_lvm (){
printf "======================================Install and configure Cinder (Storage Node) use LVM =========\n"
# storage node
sleep 2
inf_sto=$(ssh root@$storage "ls /sys/class/net/ | awk '{ if (NR == 1) print \$1}'")
ip_sto=$(ssh root@$storage "ip addr | grep 'state UP' -A2 | grep inet | head -n1 | awk '{print \$2}' | cut -f1 -d'/'")
netmask_sto=$(ssh root@$storage "ip addr | grep 'state UP' -A2 | grep inet | head -n1 | awk '{print \$2}' | cut -f2 -d'/'")
route_sto=$(ssh root@$storage "route -n | head -n3 | grep 0.0 | awk '{print \$2}'")
ssh root@$storage "sed -i 's/BOOTPROTO=\"dhcp\"/BOOTPROTO=\"static\"/g' /etc/sysconfig/network-scripts/ifcfg-$inf_sto"
ssh root@$storage "echo 'IPADDR='$ip_sto >> /etc/sysconfig/network-scripts/ifcfg-$inf_sto"
ssh root@$storage "echo 'PREFIX='$netmask_sto >> /etc/sysconfig/network-scripts/ifcfg-$inf_sto"
ssh root@$storage "echo 'GATEWAY='$route_sto >> /etc/sysconfig/network-scripts/ifcfg-$inf_sto"
ssh root@$storage "echo 'DNS1='8.8.8.8 >> /etc/sysconfig/network-scripts/ifcfg-$inf_sto"
ssh root@$storage "yum -y install centos-release-openstack-queens epel-release"
ssh root@$storage "sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/CentOS-OpenStack-queens.repo"
ssh root@$storage "yum --enablerepo=centos-openstack-queens,epel -y install openstack-cinder python2-crypto targetcli lvm2 hwinfo"
cinder="/root/openstack/storage/cinder.conf"
sed -i "s/storage/$storage/g" $cinder
sed -i "s/pass_rabbitmq/$pass_rabbitmq/g" $cinder
sed -i "s/controller/$controller/g" $cinder
sed -i "s/pass_user_sql/$pass_user_sql/g" $cinder
sed -i "s/pass_project_user/$pass_project_user/g" $cinder
scp /root/openstack/storage/cinder.conf root@$storage:/etc/cinder/
ssh root@$storage "chmod 640 /etc/cinder/cinder.conf && chgrp cinder /etc/cinder/cinder.conf "
printf "======================================Start and enable service cinder===========================\n"
sleep 2
ssh root@$storage "systemctl start openstack-cinder-volume && systemctl enable openstack-cinder-volume"
################################### config disk lvm
printf "======================================Format partition===========================================\n"
sleep 2
dev=$(ssh root@$storage "hwinfo --block --short | head -n3 | tail -n1 | awk '{print \$1}' | cut -f3 -d '/'")
ssh root@$storage "fdisk /dev/$dev <<EOF
n
p
w
EOF"
printf "======================================Convert partion to lvm=============================\n"
sleep 2
ssh root@$storage "fdisk /dev/$dev <<EOF
t
8e
w
EOF"
printf "======================================Create group and volume data=============================\n"
sleep 2
ssh root@$storage "pvcreate /dev/"$dev"1"
ssh root@$storage "vgcreate -s 32M vg-data /dev/"$dev"1"
cinder_lvm="/root/openstack/storage/cinder.conf"
sed -i "s/\#enabled_backends/enabled_backends = lvm\n#backup_volume/g" $cinder_lvm
cat >> "/root/openstack/storage/cinder.conf" << END
# add follows to the end
[lvm]
iscsi_helper = lioadm
# volume group name just created
volume_group = vg-data
# IP address of Storage Node
iscsi_ip_address = $storage
volume_driver = cinder.volume.drivers.lvm.LVMVolumeDriver
volumes_dir = \$state_path/volumes
iscsi_protocol = iscsi
END
scp /root/openstack/storage/cinder.conf root@$storage:/etc/cinder/
echo "export OS_VOLUME_API_VERSION=2" >> /root/keystonerc
printf "======================================Restart cinder-volume service=============================\n"
sleep 2
ssh root@$storage "systemctl restart openstack-cinder-volume "
#####cinder compute node
cinder_nova='/root/openstack/compute/nova.conf'
cat >> "/root/openstack/compute/nova.conf" << END