Mike Barlow
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    ###### tags: `TiDB` `TiUP` `Google` `GCP` `Tutorial` # Getting TiDB Up and Running on Google Cloud Compute (GCP) Instance - Part 1 ## Overview The primary goal of this blog post series is to get a simple TiDB cluster up and running on Google GCP. This will allow you to try out TiDB and get familiar with the major components. This is a two part post. The first part is setting up GCP so that we can run TiDB. The second part is setting up and running TiDB on the GCP environment that we created in the first part. Here's a Reference Architecture of what we will have the end of the 2nd post. ![](https://i.imgur.com/vypLT5V.png =500x) Table of Contents [ToC] In this first part, we will be focused on implementing Prerequisites Operations (see image below). Notice the two Swim Lanes (Local, GCP Instance). Each operation is run on the system associated with its specific Swim Lane "Local" is refers to your person/company computer. For me, my local computer is a MacBook Pro that is my daily computer. "GCP Instance", is a virtual machine instance that we will create in Google GCP. ![](https://i.imgur.com/BcGl91x.png) In each section, I will reference the image above with an arrow identifying the section we are working on. ### Requirements * Basic understanding and access to Google GCP * Google GCP `gcloud` installed and configured on local computer # The Process ## Validate Google `gcloud` Configuration on Local Computer ![](https://i.imgur.com/mVhdofL.png =400x) Alright, let's start. On your local computer, you should have Google gcloud installed and configured. On our local computer let's take a look at `gcloud` configuration. ```bash= gcloud config list ``` ![](https://i.imgur.com/i1kCT4q.png) Notice that I'm using a User Account; not a Service Account. Usually a service account will end with `gserviceaccount.com`. In the following image, notice that I have `compute` configuration set for `region` and `zone` and you may also have this set. It shouldn't matter if these values are set or not. In this getting started guide, when we use gcloud commands we will specify where the resource will live. ![](https://i.imgur.com/JwHvBx7.png) ## Create GCP Instance ![](https://i.imgur.com/NsmFN2y.png =400x) Let's create a GCP instance where we will run TiDB. ```bash= gcloud compute instances create tidb-vm \ --image-family=ubuntu-1804-lts \ --image-project=ubuntu-os-cloud \ --machine-type=e2-medium \ --boot-disk-size=200GB \ --boot-disk-type=pd-standard \ --boot-disk-device-name=tidb-vm \ --zone=us-west1-a ``` This may take a few moments to complete ##### Sanity Check Let's validate the instance is up and running ```bash= gcloud compute instances list ``` ![](https://i.imgur.com/jPKQXMj.png) :::info If you get an error and not able to create an instance, you probably do not have valid permissions with the GCP account that gcloud is associated with. ::: ## SSH into New GCP Instance ![](https://i.imgur.com/zbp20RV.png =400x) Here we will use `gcloud` ssh feature to access our newly created GCP instance. ```bash= gcloud compute ssh --zone "us-west1-a" "tidb-vm" ``` ![](https://i.imgur.com/ktgoTuv.png) Notice that the server we SSH into has a prompt that references the `tidb-vm` instance. ## GCP Instance - Change Service Account to User Account ![](https://i.imgur.com/8jPbi10.png =400x) ### gcloud Account We should now be logged into the GCP instance tidb-vm Let's do something simple with `gcloud` that should validate our level of access, or the lack of access. Let's get a list of GCP instances . ``` gcloud compute instances lists ``` ![](https://i.imgur.com/opDGBXm.png) Notice that I received an error. This is because the account associated with gcloud is a Service Account that does not have permissions to get a list of instances. Even though you may not get an error, I recommend following the instructions below to change from a Services Account to your User Account. :::info A GCP Service Account is a special kind of account used by an application or a virtual machine (VM) instance, not a person. By default, GCP creates a Service Account and adds it to your project and is enabled on all instances. </br> Reference: * [GCP Docs - Account Types](https://cloud.google.com/sdk/docs/authorizing#types_of_accounts) * [GCP Docs - Service Accounts](https://cloud.google.com/compute/docs/access/service-accounts) ::: Let's see what account we are running as. Here I run two commands that show similar information. Both of these commands provide similar information ```bash= gcloud config list # or gcloud auth list ``` ![](https://i.imgur.com/x6Nl8Ta.png) Note that the account email address and the domain. If it ends in `compute@developer.gserviceaccount.com`, you are running as a service account. In this getting started guide we want to execute gcloud commands with our User Account. Let's change the account that gcloud is associated with. ### Login with GCP User Account Here we will change the account that gcloud is associated with from a Service Account our User Account. It's a multi-step process to change the `gcloud` account. ![](https://i.imgur.com/0Uz5fDo.png =500x) :::info Reference: [GCP Docs - Authorizing Cloud SDK tools](https://cloud.google.com/sdk/docs/authorizing) ::: Let's start the process by using `gcloud` `auth login` command. This will initiate the process ```bash= gcloud auth login ``` ![](https://i.imgur.com/B5756mW.png) You will see a long URL (see image above). Copy this url and paste it in a browser address bar. In the browser, select the Google Account that has the permissions needed. For me, this is the same account I used when creating the GCP instance. ![](https://i.imgur.com/OBCHwLD.png) Click the "Allow" button ![](https://i.imgur.com/o47TZjt.png) Click the copy button ![](https://i.imgur.com/8VDwXZC.png) Paste the verification code from the browser to the `gcloud` CLI. ![](https://i.imgur.com/Hrik772.png) Our User Account should now be associated with `gcloud`. ##### Sanity Check Let's confirm the account we are running as. ```bash= gcloud config list # Or gcloud auth list ``` ![](https://i.imgur.com/AulXNIM.png) Perfect, gcloud is now running under a User Account. Let's try again to get a list of machines. ``` gcloud compute instances lists ``` ![](https://i.imgur.com/bSmg6EE.png) This doesn't prove that we have all the access we need, but it's a good baseline. ## Create SSH Keys for TiUP ![](https://i.imgur.com/VBb0OJ0.png =400x) In Part 2 of this post, we will use TiUP to create TiDB clusters. TiUP uses SSH. We will need to configure SSH. Think of TiUP as a package manager that makes it easier to manage different cluster components in the TiDB ecosystem. We will discuss TiUP more in Part 2 of this post. Let's see what's in the .ssh directory ``` ls -al .ssh ``` ![](https://i.imgur.com/J36Grc6.png) There are no actual keys in this directory. We can use `gcloud` to create SSH key that TiUP will need. :::info Reference: [Google Docs - gcloud compute config-ssh](https://cloud.google.com/sdk/gcloud/reference/compute/config-ssh) ::: When running the following command, you will be prompted to enter a passphrase. For simplicity, do not enter a passphrase when prompted. Just hit <return> to provide an empty passphrase. ```bash= gcloud compute config-ssh ``` ![](https://i.imgur.com/6iVdUkQ.png) ##### Sanity Check Let's see what files were created. ```bash= ls -al .ssh/ ``` ![](https://i.imgur.com/DJYkHtz.png) Notice we now have 3 new files. The primary file we are interested in is the `google_compute_engine`, which is the private key that TiUP will use for SSH. ## Open TiDB Ports on GCP Network We will want to access TiDB resources (TiDB Dashboard, Grafana, Prometheus) from a browser on your local computer. To do this, we will need to open ports on the GCP network by creating a GCP Firewall Rule. ![](https://i.imgur.com/OjGu25t.png =400x) Below, we are going to create a firewall rule that will allow only our local computer to access TiDB resources. :::info Reference: [Google Docs - VPC firewall rules overview](https://cloud.google.com/vpc/docs/firewalls) ::: Let's get our local computer public IP Address :::info Here's a link that provides different ways of getting your local IP [How To Find My Public IP Address From Command Line On a Linux](https://www.cyberciti.biz/faq/how-to-find-my-public-ip-address-from-command-line-on-a-linux/) ::: :::warning :exclamation: We want our local computer IP address, **NOT** the GCP instance IP address. Therefore, run the following command on your local computer. For me, I'm running the following command on my MacBook. Notice in the image below, that the command prompt does not include `tidb-vm` ::: ```bash= host myip.opendns.com resolver1.opendns.com ``` ![](https://i.imgur.com/yUnTrfR.png) Notice my blurred-out IP address. We are going to use this IP Address below. Let's look at the current firewall rules ```bash= gcloud compute firewall-rules list ``` Notice, by default, that GCP already has some firewall rules. We will create a new firewall rule. ![](https://i.imgur.com/NCLl35a.png) <br> Here are the TiDB ports that we will make available to our local computer: * TiDB SQL Client: 4000 * Grafana: 3000 * Prometheus: 9090 * TiDB Dashboard: 2379 </br> :::info [PingCAP Docs - List of All TiDB Ports](https://docs.pingcap.com/tidb/stable/hardware-and-software-requirements#network-requirements) ::: Let's create a firewall rule with our local IP Address. In the code example below, for the parameter`--source-ranges`, replace <LOCAL IP> with your own local IP Address. Do keep the `/32`. This will limit it to your specific IP Address. ```bash= gcloud compute firewall-rules create access-from-home \ --allow tcp:4000,tcp:3000,tcp:9090,tcp:2379 \ --description="Allow traffic from my personal computer" \ --source-ranges="98.245.63.241/32" ``` :::info I added port 2379 to the above command. It's different than the image shows below. ::: ![](https://i.imgur.com/Z8jR4U4.png) In part 2, we will access TiDB from our local computer using these ports. ## MySQL Client ![](https://i.imgur.com/dUGDWai.png =400x) TiDB is fully compatible with the MySQL 5.7 protocol and the common features and syntax of MySQL 5.7. :::info REFERENCE: [PinCAP Docs - MySQL Compatibility](https://docs.pingcap.com/tidb/stable/mysql-compatibility) ::: In Part 2, after we installed TiDB, we will access TiDB with a MySQL Client. Here we will install MySQL Client using apt-get ```bash= sudo apt-get update sudo apt-get install mysql-client ``` ![](https://i.imgur.com/GYUuojW.png) ## Wrap Up You should now have a GCP instance that you can use to install and run a simple TiDB environment. Next is [Part 2](https://hackmd.io/DUIgo9WhTeyzPqpPlSj7uQ) where we install and run TiDB.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully