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 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
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
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
https://fdns.uk https://www.noip.com/ Note: no dash is allowed Portland State University CS 430P/530 Internet, Web & Cloud Systems
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
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
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
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
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
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
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
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
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
Databases
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
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
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
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
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
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
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
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
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
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
Cleanup eanup Shutdown the Cloud SQL instance to avoid… Portland State University CS 430P/530 Internet, Web & Cloud Systems
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
Recommend
More recommend