Advertisement
efattibene

Hands-on Corso Cloud@CNAF

May 21st, 2014
561
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Corso Cloud@Cnaf - Hands on
  2.  
  3. # PARTE 1 - BASIC
  4. # questa parte e' gia' stata fatta attraverso la dashboard
  5. # Source credentials file
  6. source userXX-openrc.sh
  7.  
  8. # Change user password
  9. keystone password-update
  10.  
  11. # Create private network
  12. neutron net-create private_net
  13.  
  14. # Associate subnet
  15. neutron subnet-create --name private_subnet private_net 10.0.1.0/24
  16.  
  17. # Check private network and subnet
  18. neutron net-list
  19. neutron subnet-list
  20.  
  21. # create router
  22. neutron router-create myrouter
  23.  
  24. # uplink router to the public internet (set gateway)
  25. neutron router-gateway-set myrouter public
  26.  
  27. # uplink subnet to router
  28. neutron router-interface-add myrouter private_subnet
  29.  
  30. # create security profile for jump host
  31. neutron security-group-create jumphost
  32.  
  33. # Add rule to allow icmp in
  34. neutron security-group-rule-create --protocol icmp jumphost
  35.  
  36. # Add rule to allow ssh in
  37. neutron security-group-rule-create --protocol tcp --port-range-min 22 --port-range-max 22 jumphost
  38.  
  39. # Create ssh key and paste output into mykey.pem
  40. nova keypair-add mykey
  41. chmod 600 mykey.pem  # mykey.pem must contain output from previous command
  42.  
  43. # Launch jump host:
  44. nova boot --image SL-65 --flavor m1.small jumphost --security_groups jumphost --key-name mykey # retrieve admin (root) password by the output of nova boot command
  45.  
  46. # Check running vm
  47. nova list
  48.  
  49. # Determine port-id attached to jumphost
  50. neutron port-list --device_id=<instance_id>
  51.  
  52. # Create floatingip
  53. neutron floatingip-create public --port-id <port-id>
  54.  
  55. # Test ping/ssh
  56. nova list
  57. ping -c 3 131.154.96.xxx
  58. ssh -i mykey.pem cloud-user@131.154.96.xxx
  59.  
  60.  
  61. ############################################
  62. # PARTE 2 - ADVANCED
  63. # Source credentials file
  64. source userXX-openrc.sh
  65.  
  66. # Check private network, subnet, running vm
  67. neutron net-list
  68. neutron subnet-list
  69. neutron router-list
  70. nova list
  71.  
  72. # Create web security group
  73. neutron security-group-create web
  74.  
  75. # Allow tcp 80 in
  76. neutron security-group-rule-create --protocol TCP --port-range-min 80 --port-range-max 80 web
  77.  
  78. # Allow ssh from members of jumphost
  79. neutron security-group-rule-create --direction ingress --protocol TCP --port-range-min 22 --port-range-max 22 --remote-group-id jumphost web
  80.  
  81. # Boot two webservers
  82. # Retrieve admin (root) password by the output of nova boot command
  83. nova boot --image SL-65 --flavor m1.small webserver1 --security_groups web --key-name mykey
  84. nova boot --image SL-65 --flavor m1.small webserver2 --security_groups web --key-name mykey
  85. nova list
  86.  
  87. # Copy private key to jumphost
  88. # SSH to jumphost (floating-ip = 131.154.96.xxx)
  89. scp -i mykey.pem mykey.pem cloud-user@<floating-ip>:
  90. ssh -i mykey.pem cloud-user@<floating-ip>
  91.  
  92. # SSH to webserver1
  93. ssh -i mykey.pem 10.0.1.x
  94.  
  95. # Start dummy webserver
  96. sudo su -
  97. echo "Welcome to $HOSTNAME" > /var/www/html/index.html
  98. /etc/init.d/httpd start
  99. chkconfig httpd on
  100. curl 10.0.1.x
  101.  
  102. # Exit from root user in webserver1
  103. exit
  104.  
  105. # Exit from webserver1 to jumphost
  106. exit
  107.  
  108. # Repeat for webserver2
  109.  
  110. # From jumphost: curl <webserver1-ip>
  111. Welcome to webserver1
  112.  
  113. # From jumphost: curl <webserver2-ip>
  114. Welcome to webserver2
  115.  
  116. # Exit from jumphost
  117. exit
  118.  
  119. # Create loadbalanacer pool
  120. neutron subnet-list
  121. neutron lb-pool-create --lb-method ROUND_ROBIN --name mypool --protocol HTTP --subnet-id <private_subnet_ID>
  122.  
  123. # Add webservers as memebers
  124. neutron lb-member-create --address <webserver_1_ip> --protocol-port 80 mypool
  125. neutron lb-member-create --address <webserver_2_ip> --protocol-port 80 mypool
  126.  
  127. # Create health monitor
  128. neutron lb-healthmonitor-create --delay 3 --type HTTP --max-retries 3 --timeout 3
  129.  
  130. # Associate with pool
  131. neutron lb-healthmonitor-associate <heath-monitor-id> mypool
  132.  
  133. # Create vip for loadbalaner
  134. neutron lb-vip-create --name myvip --protocol-port 80 --protocol HTTP --subnet-id <private_subnet_ID> mypool
  135.  
  136. # Associate floatingip to vip
  137. neutron floatingip-create public --port-id <port_ID da output comando precedente>
  138.  
  139. # Requests are now loadbalanced over vip ip:
  140. curl <vip-floatingip>
  141.  
  142. # Test loadbalancer timeout
  143. nova stop webserver1
  144. curl <vip-floatingip> #only returns webserver2, after a while
  145.  
  146. # Start the stopped node
  147. nova start webserver1
  148. curl <vip-floatingip> #loadbalances again the requests between the two nodes
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement