labs 2 webdev web ebde dev v lab 1
play

Labs #2 WebDev Web ebDe Dev v Lab #1 On your local Ubuntu VM, - PowerPoint PPT Presentation

Labs #2 WebDev Web ebDe Dev v Lab #1 On your local Ubuntu VM, install the Python and C development tools, then run the app locally sudo apt update sudo apt install python3-dev build-essential git clone


  1. Labs #2

  2. WebDev

  3. Web ebDe Dev v Lab #1  On your local Ubuntu VM, install the Python and C development tools, then run the app locally sudo apt update sudo apt install python3-dev build-essential git clone https://bitbucket.org/wuchangfeng/cs430-src cd cs430-src/WebDev_Guestbook_v3_nginx_uwsgi virtualenv -p python3 env source env/bin/activate pip install -r requirements.txt installs Flask, uwsgi packages python app.py  Bring up a browser on the VM and point the browser to the web app (localhost:5000)  Add several entries that include your OdinID and show the resulting page Portland State University CS 430P/530 Internet, Web & Cloud Systems

  4.  On GCP (Compute Engine), create instance  Ubuntu 18.04 LTS on an f1-micro instance within the us-west1-b zone  Also allow both HTTP and HTTPS traffic to the instance Portland State University CS 430P/530 Internet, Web & Cloud Systems

  5.  Record the external IP address of your Compute Engine instance  Important: keep this instance running for rest of lab.  Register a DNS name cs430-<OdinID> on ipq.co , fdns.uk , or noip.com that points to your instance  https://ipq.co/  If you get a rate-limit error on Let's Encrypt, use https://www.noip.com/ or https://fdns.uk Portland State University CS 430P/530 Internet, Web & Cloud Systems

  6.  https://fdns.uk  https://www.noip.com/  Note: no dash is allowed Portland State University CS 430P/530 Internet, Web & Cloud Systems

  7.  https://www.freenom.com/  Or use xip.io and its rip-offs  http://nip.io/  https://sslip.io/  http://xip.io/ Portland State University CS 430P/530 Internet, Web & Cloud Systems

  8.  ssh into instance and clone course repository git clone https://bitbucket.org/wuchangfeng/cs430-src  Navigate to WebDev_Guestbook_v3_nginx_uwsgi for uwsgi setup  Examine app.ini  Configures entry-point, number of processes, communication channel  Examine wsgi.py  Called upon initialization of uwsgi  Import app from app.py and run it Portland State University CS 430P/530 Internet, Web & Cloud Systems

  9.  Examine etc/systemd.template  systemd system and service manager for Ubuntu 18  Configures startup of uwsgi daemon and its environment  Permissions set to Unix account of nginx ( www-data )  Working directory set to PROJECT_DIR (replaced on installation with your directory)  PATH environment variable set to location of binaries for pre-installed Python environment (assumes virtualenv 's env is in PROJECT_DIR )  Specify command to start uwsgi daemon using config file from previous slide Portland State University CS 430P/530 Internet, Web & Cloud Systems

  10.  Examine etc/nginx.template  Configure nginx web server using your DNS name and point reverse proxy to uwsgi socket  server_name being served by configuration (replaced on installation with IPQuick name, e.g. cs430-wuchang.ipq.co )  root file system location to serve web application files from  Specify / path served by uwsgi and the python app  uwsgi_pass to specify location of unix domain socket for communication  Specify /static path to be served directly by nginx from specified directory Portland State University CS 430P/530 Internet, Web & Cloud Systems

  11.  Examine install.sh  Will be invoked with your DNS name  (e.g. ./ install.sh cs430-wuchang.ipq.co )  Script pulls out first part of the DNS-name (cs430-wuchang) (e.g. eliminates first period and all subsequent characters)  Used to name systemd service  Installs python , virtualenv , nginx , and certbot . Create virtualenv environment for web application and install packages into it from requirements.txt Portland State University CS 430P/530 Internet, Web & Cloud Systems

  12.  Examine install.sh (cont.)  Sets up systemd startup file for uwsgi . Name it using the first part of site name ( $SITE from previous slide)  Substitute PROJECT_DIR and PROJECT_USER based on current directory ( $PWD ) and current user ( $SUDO_USER )  Note sed use of + instead of / (since / is used in PROJECT_DIR ) Portland State University CS 430P/530 Internet, Web & Cloud Systems

  13.  Examine install.sh (cont.)  Sets up nginx startup to add site (done via adding config file to /etc/nginx/sites-available and a link in /etc/nginx/sites-enabled to it) Portland State University CS 430P/530 Internet, Web & Cloud Systems

  14.  Examine install.sh (cont.)  Changes ownership to allow nginx (via www-data account) to create domain socket  Starts systemd service for site via systemctl , enables it by default (on startup), and restarts nginx for changes to take hold  Obtains the TLS certificate via certbot in non-interactive mode (see TLS slides on Let's Encrypt) Portland State University CS 430P/530 Internet, Web & Cloud Systems

  15. Web ebDe Dev Lab #1  Run the install script, show site  sudo ./install.sh cs430-wuchang.ipq.co Portland State University CS 430P/530 Internet, Web & Cloud Systems

  16. Databases

  17. Da Databases tabases Lab #1 Do this quiz  http://www.w3schools.com/sql/sql_quiz.asp  Screenshot of "Check your answers"  Does not have to be perfect (mine wasn't), but check the ones you got incorrect Portland State University CS 430P/530 Internet, Web & Cloud Systems

  18. Da Databases tabases Lab #2 (Cloud ud SQL QL)  Create a Managed MySQL database with Cloud SQL  Set-up and query using a Cloud MySQL instance Portland State University CS 430P/530 Internet, Web & Cloud Systems

  19. Setup etup  From Google Cloud Shell, download data git clone https://github.com/GoogleCloudPlatform/training-data-analyst  Examine schema and data in CSV (comma separated values) format cd training-data-analyst/CPB100/lab3a less cloudsql/table_creation.sql head cloudsql/*.csv  Stage data definition file and values in a storage bucket so it can be imported by Cloud SQL service  Create a storage bucket gsutil mb -c regional -l us-west1 gs://<BUCKET-NAME> gsutil cp cloudsql/* gs://<BUCKET-NAME>/sql/  Verify files are in Cloud Storage bucket via web console Portland State University CS 430P/530 Internet, Web & Cloud Systems

  20. Create a new Cloud SQL instance  In the Google Cloud Console, scroll down and select SQL in the Storage subsection Portland State University CS 430P/530 Internet, Web & Cloud Systems

  21. Create a new Cloud SQL instance  Create an instance  Choose MySQL (Second Generation)  Name the Instance ID: rentals  Set and remember the root password for the database  Place in us-west1-b Portland State University CS 430P/530 Internet, Web & Cloud Systems

  22. Conf nfig igure ure access cess to i instance stance from om Cloud ud Shell ell  In Cloud Shell, find the external IP address of the shell curl http://ipecho.net/plain; echo  Within Cloud SQL, click on the instance, then on "Edit", then on "Connectivity" under Configuration Options, then on "Add Network"  We will be adding the Cloud Shell IP address to authorized addresses that can connect to the instance Portland State University CS 430P/530 Internet, Web & Cloud Systems

  23. Conf nfig igure ure access cess to i instance stance from om Cloud ud Shell ell  Enter the IP address found previously with ipecho as a CIDR route  e.g. 131.252.220.66/32  Click on "Done", then "Close"  Ensure it appears in "Authorized Networks", then "Save" Fill in your Cloud Shell's IP address here as a CIDR prefix Portland State University CS 430P/530 Internet, Web & Cloud Systems

  24. Import table definitions and tables (from Cloud Storage bucket)  Click on the hyperlink named rentals (i.e. your Cloud SQL instance name)  Click on Import (on the top menu bar)  Click on the Browse button and browse to your storage bucket containing the SQL lab files  Navigate to table_creation.sql  Select and click Import. Portland State University CS 430P/530 Internet, Web & Cloud Systems

  25. Populate tables  Import the two CSV files from Cloud Storage  Within Cloud SQL instance, click on Import (top menu)  Click Browse, then find and select accommodation.csv  Fill out the rest of the dialog  Database = recommendation_spark  Table = Accommodation  Repeat for rating.csv  Table = Rating Portland State University CS 430P/530 Internet, Web & Cloud Systems

  26. Use se Cloud ud SQL QL  Connect to instance mysql --host=<MySQLIP> --user=root --password  Set database for MySQL session use recommendation_spark;  View tables created show tables;  Verify data select * from Rating;  Run queries for accommodations at various price levels and types select * from Accommodation where… Portland State University CS 430P/530 Internet, Web & Cloud Systems

  27. Cleanup eanup  Shutdown the Cloud SQL instance to avoid… Portland State University CS 430P/530 Internet, Web & Cloud Systems

  28. Da Databases tabases Lab #2 (Cloud ud SQL QL)  https://codelabs.developers.google.com/codelabs/cpb100-cloud-sql (22 min) Portland State University CS 430P/530 Internet, Web & Cloud Systems

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend