chrisluiz16

Day 12

Jun 3rd, 2023
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.06 KB | None | 0 0
  1.  
  2.  
  3.  
  4.  
  5. #---------------------------------------------------- Task 1 IPgeolacation-api --------------------------------------------#
  6.  
  7.  
  8.  
  9. [ec2-user@ip-172-31-41-59 ~]$
  10. [ec2-user@ip-172-31-41-59 ~]$
  11. [ec2-user@ip-172-31-41-59 ~]$ docker network create ip-net
  12. 678148d6ccb2d7fbf1ef323371d5df9e6fb9a5d79a6f97a4c452d69394deb99a
  13. [ec2-user@ip-172-31-41-59 ~]$
  14. [ec2-user@ip-172-31-41-59 ~]$
  15.  
  16. [ec2-user@ip-172-31-41-59 ~]$ docker container run \
  17. > --name redis \
  18. > --restart always \
  19. > --network ip-net \
  20. > -d \
  21. > redis:latest
  22. Unable to find image 'redis:latest' locally
  23. latest: Pulling from library/redis
  24.  
  25. [ec2-user@ip-172-31-41-59 ~]$ docker container run \
  26. > --name ip-api1 \
  27. > --network ip-net \
  28. > --restart always \
  29. > -d \
  30. > -e REDIS_PORT="6379" \
  31. > -e REDIS_HOST="redis" \
  32. > -e APP_PORT="8080" \
  33. > -e API_KEY="48c444472b0840848c261f62abe32b0d" \
  34. > fujikomalan/ipgeolocation-api-service
  35. 37ba7046fedfec3f7b5095d04aaf386cd5fe133ff3b957e51b5657dc0753d40b
  36. [ec2-user@ip-172-31-41-59 ~]$
  37. [ec2-user@ip-172-31-41-59 ~]$
  38. [ec2-user@ip-172-31-41-59 ~]$ docker container run --name ip-api2 --network ip-net --restart always -d -e REDIS_PORT="6379" -e REDIS_HOST="redis" -e APP_PORT="8080" -e API_KEY="48c444472b0840848c261f62abe32b0d" fujikomalan/ipgeolocation-api-service
  39. 258848e736a156b5d87d7cdb816cc0fc78fcfacd43bb0e09a9147ca9613da2aa
  40. [ec2-user@ip-172-31-41-59 ~]$
  41. [ec2-user@ip-172-31-41-59 ~]$
  42. [ec2-user@ip-172-31-41-59 ~]$
  43. [ec2-user@ip-172-31-41-59 ~]$ docker container run --name ip-api3 --network ip-net --restart always -d -e REDIS_PORT="6379" -e REDIS_HOST="redis" -e APP_PORT="8080" -e API_KEY="48c444472b0840848c261f62abe32b0d" fujikomalan/ipgeolocation-api-service
  44. be25e445c1adfbe576e74b983221d5011f2dd51450bce2c9b3fdeef2337be4bf
  45. [ec2-user@ip-172-31-41-59 ~]$
  46.  
  47.  
  48.  
  49. #---------------------------------------------------- Task 1.1 nginx container --------------------------------------------#
  50.  
  51.  
  52. [______________________________________________SSL from freessl.org_________________________________________]
  53.  
  54.  
  55. [ec2-user@ip-172-31-41-59 certs]$ cat ipgeolocation.chrisich.fun.pem intermediate.pem root.pem > ssl.crt
  56. [ec2-user@ip-172-31-41-59 certs]$
  57. [ec2-user@ip-172-31-41-59 certs]$
  58. [ec2-user@ip-172-31-41-59 certs]$ mv ipgeolocation.chrisich.fun.key ssl.key
  59. [ec2-user@ip-172-31-41-59 certs]$ ll
  60. total 32
  61. -rwxr-xr-x. 1 ec2-user ec2-user 4041 Jun 3 08:53 intermediate.pem
  62. -rwxr-xr-x. 1 ec2-user ec2-user 6103 Jun 3 08:53 ipgeolocation.chrisich.fun.pem
  63. -rwxr-xr-x. 1 ec2-user ec2-user 2093 Jun 3 08:53 root.pem
  64. -rw-r--r--. 1 ec2-user ec2-user 12237 Jun 3 08:57 ssl.crt
  65. -rwxr-xr-x. 1 ec2-user ec2-user 1732 Jun 3 08:53 ssl.key
  66.  
  67. [ec2-user@ip-172-31-41-59 ssl]$ cat default.conf
  68. server {
  69. listen 80;
  70. listen [::]:80;
  71. return 301 https://$host$request_uri;
  72. server_name ipgeolocation.chrisich.fun;
  73.  
  74.  
  75.  
  76. }
  77.  
  78. server {
  79. listen 443 ssl;
  80. server_name ipgeolocation.chrisich.fun;
  81.  
  82.  
  83. ssl_certificate /etc/nginx/cert/ssl.crt;
  84. ssl_certificate_key /etc/nginx/cert/ssl.key;
  85.  
  86. location / {
  87. proxy_pass http://flaskapps;
  88. proxy_set_header Host $host;
  89. proxy_set_header X-Real-IP $remote_addr;
  90. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  91. proxy_set_header X-Forwarded-Proto $scheme;
  92. }
  93.  
  94. }
  95.  
  96. upstream flaskapps{
  97. server ip-api1:8080;
  98. server ip-api2:8080;
  99. server ip-api3:8080;
  100.  
  101. }
  102.  
  103.  
  104. [ec2-user@ip-172-31-41-59 ssl]$ docker container run \
  105. > --name nginx \
  106. > --restart always \
  107. > --network ip-net \
  108. > -p 80:80 -p 443:443 \
  109. > -d \
  110. > -v $(pwd)/default.conf:/etc/nginx/conf.d/default.conf \
  111. > -v $(pwd)/certs/:/etch/nginx/cert/ \
  112. > nginx:latest
  113.  
  114.  
  115. [ec2-user@ip-172-31-41-59 ssl]$ docker container ls -a
  116. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  117. 81b5ce908a89 nginx:latest "/docker-entrypoint.…" 22 minutes ago Up 22 minutes 0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp nginx
  118. be25e445c1ad fujikomalan/ipgeolocation-api-service "python3 app.py" About an hour ago Up About an hour 8080/tcp ip-api3
  119. 258848e736a1 fujikomalan/ipgeolocation-api-service "python3 app.py" About an hour ago Up About an hour 8080/tcp ip-api2
  120. 37ba7046fedf fujikomalan/ipgeolocation-api-service "python3 app.py" 2 hours ago Up 2 hours 8080/tcp ip-api1
  121. 3d95675a1e56 redis:latest "docker-entrypoint.s…" 2 hours ago Up 2 hours 6379/tcp redis
  122.  
  123.  
  124.  
  125. #---------------------------------------------------- Task 2 Redsis-cli --------------------------------------------#
  126.  
  127.  
  128.  
  129. [ec2-user@ip-172-31-41-59 ssl]$ docker container exec redis cat /etc/os-release
  130. PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
  131. NAME="Debian GNU/Linux"
  132. VERSION_ID="11"
  133. VERSION="11 (bullseye)"
  134. VERSION_CODENAME=bullseye
  135. ID=debian
  136. HOME_URL="https://www.debian.org/"
  137. SUPPORT_URL="https://www.debian.org/support"
  138. BUG_REPORT_URL="https://bugs.debian.org/"
  139. [ec2-user@ip-172-31-41-59 ssl]$
  140. [ec2-user@ip-172-31-41-59 ssl]$
  141. [ec2-user@ip-172-31-41-59 ssl]$ docker container exec -it redis bash
  142. root@3d95675a1e56:/data#
  143. root@3d95675a1e56:/data#
  144. root@3d95675a1e56:/data# redis-cli
  145. 127.0.0.1:6379>
  146. 127.0.0.1:6379>
  147. 127.0.0.1:6379>
  148. 127.0.0.1:6379> KEYS * [List all the keys]
  149. 1) "9.9.9.9"
  150. 2) "1.1.1.1"
  151. 127.0.0.1:6379>
  152. 127.0.0.1:6379>
  153. 127.0.0.1:6379> GET 9.9.9.9 [showing one key value]
  154. "{\"ip\": \"9.9.9.9\", \"continent_code\": \"EU\", \"continent_name\": \"Europe\", \"country_code2\": \"CH\", \"country_code3\": \"CHE\", \"country_name\": \"Switzerland\", \"country_capital\": \"Bern\", \"state_prov\": \"Zurich\", \"state_code\": \"CH-ZH\", \"district\": \"\", \"city\": \"Zurich\", \"zipcode\": \"8004\", \"latitude\": \"47.37328\", \"longitude\": \"8.53113\", \"is_eu\": false, \"calling_code\": \"+41\", \"country_tld\": \".ch\", \"languages\": \"de-CH,fr-CH,it-CH,rm\", \"country_flag\": \"https://ipgeolocation.io/static/flags/ch_64.png\", \"geoname_id\": 12003391, \"isp\": \"Quad9\", \"connection_type\": \"\", \"organization\": \"Quad9\", \"currency\": {\"code\": \"CHF\", \"name\": \"Swiss Franc\", \"symbol\": \"CHF\"}, \"time_zone\": {\"name\": \"Europe/Zurich\", \"offset\": 1, \"current_time\": \"2023-06-03 11:24:53.733+0200\", \"current_time_unix\": 1685784293.733, \"is_dst\": true, \"dst_savings\": 1}, \"cached\": \"False\", \"apiServer\": \"37ba7046fedf\"}"
  155.  
  156. 127.0.0.1:6379>
  157. 127.0.0.1:6379> DEL 9.9.9.9 [Deleting one key value]
  158. (integer) 1
  159. 127.0.0.1:6379>
  160. 127.0.0.1:6379> KEYS *
  161. 1) "1.1.1.1
  162.  
  163. "127.0.0.1:6379>
  164. 127.0.0.1:6379>
  165. 127.0.0.1:6379> FLUSHALL [Flushing all keys]
  166. OK
  167. 127.0.0.1:6379>
  168. 127.0.0.1:6379> KEYS *
  169. (empty array)
Advertisement
Add Comment
Please, Sign In to add comment