2018 Rails Application in Docker(certbot+nginx+docker+rails+facebook)

With the emergence of Cloud-native concept, apparently, going deploying your application in the cloud is critical and important. Accordingly my tiny business,  I don’t really need cloud SQL and Kubernetes engine in Cloud- I take GCP as an example. It cost me too much if you don’t need such powerful weapons. To be honest, if my business was big enough, I deploy my service with those off-the-shelf managed services for sure.

To exploit free tier in GCP, I choose small instance to maintain my data, including cloud storage(AWS S3). Only when I meet the spike traffic for my services (intense shopping period), I scale-up my instance in the schedule. It is easy to tackle my budget and performance. Here is my architect, and next I will depict my issues when I deploy the service.

Untitled Diagram

 

The problem on free certificate using Letsencrypt

In order to use a free certificate, I adopted Letsencrypt, and they support Certbot now. Using the module is quite simple, and it can automatically fill the Nginx configuration where it detects the corresponding directive.

It can support a cronjob that can make an update in a schedule. Due to 3 months expired time, you have to update the certificate in manual if you don’t use the mechanism like this. So don’t hesitate, go try Certbot.

Make your Docker versionable

Compiling Dockerfile and making your images is quite a normal thing in Docker world; however, in Rails, it would bring some burdens- Gemsets. Therefore, you should compose your Dockerfile carefully. Here is an example.

FROM ruby:2.3.1
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
# Set an environment variable where the Rails app is installed to inside of Docker image
ENV LC_ALL C.UTF-8
# Setup TZ
ENV TZ Asia/Taipei
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
ENV RAILS_ROOT /var/www/app
RUN mkdir -p $RAILS_ROOT
# Set working directory
WORKDIR $RAILS_ROOT
# Setting env up
ENV RAILS_ENV='production'
ENV RACK_ENV='production'
# Adding gems
# Adding project files
COPY ./app/{project}/Gemfile ./{project}/Gemfile
COPY ./app/{project}/Gemfile.lock ./{project}/Gemfile.lock
COPY ./app/{model}/Gemfile ./{model}/Gemfile
COPY ./app/{model}/Gemfile.lock ./{model}/Gemfile.lock
COPY ./app/{model}/lib/shoppe/version.rb ./{model}/lib/{model}/version.rb
COPY ./app/{model}/shoppe.gemspec ./{model}/{model}.gemspec
WORKDIR $RAILS_ROOT/easybuy
RUN bundle install --jobs 20 --retry 5 --without development test
WORKDIR $RAILS_ROOT
COPY ./app/{project}/ ./{project}/
COPY ./app/{model}/ ./{model}/
WORKDIR $RAILS_ROOT/{project}
COPY ./conf/email.yml ./config/email.yml
COPY ./conf/ecpay.yml ./config/ecpay.yml
COPY ./conf/facebook.yml ./config/facebook.yml
COPY ./conf/secrets.yml ./config/secrets.yml
COPY ./conf/redis.yml ./config/redis.yml
COPY ./conf/database.yml ./config/database.yml
RUN bundle exec rake assets:clean
RUN bundle exec rake tmp:clear
RUN bundle exec rake log:clear
RUN bundle exec rake assets:precompile
EXPOSE 3000
CMD ["bundle", "exec", "puma"]
view raw Dockerfile.app hosted with ❤ by GitHub

Line 19-24 shows that we add Gemfile and bundle them first. Why should we do that? Because Docker records the progress of building an image by each instructor line by line. Only when any one of instructor which comprises modified contexts, the instructor will invoke again. To avoid bundle installation during building an image or updating an image, we put the section prior to line 30 – COPY ./app/{project}/ ./{project}/.

In other words, Gemfile or Gemfile.lock are not changed, you won’t bundle install while you try to build image once again.

The problem on Assets problem

Since we don’t put either reverse proxy or application service in the same space (host and docker). It’s a little difficult to map to the static files. Of course, you can use some tricks, saying, mount the volumes to make static files work. Here I directly let rails support it, and make ETag and expired tags.

location ~ ^/(assets|images|javascripts|stylesheets|swfs|system)/ {
    try_files $uri @rails;
    access_log off;
    gzip_static on; # to serve pre-gzipped version
    expires max;
    add_header Cache-Control public;
    # Some browsers still send conditional-GET requests if there's a
    # Last-Modified header or an ETag header even if they haven't
    # reached the expiry date sent in the Expires header.
    add_header Last-Modified "";
    add_header ETag "";
    break;
}

I try to make Rails serve the static files. config/environments/production.rb, there’s a line where it describes like the following.

config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?

Apparently, you can setup it by fill RAILS_SERVE_STATIC_FILES on environment variables. You can run your docker with-e RAILS_SERVE_STATIC_FILES=true for example.

The Problem on Facebook-Omniauth-Facebook

First, you might encounter the timeout issue when you try to call Graph API. Here, you can extend your timeout to avoid 504 Bad Gateway.

location @rails {
    proxy_set_header  X-Real-IP  $remote_addr;
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://rails_app;
    proxy_connect_timeout       600;
    proxy_send_timeout          600;
    proxy_read_timeout          600;
    send_timeout                600;
  }

Secondly,  if you need Oauth or called Facebook Login, you might use Omnioauth-facebook in Rails, and you probably face an invalid_credential issue as well. You ought to turn on the logger file in the first place; then you can find an exact problem.

OmniAuth.config.logger = Rails.logger

Turning on the logger in OmniAuth would help you solve your real problem. For me, I encounter a domain name issue. However, I don’t change any domain name neither. Weird right? I check my app settings on Facebook as well. The only thing I change is the deployment way. I infer to reverse proxy issue. How I solve the issue is specific callback_url.

Recently, nobody said that you should specify a customized callback_url after 2016 when you try to google it. Also, I check the Omniauth-facebook Github repo and check out the parameter with regards to callback_url ​Specify a custom callback URL used during the server-side flow. Note this must be allowed by your app configuration on Facebook.

Here is what I modify

Rails.application.config.middleware.use OmniAuth::Builder do
    provider :facebook, ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_APP_SECRET'],
        provider_ignores_state: true,
        cope: %w[ email public_profile].join(","),
        callback_url: "https://{domain-name}/auth/facebook/callback",
        strategy_class: OmniAuth::Strategies::Facebook,
        client_options: {
            site: 'https://graph.facebook.com/v3.2',
            authorize_url: "https://www.facebook.com/v3.2/dialog/oauth"
        }
end

I specify the callback_url with my callback path. Magically, it works though.

Summary

After all, you ought to adopt managed services if you really own huge businesses, and they really solve lots of problems. Not only did they save your time, but give your high availability in no pain. You just need to divide your resources with fixed and elastic ones, saying reserved/committed instances and spot/pre-emptive instances. You can control your budget well. Combining auto-scaling solutions also brings you a great low budget according to metering.

But, if you only own small business, and want to manipulate them in free-tier or merely exceed a little bit. You can compose it like me. For sure, you can make a progress of your architecture toward more cloud. That is to say, changing your RBD into cloud SQL is a good alternative, and try to deploy your containers with clusters by Kubernets engine supplied by GKE/AWS EKS, and only cost you higher a little bit. Most importantly, you have to do that one day once your business grows up gradually.

Array Manipulation in Bash

It’s important to manipulate array in various languages, and I want to take a note with regards with Bash.

#!/bin/bash
#assign variables into array
array=(Redhat Novell MicroSoft Sun IBM HP Dell)
#iterate all elements, and print them out
for i in 0 1 2 3 4 5 6
do
echo "array[$i]=${array[$i]}"
done
unset -v IFS # restore IFS to default
# delimiter as :, and adopt $* print out all elements.
IFS=:
echo "${array[*]}"
# delimiter as \n
IFS=$'\n'
echo "${array[*]}"
#print out all elements without joint as $* do
echo "${array[@]}"
# print out length of array
echo "${#array[@]}"
#result:
#array[0]=Redhat
#array[1]=Novell
#array[2]=MicroSoft
#array[3]=Sun
#array[4]=IBM
#array[5]=HP
#array[6]=Dell
#Redhat:Novell:MicroSoft:Sun:IBM:HP:Dell
#Redhat
#Novell
#MicroSoft
#Sun
#IBM
#HP
#Dell
#Redhat Novell MicroSoft Sun IBM HP Dell
#7

Virtual IP with OpenStack Neutron

Preamble

As part of Jexia’s infrastructure team we are often required to deploy services in a highly-available fashion. Since we use OpenStack as our cloud provider, we had to pull this off using OpenStack’s networking software — Neutron.

Neutron has the ability to assign a “shared-IP” (or Virtual-IP) to any number of virtual machines. In Openstack, a virtual machine has a default Neutron port providing its default IP address.

We can “pair” the shared-IP with this port. This allows the virtual machine to configure both its default IP and shared IP on a single interface.

In this blog post we would like to share how we leverage OpenStack’s Neutron shared-IP to provide a highly available service. We decided a proof-of-concept tutorial is a good way to do it.

Ergo, to get the most out of this blog post, you need to have:
– basic experience working with OpenStack (Neutron)
– understanding of the requirements for deploying a highly-available service

Setup

The basic setup

Okay, let’s explain this diagram:

We have an “external” network (10.10.0.0/24) and an internal network (192.168.168.0/24).

Note: this is a “fake” external network for the purpose of this blog. In reality, any available external network addresses can be used.

Within the internal network we have two web-servers: vm01 and vm02.

Both are running httpd and keepalived services (more about keepalived later). The IP address 192.168.168.8 is allocated to vm01 and 192.168.168.11allocated to vm02.

In addition, there is a virtual-IP (VIP, also referred to as a shared-IP) with the address 192.168.168.3. This IP address has an association to an IP address on the external network: 10.10.0.237 which is a “floating IP”.

The floating IP is the address a client on the internet would use to reach any web page served on the vm01 and vm02 web-servers.

To sum this up:

  • External network: 10.10.0.0/24
  • Internal network: 192.168.168.0/24
  • Virtual IP (shared IP): 192.168.168.3
  • Floating IP (external): 10.10.0.237
  • vm01: 192.168.168.8
  • vm02: 192.168.168.11

Here’s a Simplified Scenario…

Let’s imaging a client accesses the address http://10.10.0.237/index.html. The address would translate to its associated internal IP 192.168.168.3 (i.e.VIP).

It is important to note that the VIP can only be configured on one of the web-servers at any given time. This server will be the one to respond to a client’s request.

Suppose that vm01 dies out for some reason. The VIP will then be made available on vm02, hence the client can still use the same external IP. This magic is being handled by keepalived.

Steps Breakdown

Listed below are the steps we are going to take to configure our highly available setup in OpenStack:

  1. Networking Setup
    Create an external network 10.10.0.0/24, an internal network 192.168.168.0/24 and finally a virtual router with an interface to each one of these networks.
  2. Security Rule
    Add security group rule to allow protocol 112 (VRRP) for keepalived to work.
  3. Deploy VMs
    Deploy two CentOS 7 instances (virtual machines) onto the internal network 192.168.168.0/24 (each VM will automatically get a unique address from this subnet) — vm01: 192.168.168.8, vm02: 192.168.168.11
  4. Create VIP
    Create a Neutron port on the internal network. In our case it gets the IP address 192.168.168.3 — this is the Virtual IP which will be shared by both VMs.
  5. Create Floating IP
    Allocate a floating IP on the external network. In our case it is 10.10.0.237). This will be the IP to which external users/public will connect to.
  6. Associate Floating IP to VIP
    Associate the floating IP we’ve created earlier (10.10.0.237) to the VIP address we’ve created (192.168.168.3).
  7. Update VM Ports
    Update the VM’s network ports using the “allowed-address-pairs” and provide the VIP (192.168.168.3).
  8. Install Services
    Install keepalived and httpd on both VMs (for now we can access them from the controller node using ip netns exec ssh centos@${vm_ipaddress} -i sshkey)
  9. Configure Services
    Configure keepalived on both VMs (vm01 as master, vm02 as backup). Edit the default index.html of httpd to output the hostname or some string to help identify which VM is replying.
  10. Test
    Shutdown the master VM (vm01) and keep running curl to the floating IP (10.10.0.237). We should see the backup VM replying after a few moments.

Commands

Note that we are using TripleO’s Undercloud/Overcloud setup. We are executing the commands from the Undercloud to control the Overcloud.

In addition, it is worth mentioning that we provide these commands as a reference. They should not be entered exactly as they appear as your environment might be configured differently.


TL;DR

There’re many steps in the original article. However, I only focus on step 4 and step 7.

The step4 is where VIP is created w/ a neutron port, and the port isn’t attached any virtual server. Afterward, step7 would associate two IPs with VIP. Note that, only IP is needed here for step7.


Okay, let’s have a quick summary of what we’ve done to this point:

We’ve…

  • created external and internal networks
  • deployed two virtual machines
  • created a virtual IP and a floating IP
  • associated the two IPs so that traffic to the floating IP reaches the virtual IP

We will proceed with the list of steps as we allow the virtual machines to make use of the virtual IP. Then, we will configure them to act as web servers. Finally, we will configure keepalived and then test our setup.

Step 4

In this step we create the virtual IP. We need to know both the subnet and network IDs on which we create the VIP.

In the first command we list the existing networks. We make note of the subnet ID and network ID.

In the second command we specify the subnet ID and network ID on which to create the new port.

[stack@undercloud ~]$ neutron net-list
+--------------------------------------+----------------------------------------------------+-------------------------------------------------------+
| id | name | subnets |
+--------------------------------------+----------------------------------------------------+-------------------------------------------------------+
| 2c5ba534-6684-4123-83f4-107068d24455 | internal01 | dfbe79dd-e9a9-4082-9555-2b62ed7f5ca6 192.168.168.0/24 |
| 4bef3e65-1199-4cc0-8feb-ca29b808727f | ext_net | 569f30e8-0f63-4900-94eb-72f4e575ad65 10.10.0.0/24 |
| b488e3ea-f1d0-4215-9ada-f6016e3b8ad8 | HA network tenant ddc091c1cff24105a305afed0e4c3f2e | a6309ff0-8378-4b54-b6e5-8a6a2a1e7cca 169.254.192.0/18 |
+--------------------------------------+----------------------------------------------------+-------------------------------------------------------+
[stack@undercloud ~]$ neutron port-create \
--fixed-ip subnet_id=dfbe79dd-e9a9-4082-9555-2b62ed7f5ca6 \
--no-security-groups \
--name "Virtual IP" 2c5ba534-6684-4123-83f4-107068d24455
Created a new port:
+-----------------------+--------------------------------------------------------------------------------------+
| Field | Value |
+-----------------------+--------------------------------------------------------------------------------------+
| admin_state_up | True |
| allowed_address_pairs | |
| binding:host_id | |
| binding:profile | {} |
| binding:vif_details | {} |
| binding:vif_type | unbound |
| binding:vnic_type | normal |
| created_at | 2017-03-03T15:09:46Z |
| description | |
| device_id | |
| device_owner | |
| extra_dhcp_opts | |
| fixed_ips | {"subnet_id": "dfbe79dd-e9a9-4082-9555-2b62ed7f5ca6", "ip_address": "192.168.168.3"} |
| id | d9fad1d7-14bb-49cb-8765-c997dd8c7f60 |
| mac_address | fa:16:3e:13:52:8d |
| name | Virtual IP |
| network_id | 2c5ba534-6684-4123-83f4-107068d24455 |
| port_security_enabled | True |
| project_id | ddc091c1cff24105a305afed0e4c3f2e |
| qos_policy_id | |
| revision_number | 4 |
| security_groups | |
| status | DOWN |
| tenant_id | ddc091c1cff24105a305afed0e4c3f2e |
| updated_at | 2017-03-03T15:09:46Z |
+-----------------------+--------------------------------------------------------------------------------------+
view raw gistfile1.txt hosted with ❤ by GitHub

Step 7

First we must run nova list to see which IP addresses have been allocated to the virtual machines.

Then we can run neutron port-list to correlate those IPs to their respective port ID.

[stack@undercloud ~]$ nova list
+--------------------------------------+------+--------+------------+-------------+---------------------------+
| ID | Name | Status | Task State | Power State | Networks |
+--------------------------------------+------+--------+------------+-------------+---------------------------+
| 637f0077-72bb-40e7-b184-0f5a6a048fa7 | vm01 | ACTIVE | - | Running | internal01=192.168.168.8 |
| 26ceaa45-5668-4b44-92da-3ca29b66b389 | vm02 | ACTIVE | - | Running | internal01=192.168.168.11 |
+--------------------------------------+------+--------+------------+-------------+---------------------------+
(overcloud)
[stack@undercloud ~]$ neutron port-list
+--------------------------------------+-------------------------------------------------+-------------------+---------------------------------------------------------------------------------------+
| id | name | mac_address | fixed_ips |
+--------------------------------------+-------------------------------------------------+-------------------+---------------------------------------------------------------------------------------+
| 10cd10ec-87e7-46d9-a3dd-3e2060ead570 | HA port tenant ddc091c1cff24105a305afed0e4c3f2e | fa:16:3e:e8:44:4a | {"subnet_id": "a6309ff0-8378-4b54-b6e5-8a6a2a1e7cca", "ip_address": "169.254.192.9"} |
| 369c0fa4-1cee-4276-a70a-9005f3cc1f05 | | fa:16:3e:26:b9:7d | {"subnet_id": "569f30e8-0f63-4900-94eb-72f4e575ad65", "ip_address": "10.10.0.235"} |
| 62864260-d36f-432d-bde6-eddd395d7bd4 | | fa:16:3e:5f:a1:ff | {"subnet_id": "569f30e8-0f63-4900-94eb-72f4e575ad65", "ip_address": "10.10.0.237"} |
| 6ace3e52-660b-4d05-b07e-fb77dae33d4e | | fa:16:3e:25:7e:03 | {"subnet_id": "dfbe79dd-e9a9-4082-9555-2b62ed7f5ca6", "ip_address": "192.168.168.2"} |
| 7151f77a-b590-422a-bc4e-a630a7b578d4 | | fa:16:3e:2b:69:7e | {"subnet_id": "dfbe79dd-e9a9-4082-9555-2b62ed7f5ca6", "ip_address": "192.168.168.8"} |
| 9a5e3e6c-b446-4721-84dc-ae9f9de982c4 | | fa:16:3e:bd:41:3e | {"subnet_id": "dfbe79dd-e9a9-4082-9555-2b62ed7f5ca6", "ip_address": "192.168.168.11"} |
| b75e7a04-51ef-4d03-a062-8b64afe9d58e | | fa:16:3e:76:a7:18 | {"subnet_id": "dfbe79dd-e9a9-4082-9555-2b62ed7f5ca6", "ip_address": "192.168.168.1"} |
| d5519a58-f652-4d55-bef2-df3c1e715a03 | HA port tenant ddc091c1cff24105a305afed0e4c3f2e | fa:16:3e:7f:a2:66 | {"subnet_id": "a6309ff0-8378-4b54-b6e5-8a6a2a1e7cca", "ip_address": "169.254.192.5"} |
| d9fad1d7-14bb-49cb-8765-c997dd8c7f60 | Virtual IP | fa:16:3e:13:52:8d | {"subnet_id": "dfbe79dd-e9a9-4082-9555-2b62ed7f5ca6", "ip_address": "192.168.168.3"} |
| ec79bd5a-7db6-41e6-8fdb-679b5fe0dfc5 | HA port tenant ddc091c1cff24105a305afed0e4c3f2e | fa:16:3e:bc:07:2f | {"subnet_id": "a6309ff0-8378-4b54-b6e5-8a6a2a1e7cca", "ip_address": "169.254.192.10"} |
+--------------------------------------+-------------------------------------------------+-------------------+---------------------------------------------------------------------------------------+
view raw gistfile1.txt hosted with ❤ by GitHub

We see that the VMs have the IPs 192.168.168.8 and 192.168.168.11 which correspond to the port IDs of 7151f77a-b590–422a-bc4e-a630a7b578d4 and 9a5e3e6c-b446–4721–84dc-ae9f9de982c4 respectively.

Using these port IDs and VIP address we can update the ports to allow “address-pairing” with the VIP address 192.168.168.3:

[stack@undercloud ~]$ neutron port-update 7151f77a-b590-422a-bc4e-a630a7b578d4 \
--allowed-address-pairs \
type=dict \
list=true \
ip_address=192.168.168.3
Updated port: 7151f77a-b590-422a-bc4e-a630a7b578d4
[stack@undercloud ~]$ neutron port-update 9a5e3e6c-b446-4721-84dc-ae9f9de982c4 \
--allowed-address-pairs \
type=dict \
list=true \
ip_address=192.168.168.3
Updated port: 9a5e3e6c-b446-4721-84dc-ae9f9de982c4
view raw gistfile1.txt hosted with ❤ by GitHub

Now, if we view one of the ports we see that the Allowed Address Pairs is update with the VIP:

[stack@undercloud ~]$ neutron port-show 7151f77a-b590-422a-bc4e-a630a7b578d4
+-----------------------+--------------------------------------------------------------------------------------+
| Field | Value |
+-----------------------+--------------------------------------------------------------------------------------+
| admin_state_up | True |
| allowed_address_pairs | {"ip_address": "192.168.168.3", "mac_address": "fa:16:3e:2b:69:7e"} |
| binding:host_id | overcloud-novacompute-0.localdomain |
| binding:profile | {} |
| binding:vif_details | {"port_filter": true, "ovs_hybrid_plug": true} |
| binding:vif_type | ovs |
| binding:vnic_type | normal |
| created_at | 2017-03-03T15:07:46Z |
| description | |
| device_id | 637f0077-72bb-40e7-b184-0f5a6a048fa7 |
| device_owner | compute:None |
| extra_dhcp_opts | |
| fixed_ips | {"subnet_id": "dfbe79dd-e9a9-4082-9555-2b62ed7f5ca6", "ip_address": "192.168.168.8"} |
| id | 7151f77a-b590-422a-bc4e-a630a7b578d4 |
| mac_address | fa:16:3e:2b:69:7e |
| name | |
| network_id | 2c5ba534-6684-4123-83f4-107068d24455 |
| port_security_enabled | True |
| project_id | ddc091c1cff24105a305afed0e4c3f2e |
| qos_policy_id | |
| revision_number | 13 |
| security_groups | 498bc9dc-21f7-44ab-bc28-14aee32e3a67 |
| status | ACTIVE |
| tenant_id | ddc091c1cff24105a305afed0e4c3f2e |
| updated_at | 2017-03-03T15:18:03Z |
+-----------------------+--------------------------------------------------------------------------------------+
view raw gistfile1.txt hosted with ❤ by GitHub

TL;DR

you can directly refer original article, Virtual IP with OpenStack Neutron. I only capture the key point here.


Conclusion

In this blog we introduced you to Neutron’s address-pairs (shared IP) and how to use them to allow for a highly available service.

In more complicated scenarios, you might want to use HAProxy load-balancer together with keepalived spawning across multiple VMs (e.g. 5 Kubernetes master nodes). The idea is the same, as the shared IP has to be able to be configured on any of the VMs in the cluster.

We outlined the manual steps you need to take to configure the VMs in a highly-available setup. These steps can certainly be automated.

At Jexia, we need our setup to allow for auto-scaling. This means we can automatically deploy VMs and configure them to either extend an existing cluster, or form a new one.

To do that, we need to fully automate the configuration in Neutron in several key areas. These include the settings for allowed-address-pairs for newly deployed VMs, the configuration of the load-balancers, keepalived and any service that is required on the cluster.

You can refer to a previous article posted at Jexia regarding auto-scaling and Serverless Computing: https://medium.com/p/a9a8162f4983

Sources

Virtual IP with OpenStack Neutron

Neutron Specs, Allowed Address Pairs: https://specs.openstack.org/openstack/neutron-specs/specs/api/allowed_address_pairs.html

RedHat, Configure Allowed Address Pairs: https://access.redhat.com/documentation/en-us/red_hat_openstack_platform/9/html/networking_guide/sec-allowed-address-pairs

Highly Available VIPs on Openstack: https://blog.codecentric.de/en/2016/11/highly-available-vips-openstack-vms-vrrp/

Solve USN-3586-1: DHCP vulnerabilities – ubuntu by disabling DHCP

Replace your interfaces configuration

  1. First, Checkout your network configuration, and replace DHCP with the static one
  2. > nano /etc/network/interfaces
    interfaces
  3. As shown above,  the interface, ens32, changes from ‘inet dhcp’ to ‘inet static’
  4. Append your gateway, network, netmask and dns. You can retrieve those information by ‘ip a’ and ‘route’

Restart your network

  1. >sudo /etc/init.d/networking restart

Remove dhcpclient

  1. remove out your ISC dhcpclient command
  2. >sudo apt-get remove isc-dhcp-client
  3. Done

Otherwise, you can directly upgrade your dhcp-client

  1. For sure, you can neglect above instructions, and just upgrade the dhcp-client.

Hopefully you would get the help to solve this vulnerability easily by this guide

AWS Solution Architect Associate 2018考試心得

因為某些因素,想趁著一些工作上的空檔把這個證照拿到手; AWS Certification 中的 Associate Level Solutions Architect

因為這個證照將在2018.08.12後改版,所以趕在5/12前取得這份成績,順便為自己加些分數,這篇大概是台灣2018年唯一分享心得文吧(高手都考完了renew了@@),雖然有其他的前輩rickhw提到變難了,但我自己是覺得差不多,就考試當下需要多想一下。

至於rickhw的blog寫得很棒,大家也可以參考。

 

 

  • 測試形式
    • 全英文(2018.05.05我安排考試時,舊制己經有繁中可選,但我還是選擇英文,畢竟閱讀的所有東西都以英文為主)
    • 考試使用滑鼠點選操作(有flag機制和可修改答案機制,完全不需紙筆,並且可以做完回頭檢查)
    • 測驗時間為 55 題 80 分鐘
    • 作答完後會有個小問卷,限時 10 分鐘,與分數無關
    • 考完畫面會告試您通過與否,並且在數分鐘內就知道分數
  • 推薦讀物
    • 認證相關文件 (Exam Guide, Sample Questions) 必看
    • AWS 官方文件:
      現在似乎有簡中版本上線,但還是建議閱讀英文版本;另外 html (線上), Kindle, pdf 間更新有時間差。
    • White Paper:
    • FAQ︰
      • 以前前輩可能沒貼,不過一定要看,特別是幾個老字號服務S3,EC2,VPC,IAM,Cloudfront, Rount53, RDS and EBS等
    • 線上網站
      • udemy – a cloud guru,個人滿推薦他的,講得很棒,而且有些exam tips很好用;不是說考試一定考,而是當很多服務的特性搞亂時,它很有幫助。
  • 心得建議
    • 一定要做考古題;這裡不是說會從考古題考(至少我的是沒有),但會抓到考試的感覺;例如,題目會提示您unstructured, persistence, high scalability and durability時,您大概就會想S3,對答題會有一定的準度。我考前1周從50%->80% 但實際上戰場考出9x%,覺得滿有用的。至於 考古題,答案要自己去查,去確認,個人覺得不一定對,如果沒把握,建議把相關documents和faq再查,再看過。
    • 題目方向可參照 Exam Guide
    • 針對各種服務或子功能 (例如 VPC 的 subnet),要知道作用層級,是 [Managed, Hosted] Service, 作用於 [Instance, Availability Zone, Region, Globally,Facilities] 等等

以上文章範例,參考aws community hero : Clifflu和aws hao

至於花多久準備,個人覺得每個人的條件不同(我指background),沒有參考價值;像大陸有人用3天,就考到了。我自己本身具備雲服務和Openstack設計開發的經驗,所以總時數不算多的情況下,也順利考到。至於要準備多完整;您做考古題能到80%時,可以跟別人講解大部分的solutions時,就差不多了。

 

 

 

How To Install an SSL Certificate from a Commercial Certificate Authorities

Introduction

This tutorial will show you how to acquire and install an SSL certificate from a trusted, commercial Certificate Authority (CA). SSL certificates allow web servers to encrypt their traffic, and also offer a mechanism to validate server identities to their visitors. The main benefit of using a purchased SSL certificate from a trusted CA, over self-signed certificates, is that your site’s visitors will not be presented with a scary warning about not being able to verify your site’s identity.

This tutorial covers how to acquire an SSL certificate from the following trusted certificate authorities:

After you have acquired your SSL certificate, we will show you how to install it on Nginx and Apache HTTP web servers. There’re some installation guides for various web servers, such as IIS, Apache, Tomcat and so forth.(https://gca.nat.gov.tw/web2/form02.html)

Prerequisites

There are several prerequisites that you should ensure before attempting to obtain an SSL certificate from a commercial CA. This section will cover what you will need in order to be issued an SSL certificate from most CAs.

Money

SSL certificates that are issued from commercial CAs have to be purchased. The best free alternative are certificates issued from Let’s Encrypt. Let’s Encrypt is a new certificate authority that issues free SSL/TLS certificates that are trusted in most web browsers.

Registered Domain Name

Before acquiring an SSL certificate, you must own or control the registered domain name that you wish to use the certificate with. If you do not already have a registered domain name, you may register one with one of the many domain name registrars out there (e.g. Namecheap, GoDaddy, etc.).

Domain Validation Rights

For the basic domain validation process, you must have access to one of the email addresses on your domain’s WHOIS record or to an “admin type" email address at the domain itself. Certificate authorities that issue SSL certificates will typically validate domain control by sending a validation email to one of the addresses on the domain’s WHOIS record, or to a generic admin email address at the domain itself. Some CAs provide alternative domain validation methods, such as DNS- or HTTP-based validation, which are outside the scope of this guide.

If you wish to be issued an Organization Validation (OV) or Extended Validation (EV) SSL certificate, you will also be required to provide the CA with paperwork to establish the legal identity of the website’s owner, among other things.

Web Server

In addition to the previously mentioned points, you will need a web server to install the SSL certificate on. This is the server that is reachable at the domain name for which the SSL certificate will be issued for. Typically, this will be an Apache HTTP, Nginx, HAProxy, or Varnish server. If you need help setting up a web server that is accessible via your registered domain name, follow these steps:

  1. Set up a web server of your choice. For example, a LEMP (Nginx) or LAMP (Apache) server–be sure to configure the web server software to use the name of your registered domain
  2. Configure your domain to use the appropriate nameservers. If your web server is hosted on DigitalOcean, this guide can help you get set up: How To Point to DigitalOcean’s Nameservers from Common Domain Registrars
  3. Add DNS records for your web server to your nameservers. If you are using DigitalOcean’s nameservers, follow this guide to learn how to add the appropriate records: How To Set Up a Host Name with DigitalOcean

Choose Your Certificate Authority

If you are not sure of which Certificate Authority you are going to use, there are a few important factors to consider. At an overview level, the most important thing is that the CA you choose provides the features you want at a price that you are comfortable with. This section will focus more on the features that most SSL certificate buyers should be aware of, rather than prices.

Root Certificate Program Memberships

The most crucial point is that the CA that you choose is a member of the root certificate programs of the most commonly used operating systems and web browsers, i.e. it is a “trusted" CA, and its root certificate is trusted by common browsers and other software. If your website’s SSL certificate is signed by a trusted" CA, its identity is considered to be valid by software that trusts the CA–this is in contrast to self-signed SSL certificates, which also provide encryption capabilities but are accompanied by identity validation warnings that are off-putting to most website visitors.

Most commercial CAs that you will encounter will be members of the common root CA programs, and will say they are compatible with 99% of browsers, but it does not hurt to check before making your certificate purchase. For example, Apple provides its list of trusted SSL root certificates for iOS8 here.

Certificate Types

Ensure that you choose a CA that offers the certificate type that you require. Many CAs offer variations of these certificate types under a variety of, often confusing, names and pricing structures. Here is a short description of each type:

  • Single Domain: Used for a single domain, e.g. example.com. Note that additional subdomains, such as www.example.com, are not included
  • Wildcard: Used for a domain and any of its subdomains. For example, a wildcard certificate for *.example.com can also be used for www.example.com and store.example.com
  • Multiple Domain: Known as a SAN or UC certificate, these can be used with multiple domains and subdomains that are added to the Subject Alternative Name field. For example, a single multi-domain certificate could be used with example.com, www.example.com, and example.net

In addition to the aforementioned certificate types, there are different levels of validations that CAs offer. We will cover them here:

  • Domain Validation (DV): DV certificates are issued after the CA validates that the requestor owns or controls the domain in question
  • Organization Validation (OV): OV certificates can be issued only after the issuing CA validates the legal identity of the requestor
  • Extended Validation (EV): EV certificates can be issued only after the issuing CA validates the legal identity, among other things, of the requestor, according to a strict set of guidelines. The purpose of this type of certificate is to provide additional assurance of the legitimacy of your organization’s identity to your site’s visitors. EV certificates can be single or multiple domain, but not wildcard

This guide will show you how to obtain a single domain or wildcard SSL certificate from GoDaddy and RapidSSL, but obtaining the other types of certificates is very similar.

Additional Features

Many CAs offer a large variety of “bonus" features to differentiate themselves from the rest of the SSL certificate-issuing vendors. Some of these features can end up saving you money, so it is important that you weigh your needs against the offerings carefully before making a purchase. Example of features to look out for include free certificate reissues or a single domain-priced certificate that works for www. and the domain basename, e.g. www.example.com with a SAN of example.com

Generate a CSR and Private Key

After you have all of your prerequisites sorted out, and you know the type of certificate you want to get, it’s time to generate a certificate signing request (CSR) and private key.

If you are planning on using Apache HTTP or Nginx as your web server, use openssl to generate your private key and CSR on your web server. In this tutorial, we will just keep all of the relevant files in our home directory but feel free to store them in any secure location on your server:

cd ~

To generate a private key, called example.com.key, and a CSR, called example.com.csr, run this command (replace the example.com with the name of your domain):

openssl req -newkey rsa:2048 -nodes -keyout example.com.key -out example.com.csr

At this point, you will be prompted for several lines of information that will be included in your certificate request. The most important part is the Common Name field which should match the name that you want to use your certificate with–for example, example.com, www.example.com, or (for a wildcard certificate request) *.example.com. If you are planning on getting an OV or EV certificate, ensure that all of the other fields accurately reflect your organization or business details.

For example:

Country Name (2 letter code) [AU]:US
State or Province Name (full name) [Some-State]:New York
Locality Name (eg, city) []:New York
Organization Name (eg, company) [Internet Widgits Pty Ltd]:My Company
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:example.com
Email Address []:sammy@example.com

This will generate a .key and .csr file. The .key file is your private key, and should be kept secure. The .csr file is what you will send to the CA to request your SSL certificate.

You will need to copy and paste your CSR when submitting your certificate request to your CA. To print the contents of your CSR, use this command (replace the filename with your own):

cat example.com.csr

Now we are ready to buy a certificate from a CA. We will show two examples, GoDaddy and RapidSSL via Namecheap, but feel free to get a certificate from any other vendor.

Example CA 1: RapidSSL via Namecheap

Namecheap provides a way to buy SSL certificates from a variety of CAs. We will walk through the process of acquiring a single domain certificate from RapidSSL, but you can deviate if you want a different type of certificate.

Note: If you request a single domain certificate from RapidSSL for the www subdomain of your domain (e.g. www.example.com), they will issue the certificate with a SAN of your base domain. For example, if your certificate request is for www.example.com, the resulting certificate will work for both www.example.com and example.com.

Select and Purchase Certificate

Go to Namecheap’s SSL certificate page: https://www.namecheap.com/security/ssl-certificates.aspx.

Here you can start selecting your validation level, certificate type (“Domains Secured"), or CA (“Brand").

For our example, we will click on the Compare Products button in the “Domain Validation" box. Then we will find “RapidSSL", and click the Add to Cart button.

At this point, you must register or log in to Namecheap. Then finish the payment process.

Request Certificate

After paying for the certificate of your choice, go to the Manage SSL Certificates link, under the “Hi Username" section.

Namecheap: SSL

Here, you will see a list of all of the SSL certificates that you have purchased through Namecheap. Click on the Activate Now link for the certificate that you want to use.

Namecheap: SSL Management

Now select the software of your web server. This will determine the format of the certificate that Namecheap will deliver to you. Commonly selected options are “Apache + MOD SSL", “nginx", or “Tomcat".

Paste your CSR into the box then click the Next button.

You should now be at the “Select Approver" step in the process, which will send a validation request email to an address in your domain’s WHOIS record or to an administrator type address of the domain that you are getting a certificate for. Select the address that you want to send the validation email to.

Provide the “Administrative Contact Information". Click the Submit order button.

Validate Domain

At this point, an email will be sent to the “approver" address. Open the email and approve the certificate request.

Download Certificates

After approving the certificate, the certificate will be emailed to the Technical Contact. The certificate issued for your domain and the CA’s intermediate certificate will be at the bottom of the email.

Copy and save them to your server in the same location that you generated your private key and CSR. Name the certificate with the domain name and a .crt extension, e.g. example.com.crt, and name the intermediate certificate intermediate.crt.

The certificate is now ready to be installed on your web server.

Example CA 2: GoDaddy

GoDaddy is a popular CA, and has all of the basic certificate types. We will walk through the process of acquiring a single domain certificate, but you can deviate if you want a different type of certificate.

Select and Purchase Certificate

Go to GoDaddy’s SSL certificate page: https://www.godaddy.com/ssl/ssl-certificates.aspx.

Scroll down and click on the Get Started button.

Go Daddy: Get started

Select the type of SSL certificate that you want from the drop down menu: single domain, multidomain (UCC), or wildcard.

GoDaddy: Certificate Type

Then select your plan type: domain, organization, or extended validation.

Then select the term (duration of validity).

Then click the Add to Cart button.

Review your current order, then click the Proceed to Checkout button.

Complete the registration and payment process.

Request Certificate

After you complete your order, click the SSL Certificates* button (or click on My Account > Manage SSL Certificates in the top-right corner).

Find the SSL certificate that you just purchased and click the Set Up button. If you have not used GoDaddy for SSL certificates before, you will be prompted to set up the “SSL Certificates" product, and associate your recent certificate order with the product (Click the green Set Up button and wait a few minutes before refreshing your browser).

After the “SSL Certificates" Product is added to your GoDaddy account, you should see your “New Certificate" and a “Launch" button. Click on the Launch button next to your new certificate.

Provide your CSR by pasting it into the box. The SHA-2 algorithm will be used by default.

Tick the I agree checkbox, and click the Request Certificate button.

Validate Domain

Now you will have to verify that you have control of the domain, and provide GoDaddy with a few documents. GoDaddy will send a domain ownership verification email to the address that is on your domain’s WHOIS record. Follow the directions in the emails that you are sent to you, and authorize the issuance of the certificate.

Download Certificate

After verifying to GoDaddy that you control the domain, check your email (the one that you registered with GoDaddy with) for a message that says that your SSL certificate has been issued. Open it, and follow the download certificate link (or click the Launch button next to your SSL certificate in the GoDaddy control panel).

Now click the Download button.

Select the server software that you are using from the Server type dropdown menu–if you are using Apache HTTP or Nginx, select “Apache"–then click the Download Zip File button.

Extract the ZIP archive. It should contain two .crt files; your SSL certificate (which should have a random name) and the GoDaddy intermediate certificate bundle (gd_bundle-g2-1.crt). Copy both two your web server. Rename the certificate to the domain name with a .crt extension, e.g. example.com.crt, and rename the intermediate certificate bundle as intermediate.crt.

The certificate is now ready to be installed on your web server.

Install Certificate On Web Server

After acquiring your certificate from the CA of your choice, you must install it on your web server. This involves adding a few SSL-related lines to your web server software configuration.

We will cover basic Nginx and Apache HTTP configurations on Ubuntu 14.04 in this section.

We will assume the following things:

  • The private key, SSL certificate, and, if applicable, the CA’s intermediate certificates are located in a home directory at /home/sammy
  • The private key is called example.com.key
  • The SSL certificate is called example.com.crt
  • The CA intermediate certificate(s) are in a file called intermediate.crt
  • If you have a firewall enabled, be sure that it allows port 443 (HTTPS)

Note: In a real environment, these files should be stored somewhere that only the user that runs the web server master process (usually root) can access. The private key should be kept secure.

Nginx

If you want to use your certificate with Nginx on Ubuntu 14.04, follow this section.

With Nginx, if your CA included an intermediate certificate, you must create a single “chained" certificate file that contains your certificate and the CA’s intermediate certificates.

Change to the directory that contains your private key, certificate, and the CA intermediate certificates (in the intermediate.crt file). We will assume that they are in your home directory for the example:

cd ~

Assuming your certificate file is called example.com.crt, use this command to create a combined file called example.com.chained.crt (replace the highlighted part with your own domain):

cat example.com.crt intermediate.crt > example.com.chained.crt

Now go to your Nginx server block configuration directory. Assuming that is located at /etc/nginx/sites-enabled, use this command to change to it:

cd /etc/nginx/sites-enabled

Assuming want to add SSL to your default server block file, open the file for editing:

sudo vi default

Find and modify the listen directive, and modify it so it looks like this:

    listen 443 ssl;

Then find the server_name directive, and make sure that its value matches the common name of your certificate. Also, add the ssl_certificate and ssl_certificate_key directives to specify the paths of your certificate and private key files (replace the highlighted part with the actual path of your files):

    server_name example.com;
    ssl_certificate /home/sammy/example.com.chained.crt;
    ssl_certificate_key /home/sammy/example.com.key;

To allow only the most secure SSL protocols and ciphers, add the following lines to the file:

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';

If you want HTTP traffic to redirect to HTTPS, you can add this additional server block at the top of the file (replace the highlighted parts with your own information):

server {
    listen 80;
    server_name example.com;
    rewrite ^/(.*) https://example.com/$1 permanent;
}

Then save and quit.

Now restart Nginx to load the new configuration and enable TLS/SSL over HTTPS!

sudo service nginx restart

Test it out by accessing your site via HTTPS, e.g. https://example.com.

Apache

If want to use your certificate with Apache on Ubuntu 14.04, follow this section.

Make a backup of your configuration file by copying it. Assuming your server is running on the default virtual host configuration file, /etc/apache2/sites-available/000-default.conf, use these commands to to make a copy:

cd /etc/apache2/sites-available
cp 000-default.conf 000-default.conf.orig

Then open the file for editing:

sudo vi 000-default.conf

Find the <VirtualHost *:80> entry and modify it so your web server will listen on port 443:

<VirtualHost *:443>

Then add the ServerName directive, if it doesn’t already exist (substitute your domain name here):

ServerName example.com

Then add the following lines to specify your certificate and key paths (substitute your actual paths here):

SSLEngine on
SSLCertificateFile /home/sammy/example.com.crt
SSLCertificateKeyFile /home/sammy/example.com.key

If you are using Apache 2.4.8 or greater, specify the CA intermediate bundle by adding this line (substitute the path):

SSLCACertificateFile /home/sammy/intermediate.crt

If you are using an older version of Apache, specify the CA intermediate bundle with this line (substitute the path):

SSLCertificateChainFile /home/sammy/intermediate.crt

At this point, your server is configured to listen on HTTPS only (port 443), so requests to HTTP (port 80) will not be served. To redirect HTTP requests to HTTPS, add the following to the top of the file (substitute the name in both places):

<VirtualHost *:80>
   ServerName example.com
   Redirect permanent / https://example.com/
</VirtualHost>

Save and exit.

Enable the Apache SSL module by running this command:

sudo a2enmod ssl

Now restart Apache to load the new configuration and enable TLS/SSL over HTTPS!

sudo service apache2 restart

Test it out by accessing your site via HTTPS, e.g. https://example.com. You will also want to try connecting via HTTP, e.g. http://example.com to ensure that the redirect is working properly!

Conclusion

Now you should have a good idea of how to add a trusted SSL certificate to secure your web server. Be sure to shop around for a CA that you are happy with!

The above context referred to the article of Mitchell Anicas posting on DigitalOcean

How do you setup your ubuntu 16.04 Wifi with Iphone Personal Hotspot

At the begining, I just only got success on WiFi, which means I do NOT have other experiences on Tether or Bluetooth .

Okay, Let’s go ahead.

1.First,  move toward your iphone, and go Personal Hotspot in your Settings

2.Secondly, enable your Wifi, and turn on your Personal Hotspot

3. Mark down the name under the Now Discoverable section in grey

4. Take down the Wi-Fi password, or you can change default value while drilling down

5. Go ubuntu

6. Set up /etc/network/interfaces

auto wlan0 iface wlan0
inet dhcp 
wpa-ssid <the name you just took down> 
wpa-psk <the Wi-Fi password you just took down>

7. restart your interface

sudo ifdown wlan0 && sudo ifup -v wlan0

8. check if you can connect

ping -c5 8.8.8.8

Make a Bootable USB from an ISO File in Macos

While surfing lots of articles, I found out the most useful and simplest way.

Some peoples say that you should convert ISO first; however, it is not necessary as my experience.

The steps are as followsL

  • First run diskutil list
  • then insert your usb stick
  • and run diskutil list again to check the disk node you just insert(e.g. /dev/disk2), and please keep in mind the identifier.
  • Now run diskutil unmountDisk /dev/(Identifier)
  • and do sudo dd if=/path-to.iso of=/dev/r(Identifier) bs=1m (or bs=1M with homebrew)
  • When finished diskutil eject /dev/(Identifier)

 

Note that why do we need rDisk ? Here is the answer. Helpfully, this article can solve your problem.

The reason is that rdisks are "raw" thus resulting in a higher R/W speed, according to man hdiutil[1]:

/dev/rdisk nodes are character-special devices, but are “raw” in the BSD sense and force block-aligned I/O. They are closer to the physical disk than the buffer cache. /dev/disk nodes, on the other hand, are buffered block-special devices and are used primarily by the kernel’s filesystem code.

How do you solve the issues during the installation/maintenance of the DRBD

While trying to construct your HA solution using pacemaker,corosync on Database, you probably adopt drbd at the same time. However, drbd might cause some situations, and I referred to the article from 51cto, helping us to solve most of problems

 

Problem 1:

While configuring primary node, you get the message regarding “failed to UpToDate data"

# drbdadm primary r0      
r0: State change failed: (-2) Need access to UpToDate data
Command 'drbdsetup primary r1' terminated with exit code 17

Sol 1:

# drbdadm primary --force r0          
# drbd-overview 
 1:r1/0Connected(1*) Primary(1*) UpToDate(1*)

or

#drbdadm -- --overwrite-data-of-peer primary r0 #ro indicates resource name
# drbd-overview
1:r0/0Connected(1*) Primary(1*) UpToDate(1*)

Problem 2:

failed to create metadata
# drbdadm -c /etc/drbd.conf create-md all
md_offset 314568704
al_offset 314535936
bm_offset 314523648
Found ext3 filesystem
      307200 kB data area apparently used
      307152 kB left usable by current configuration
      
Device size would be truncated, which
would corrupt data and result in
'access beyond end of device' errors.
You need to either
   * use external meta data (recommended)
   * shrink that filesystem first
   * zero out the device (destroy the filesystem)
Operation refused.
Command 'drbdmeta 1 v09 /dev/sdb1 internal create-md 1' terminated with exit code 40

Sol 2

# dd if=/dev/zero of=/dev/sdb1 bs=1M count=100

 

Problem 3

Failed to create transport

# drbdadm up r1
r1: Failure: (172) Failed to create transport (drbd_transport_xxx module missing?)
Command 'drbdsetup new-peer r1 1 --_name=node2 --shared-secret=123456 --cram-hmac-alg=sha1 --protocol=C' terminated with exit code 10
drbdadm: new-path r1: skipped due to earlier error

Sol 3

try to install drbd_transport_tcp module

# cp drbd_transport_tcp.ko /lib/modules/3.10.0-229.el7.x86_64/kernel/lib/
# depmod  
# modprobe drbd_transport_tcp
# lsmod|grep drbd_transport_tcp
drbd_transport_tcp     17731  0 
drbd                  463948  2 drbd_transport_tcp

Problem 4

Ran into invalid configuration request when you try to up your resource.
# drbdadm up r1
r1: Failure: (162) Invalid configuration request
additional info from kernel:
minor exists as different volume
Command 'drbdsetup new-minor r1 1 1' terminated with exit code 10

Sol 4

install drbd module
#  cd drbd-9.0.0/drbd
# cp drbd.ko /lib/modules/3.10.0-229.el7.x86_64/kernel/lib/
# depmod
# modprobe drbd
# lsmod |grep drbd
drbd                  463948  0 
libcrc32c              12644  2 xfs,drbd

Problem 5

Busy on devices or resources

# drbdadm up r1
No valid meta data found
Command 'drbdmeta 1 v09 /dev/sdb1 internal apply-al' terminated with exit code 255
# drbdadm create-md all
open(/dev/sdb1) failed: Device or resource busy
Exclusive open failed. Do it anyways?
[need to type 'yes' to confirm] yes
# Output might be stale, since minor 1 is attached
Device '1' is configured!
Command 'drbdmeta 1 v09 /dev/sdb1 internal create-md 1' terminated with exit code 20

Sol 5

delete the partition, and then re-create it.

handle partition by fdisk /dev/sdb (type m for help)

# fdisk /dev/sdb
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types

m print this menu

n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition‘s system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

Problem 6

Unknown resources
# drbdadm primary r1
r1: Failure: (158) Unknown resource
additional info from kernel:
unknown resource
Command 'drbdsetup primary r1' terminated with exit code 10

Sol 6

# /etc/init.d/drbd start

Problem 7

# drbd-overview 
 1:r1/1  Connec/Connec Second/Unknow UpToDa/DUnkno

Sol 7

open up the firewall, and close down the SELinux

# systemctl stop firewalld

# drbd-overview 
 1:r1/1  Connec/StaAlo Second/Unknow Outdat/DUnkno

# getenforce 0 # the above command should be good, I am not sure this is necessary.

 

Problem 8

node2 cannot contact node1, and regards it as Standalone or being network partition

Sol 8

node 1

[root@node1 ~]# drbd-overview 
 1:mysqldata/1  Connec/Connec Second/Unknow UpToDa/DUnkno

 

node 2

[root@node2 ~]# drbd-overview 
 1:mysqldata/1  Connec/StaAlo Second/Unknow UpToDa/DUnkno

 

[root@node2 ~]# drbdadm --discard-my-data connect all
[root@node2 ~]# drbd-overview 
 1:mysqldata/1  Connec/Connec Second/Unknow UpToDa/DUnkno
[root@node2 ~]# drbd-overview               # need to take some time     
 1:mysqldata/1  Connected(2*) Secondary(2*) UpToDa/UpToDa

Problem 9 and Solution

node1 and node2 regard respectively other as standalone

[root@node1 ~]# drbd-overview 
 1:mysqldata/1  Connec/StaAlo Second/Unknow UpToDa/DUnkno
[root@node1 ~]# drbdadm --discard-my-data connect all
[root@node1 ~]# drbd-overview 
 1:mysqldata/1  Connec/Connec Second/Unknow UpToDa/DUnkno
[root@node2 ~]# drbd-overview 
 1:mysqldata/1  Connec/StaAlo Second/Unknow UpToDa/DUnkno
[root@node2 ~]# drbdadm connect all
[root@node2 ~]# drbd-overview 
 1:mysqldata/1  Connected(2*) Secondary(2*) UpToDa/UpToDa