2019年5月25日 星期六

Cloud Shell & gcloud -- Google Cloud Platform GCP 實際操作實習手冊

Overview

Google Cloud Shell provides you with gcloud command-line access to computing resources hosted on the Google Cloud Platform. Cloud Shell is a Debian-based virtual machine with a persistent 5GB home directory, which makes it easy for you to manage your GCP projects and resources. The Cloud SDK gcloud and other utilities you need come pre-installed in Cloud Shell, which allows you to get up and running quickly.
In this hands-on lab, you will learn how to connect to computing resources hosted on the Google Cloud Platform via Cloud Shell. You will learn how to use Cloud Shell and the gcloud command.
We encourage students to type the commands themselves, to help encourage learning of the core concepts. Many labs will include a code block that contains the required commands. You can easily copy and paste the commands from the code block into the appropriate places during the lab.

What you'll do

  • Practice using gcloud commands.
  • Connect to storage services hosted on the Google Cloud Platform.

Prerequisites

  • Familiarity with standard Linux text editors such as vimemacs, or nano.

Setup

Before you click the Start Lab button

Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Cloud resources will be made available to you.
This Qwiklabs hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access the Google Cloud Platform for the duration of the lab.

What you need

To complete this lab, you need:
  • Access to a standard internet browser (Chrome browser recommended).
  • Time to complete the lab.
Note: If you already have your own personal GCP account or project, do not use it for this lab.

How to start your lab and sign in to the Console

  1. Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is a panel populated with the temporary credentials that you must use for this lab.
    Open Google Console
  2. Copy the username, and then click Open Google Console. The lab spins up resources, and then opens another tab that shows the Choose an account page.
    Tip: Open the tabs in separate windows, side-by-side.
  3. On the Choose an account page, click Use Another Account.
    Choose an account
  4. The Sign in page opens. Paste the username that you copied from the Connection Details panel. Then copy and paste the password.
    Important: You must use the credentials from the Connection Details panel. Do not use your Qwiklabs credentials. If you have your own GCP account, do not use it for this lab (avoids incurring charges).
  5. Click through the subsequent pages:
    • Accept the terms and conditions.
    • Do not add recovery options or two-factor authentication (because this is a temporary account).
    • Do not sign up for free trials.
After a few moments, the GCP console opens in this tab.

Activate Google Cloud Shell

Google Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Google Cloud Shell provides command-line access to your GCP resources.
  1. In GCP console, on the top right toolbar, click the Open Cloud Shell button.
    Cloud Shell icon
  2. In the dialog box that opens, click START CLOUD SHELL:
    Start Cloud Shell
It takes a few moments to provision and connect to the environment. When you are connected, you are already authenticated, and the project is set to your PROJECT_ID. For example:
Cloud Shell Terminal
gcloud is the command-line tool for Google Cloud Platform. It comes pre-installed on Cloud Shell and supports tab-completion.
You can list the active account name with this command:
gcloud auth list
Output:
Credentialed accounts:
 - <myaccount>@<mydomain>.com (active)
Example output:
Credentialed accounts:
 - google1623327_student@qwiklabs.net
You can list the project ID with this command:
gcloud config list project
Output:
[core]
project = <project_ID>
Example output:
[core]
project = qwiklabs-gcp-44776a13dea667a6

Understanding Regions and Zones

Certain Compute Engine resources live in regions or zones. A region is a specific geographical location where you can run your resources. Each region has one or more zones. For example, the us-central1 region denotes a region in the Central United States that has zones us-central1-aus-central1-bus-central1-c, and us-central1-f.
regions_and_zones.png
Resources that live in a zone are referred to as zonal resources. Virtual machine Instances and persistent disks live in a zone. To attach a persistent disk to a virtual machine instance, both resources must be in the same zone. Similarly, if you want to assign a static IP address to an instance, the instance must be in the same region as the static IP.

Use the command line

Open a new Cloud Shell session by clicking on the icon in the top right corner of the GCP Console:
cloud-shell.png
After Cloud Shell is activated you can use the command line to invoke the Cloud SDK gcloud command or other tools available on the virtual machine instance. You can also use your $HOME directory in persistent disk storage to store files across projects and between Cloud Shell sessions. Your $HOME directory is private to you and cannot be accessed by other users.
Let's take a look at some of the commands available.
gcloud offers simple usage guidelines that are available by adding the -h flag onto the end of any gcloud invocation. Run the following command in Cloud Shell:
gcloud -h
More verbose help can be obtained by appending --help flag, or executing gcloud help command. Run the following in Cloud Shell:
gcloud config --help
Press use the enter key or the spacebar to scroll through the help content. Press q to exit the content. Now run the following command:
gcloud help config
You can see that the gcloud config --help and gcloud help config commands are equivalent. Both give long, detailed help.

Use your home directory

Now let's try out your home directory. The contents of your Cloud Shell home directory persists across projects between all Cloud Shell sessions, even after the virtual machine terminates and is restarted.
Change your current working directory:
cd $HOME
Open your .bashrc configuration file using vi.
vi ./.bashrc
The editor opens and displays the contents of the file. Press the ESC key and then :q to exit the editor.

Using gcloud commands

Let's view the list of configuration in our environment. From reading the long, detailed help results in the previous step, we know we can use the command gcloud list.
gcloud config list
To check how other properties are set, see all properties by calling:
gcloud config list --all

Managing Cloud Storage data

You can use the gsutil tool in Cloud Shell to manage Cloud Storage resources. This includes creating and deleting buckets and objects, copying and moving storage data, and managing bucket and object ACLs. gsutil will also let you transfer data in and out of your Cloud Shell instance.
Try creating a Cloud Storage bucket. Bucket names must be unique, so replace unique-name with something else, or append the name to make it unique.
gsutil mb gs://unique-name

Now we'll create some data to upload to your bucket.
First, create a test file:
vi test.dat
Start the editor:
i
Add some data to your file:
Welcome to gcloud!
Save the test.dat file: <ESC>, then
:wq
Now upload some data to the bucket you created (make sure to replace "unique-name" with your storage bucket):
gsutil cp test.dat gs://unique-name
To see your bucket and file, open the navigation menu and select Storage > Browser. Then click on your bucket. You should see the test.dat file:
storage-bucket.png


Compute Engine: Qwik Start - Windows -- Google Cloud Platform GCP 實際操作實習手冊

Google Compute Engine lets you create and run virtual machines on Google infrastructure. Compute Engine offers scale, performance, and value that allows you to easily launch large compute clusters on Google's infrastructure.
You can run your Windows applications on Google Compute Engine and take advantage of many benefits available to virtual machine instances such as reliablestorage options, the speed of the Google network, and Autoscaling.
In this hands-on lab, you will learn how to launch a Windows Server instance in Google Compute Engine, and connect to it using the Remote Desktop Protocol.
If you aren't using Windows on your local machine, install a third-party RDP client such as Chrome RDP by FusionLabs.

Setup and Requirements

Before you click the Start Lab button

Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Cloud resources will be made available to you.
This Qwiklabs hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access the Google Cloud Platform for the duration of the lab.

What you need

To complete this lab, you need:
  • Access to a standard internet browser (Chrome browser recommended).
  • Time to complete the lab.
Note: If you already have your own personal GCP account or project, do not use it for this lab.

How to start your lab and sign in to the Console

  1. Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is a panel populated with the temporary credentials that you must use for this lab.
    Open Google Console
  2. Copy the username, and then click Open Google Console. The lab spins up resources, and then opens another tab that shows the Choose an account page.
    Tip: Open the tabs in separate windows, side-by-side.
  3. On the Choose an account page, click Use Another Account.
    Choose an account
  4. The Sign in page opens. Paste the username that you copied from the Connection Details panel. Then copy and paste the password.
    Important: You must use the credentials from the Connection Details panel. Do not use your Qwiklabs credentials. If you have your own GCP account, do not use it for this lab (avoids incurring charges).
  5. Click through the subsequent pages:
    • Accept the terms and conditions.
    • Do not add recovery options or two-factor authentication (because this is a temporary account).
    • Do not sign up for free trials.
After a few moments, the GCP console opens in this tab.


Create a virtual machine instance

In the GCP Console, go to Compute Engine > VM instances, then click Create.
b4ddd59640deb64e.png
In the Boot disk section, click Change to begin configuring your boot disk.
4b849540c49066e9.png
Choose Windows Server 2012 R2 Datacenter, then Select. Leave all other settings at their defaults.
6828f25897d732e6.png
Click the Create button to create the instance.

Activate Google Cloud Shell

Google Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Google Cloud Shell provides command-line access to your GCP resources.
  1. In GCP console, on the top right toolbar, click the Open Cloud Shell button.
    Cloud Shell icon
  2. In the dialog box that opens, click START CLOUD SHELL:
    Start Cloud Shell
It takes a few moments to provision and connect to the environment. When you are connected, you are already authenticated, and the project is set to your PROJECT_ID. For example:
Cloud Shell Terminal
gcloud is the command-line tool for Google Cloud Platform. It comes pre-installed on Cloud Shell and supports tab-completion.
You can list the active account name with this command:
gcloud auth list
Output:
Credentialed accounts:
 - <myaccount>@<mydomain>.com (active)
Example output:
Credentialed accounts:
 - google1623327_student@qwiklabs.net
You can list the project ID with this command:
gcloud config list project
Output:
[core]
project = <project_ID>
Example output:
[core]
project = qwiklabs-gcp-44776a13dea667a6


Test the status of Windows Startup

Allow a short time for the Windows Server instance to start up. Once it has been provisioned, it will be listed on the VM Instances page with a green status icon.
However it may not yet be ready to accept RDP connections, as it takes a while for all the OS components to initialize.
To see whether the server is ready for an RDP connection, run the following command at your Cloud Shell terminal command line:
gcloud compute instances get-serial-port-output instance-1 --zone us-central1-a
Repeat the command until you see the following in the command output, which tells you that the OS components have initialized and the Windows Server is ready to accept your RDP connection (attempt in the next step).
Finished running startup scripts.

Connect to your instance

Click the name of your virtual machine:
d6c378522f91ab55.png
Under the Remote Access section, click the Set Windows Password button.
8126ec53a6b696d9.png
A username will be generated.
Click Set to generate a password for this Windows instance. This may take several minutes to complete.
Copy the password and save it so you can log into the instance.
90c54fe047cebc0.png

Remote desktop (RDP) into the Windows Server

It's time to RDP into the Windows Server. You can RDP directly from the browser using the Chrome RDP for Google Cloud Platform extension. Click on RDP to connect.
CompEng_windows_rdp.png
This prompts you to install the RDP Extension. Once installed, GCP opens up a login page where you use your Windows user and password to log in. Paste in the password you saved earlier.
178d465523cf95cc.png
Click Continue to confirm you want to connect.
62ad6ace227976b9.png
When Server Manager opens you are connected to instance-1, the VM instance on the Windows Server.

Copy and pasting with the RDP client

Once you are securely logged in to your stance, you may find yourself copying and pasting commands from the lab manual.
To paste, hold the CTRL-V keys (if you are a Mac user, using CMND-V will not work.) If you are in a Powershell window, be sure that you have clicked in to the window or else the paste shortcut won't work.
If you are pasting into putty, right click.

2016年2月20日 星期六

哈佛大學長達75年的「快樂」研究:美好人生建立於良好關係(轉自 TEDXTaipei)

你的人生目標是什麼?
根據一份最近針對千禧年出生的年輕人所做的調查,有超過八成的年輕人表示他們的人生目標是想成為有錢人,而有五成的年輕人說他們另個人生目標是變得有名。
happiness (photo from psychologytoday.com)
其實並不難想像調查中年輕人對於名利的想望,起因於我們時常被規勸要在工作上全力以赴、接受更多挑戰、達成更高目標;這個想法也使我們對人生產生了一種想像:為了要有美好生活,必須實踐「拼命三郎」的行為模式與生活形態。
由美國哈佛大學教授塔爾班夏哈(Tal Ben-Shahar)所撰寫的暢銷書《更快樂》(Happier: Learn the Secrets to Daily Joy and Lasting Fulfillment)中,以「正向心理學」說明了拼命三郎型的人們把達成目標當成衡量成就的標準,而不重視追求目標的過程,以致於他們無法享受所做的 事情,老以為達到某個目標就能得到快樂。
班夏哈教授指出,實證研究和名人事蹟的確顯示,設定目標和個人成就確實有關聯,不過,和快樂之間就沒有直接關係。這也解釋了為何有些人達成目標後,卻沒有感受到原本預期會獲得的快樂感。

撇開功成名就,但如果其實快樂、健康、滿足感才是我們應該追求的人生終極目標,那又該如何達成?
哈佛大學醫學院臨床精神病學教授羅伯威丁格Robert Waldinger從他所主持的史上最長的「幸福感」(Happiness)研究,給了我們一個值得參考的答案。

Robert Waldinger: What makes a good life? Lessons from the longest study on happiness
這個哈佛大學針對成人生活所作的研究至今已進行75年,而威丁格教授是該研究的第四個主持人。從1938年開始,研究總共追蹤了724位成人,每一年研究團隊都會詢問研究對象的工作、生活、健康等狀況。
類似如此長期的大型研究都會面臨一些挑戰,例如:受測者中途退出、研究經費不足、研究員研究重心轉移或死亡而無人接手。但是基於堅持與運氣,原先的七百多位受測者中,至今還存活的大約有60%,而他們也都已經九十多歲。
研究是從兩大群背景迥異的美國波士頓居民開始。第一組是哈佛大學的大二學生,他們後來在二次世界大戰期間全都完成大學文憑,並且大部份的人都從軍參與戰事。第二組則是從波士頓地區最貧困的地區挑選出來的居民,他們住在破舊的房舍中,許多人家中都沒有乾淨的冷熱水。
當他們同意參加研究後,所有的青少年都被逐一訪談並接受醫療檢查,除此之外,研究人員還到所有研究對象的家中拜訪,親自與他們的父母親面談。後來這 些青少年長大成人了,進入各行各業,有工廠工人、律師、瓦工、醫生、某一任美國總統等;也有些人酗酒,有些人患有精神分裂,有些人從社會底層一路往上爬至 上流階級,也有些人則往全然不同的方向走。
大概在75年前沒有人可以想像這個研究至今仍持續進行,只是目前研究對象也開始轉向原先七百多位老先生老太太的兩千名子孫。
那麼,從七十幾年來、幾十萬頁的訪談資料與醫療記錄中,究竟帶給我們什麼樣的研究結果與啓發?

「有個很清楚的訊息:良好的關係讓我們維持快樂與健康。就這樣。」威丁格教授微笑表示,關於「關係」有三個重點:

I. 孤單有害 社交活躍有益健康

與家人、朋友、社群保持較多聯繫的人,心靈比較快樂、身體也較健康;研究也顯示,社交活躍的人比較長壽。孤單的感覺對身心都是毒害,如果人們非自願地感到孤獨,會容易感到不快樂,在中年時健康狀況會提早衰退,大腦功能較早開始退化,因此容易早逝。

II. 友不在數量多寡 而在關係深淺

我們在人群、聚會或婚姻中也會感到孤獨,所以真正重要的是:關係的「質」。高衝突的關係對我們的健康有負面影響,例如:身處爭執不斷的婚姻,可能在健康上,還不如離婚的好。而反之,在良好與溫暖的關係中,對健康就有保護作用。
根據研究,人們進入五十歲時,影響他們日後的健康狀況的,不是膽固醇高低,而是他們對目前所在關係的滿意度。意思是說,在五十歲對關係擁有最高滿意度的人,在八十歲時是最健康的一群。顯然,親密的關係能減緩老化帶來的生理與心理衝擊。

III. 良好關係不只保護身體 也保護腦力

研究顯示,是否能在年老時感受到仰賴與信任另一方,對於腦部健康有重大影響。八十幾歲的老先生若能感覺到有可以依靠的對象,他的記憶力就能更長時間地保持清晰;反推之,若老先生沒有這種感受,他就可能提早面臨記憶力衰退。

從這個75年研究結果所得的智慧,在在說明了關係的重要—最快樂健康的人是與家人朋友擁有親密關係的那些人。只不過,對絕大多數的人而言,維持關係並不是件簡單的事,如著名心理學家阿德勒也曾說過,人的煩惱都是從人際關係而來。
「美好人生建立在良好關係上。」威丁格教授在結語強調著,雖然不容易,但是卻值得我們投入精神時間。不論你現在是二十五、四十或六十歲,問問自己,除了追求工作成就,你是否也想開始打造你的美好人生呢?

原撰稿:廖庭瑋
網址:http://tedxtaipei.com/articles/what_makes_a_good_life_lessons_from_the_longest_study_on_happiness/

疑問:
美國是一個重視個人隱私與個人主義的國家,社區內甚至家族裡的連接較少,因此不難想像會有以上的結果。當回看華人社會,其社會結構內本來就存在家族、社區的小團體連接。因此,華人社會的良好關係應該是既有條件,那促使華人社會感到幸福的因素還有哪些?

建議跟進(keywords):
華人社會幸福感、陸洛