ubuntu18.04にLXCでコンテナインストールしてsshまでやってみる

Lpic304の勉強がてら試したのでメモ。

参考

Linux Containers - LXC - はじめに

環境

Ubuntu 18.04 LTS

インストール

mukkun@mukkun-ubuntu:~$ sudo apt-get install lxc

## 初期設定
ブリッジの設定を追記する
mukkun@mukkun-ubuntu:~$ cat /etc/lxc/lxc-usernet
# USERNAME TYPE BRIDGE COUNT
mukkun veth lxcbr0 10

mukkun@mukkun-ubuntu:~$ mkdir ~/.config
mukkun@mukkun-ubuntu:~$ mkdir ~/.config/lxc
mukkun@mukkun-ubuntu:~$ cp /etc/lxc/default.conf ~/.config/lxc/default.conf

mukkun@mukkun-ubuntu:~$ grep $USER /etc/subgid
mukkun:165536:65536

↑この値と合わせる
cat << EOT >> ~/.config/lxc/default.conf
lxc.idmap = u 0 165536 65536
lxc.idmap = g 0 165536 65536
EOT

コンテナ作成・確認

mukkun@mukkun-ubuntu:~$ lxc-create -t download -n my-container
Setting up the GPG keyring
Downloading the image index

---
DIST    RELEASE ARCH    VARIANT BUILD
---
alpine  3.10    amd64   default 20200709_13:00
・
・
・

↑リストが出るので選ぶ。

Distribution:
ubuntu
Release:
xenial
Architecture:
i386

Downloading the image index
Downloading the rootfs
Downloading the metadata
The image cache is now ready
Unpacking the rootfs

---
You just created an Ubuntu xenial i386 (20200709_07:42) container.

To enable SSH, run: apt install openssh-server
No default root or user password are set by LXC.

コンテナの確認

mukkun@mukkun-ubuntu:~$ lxc-ls -f
NAME         STATE   AUTOSTART GROUPS IPV4       IPV6 UNPRIVILEGED
my-container RUNNING 0         -      10.0.3.175 -    true

起動

mukkun@mukkun-ubuntu:~$ lxc-start -n my-container -d

確認

mukkun@mukkun-ubuntu:~$ lxc-info my-container
Name:           my-container
State:          RUNNING
PID:            3888
IP:             10.0.3.175
Memory use:     18.60 MiB
KMem use:       7.08 MiB
Link:           vethUNE5V1
 TX bytes:      1.62 KiB
 RX bytes:      2.29 KiB
 Total bytes:   3.91 KiB

コンテナのユーザー作成

mukkun@mukkun-ubuntu:~$ lxc-attach -n my-container
root@my-container:/# adduser lahm
Adding user `lahm' ...
Adding new group `lahm' (1001) ...
Adding new user `lahm' (1001) with group `lahm' ...
Creating home directory `/home/lahm' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for lahm
Enter the new value, or press ENTER for the default
        Full Name []: lahm
        Room Number []:
        Work Phone []:
        Home Phone []:
        Other []:
Is the information correct? [Y/n] Y
root@my-container:/#

sudoにも追加しておく

root@my-container:/# gpasswd -a lahm sudo
Adding user lahm to group sudo

openssh-server入れておく
root@my-container:/# apt-get -y install openssh-server

root@my-container:/# exit
exit

ログインしてみる

mukkun@mukkun-ubuntu:~$ lxc-console -n my-container

Connected to tty 1
Type <Ctrl+a q> to exit the console, <Ctrl+a Ctrl+a> to enter Ctrl+a itself

Login incorrect
my-container login:
Login timed out after 60 seconds.

Ubuntu 16.04.6 LTS my-container pts/0

my-container login: lahm
Password:
Welcome to Ubuntu 16.04.6 LTS (GNU/Linux 4.15.0-109-generic i686)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

lahm@my-container:~$

ネットワーク確認

lahm@my-container:~$ ip -4 a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
5: eth0@if6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link-netnsid 0
    inet 10.0.3.175/24 brd 10.0.3.255 scope global eth0
       valid_lft forever preferred_lft forever
lahm@my-container:~$
lahm@my-container:~$ ip route
default via 10.0.3.1 dev eth0
10.0.3.0/24 dev eth0  proto kernel  scope link  src 10.0.3.175

ちゃんと外に出れる

lahm@my-container:~$ ping yahoo.co.jp
PING yahoo.co.jp (182.22.59.229) 56(84) bytes of data.
64 bytes from f1.top.vip.ssk.yahoo.co.jp (182.22.59.229): icmp_seq=1 ttl=49 time=4.49 ms
64 bytes from f1.top.vip.ssk.yahoo.co.jp (182.22.59.229): icmp_seq=2 ttl=49 time=4.18 ms

コンソールから抜ける時は Ctrl + a押した後にqを押せば抜けられる

ホストからコンテナにsshしてみる

mukkun@mukkun-ubuntu:~$ ssh lahm@10.0.3.175
The authenticity of host '10.0.3.175 (10.0.3.175)' can't be established.
ECDSA key fingerprint is SHA256:PB7M16D3fCJtHqLnrd4pJ+aYgjey+u1hj+pUeNZDnWk.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.3.175' (ECDSA) to the list of known hosts.
lahm@10.0.3.175's password:
Welcome to Ubuntu 16.04.6 LTS (GNU/Linux 4.15.0-109-generic i686)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

Last login: Fri Jul 10 00:46:19 2020
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

lahm@my-container:~$

コンテナ停止

<Code>
mukkun@mukkun-ubuntu:~$ lxc-ls -f
NAME         STATE   AUTOSTART GROUPS IPV4       IPV6 UNPRIVILEGED
my-container RUNNING 0         -      10.0.3.175 -    true
mukkun@mukkun-ubuntu:~$
mukkun@mukkun-ubuntu:~$ lxc-stop -n my-container
mukkun@mukkun-ubuntu:~$ lxc-ls -f
NAME         STATE   AUTOSTART GROUPS IPV4 IPV6 UNPRIVILEGED
my-container STOPPED 0         -      -    -    true

HOWTO: change default-gateway(context) after vm creation in OpneNebula Sunstone.

You might change default-gateway after vm creation in OpenNebula Sunstone.

1. VM shutdown

Just in case, vm state is shutodwn(PowerOff).

2.Configuration

VMs => select one vm => Conf => Update Configuration

f:id:mukkun0824:20200630135623p:plain

Context => Configuration =>Uncheck 'Add Network contextualization' f:id:mukkun0824:20200630135812p:plain

Please move Custom vars and input some vars. When input finished , click 'Update'.

f:id:mukkun0824:20200630140608p:plain

You can see gateway what you input earlier.

f:id:mukkun0824:20200630140718p:plain

I hope helping you.

Ruby on Rails チュートリアル 拡張機能 ( 2 .ユーザー検索・マイクロポスト検索機能追加)

拡張機能内容

今回は、追加機能の2つのうちの「 2. ユーザー検索・マイクロポスト検索機能追加」を紹介します。

(1)エラーメッセージの i18n対応(日本語対応)

(2) ユーザー検索・マイクロポスト検索機能追加

動作イメージ

https://yusuke-sampleapp2.herokuapp.com/

testユーザーでログインして動作が確認できます。

  • メールアドレス:test@gmail.com
  • パスワード: foobar

検索機能の機能概要

  • ユーザー一覧ページでユーザーの名前で検索できる。
  • ログイン後のHomeページ、ユーザーのプロフィールページでマイクロポストのコンテンツ内容で検索ができる。
  • 検索にヒットする場合は、フラッシュで検索した件数を画面に出力する。
  • 検索にヒットしない場合は、フラッシュでヒットしなかった旨を画面に出力し、デフォルトの検索結果を出力する
  • 検索したキーワードをハイライトで表示させる。

イメージ

ユーザー検索

f:id:mukkun0824:20200628190619g:plain

マイクロポスト検索

f:id:mukkun0824:20200628190635g:plain

実装

ユーザー検索機能の実装

検索結果の数をflashで表示するためのメソッド作成

 【中略】

    def count_flash(search_result)
      flash.now[:success] = t('.search result count',search_result_count: search_result.count)
    end

モデルの作成

 【中略】

  # 検索機能
  def self.search(keyword)
    if keyword.nil? || keyword.size > 0
      User.where(['name LIKE ?', "%#{keyword}%"])
    else
      return nil
    end
  end

 【中略】

コントローラーの作成

 【中略】

  def index
    #検索機能
    search_result = User.search(params[:keyword]) if params[:keyword]

    if search_result && !search_result.empty?
      @users = search_result.paginate(page: params[:page])
      @highlight_keyword = params[:keyword]
      count_flash(search_result)
    else
      @users = User.paginate(page: params[:page])
      flash.now[:info] = t('.not hit search') if params[:keyword]
    end
  end

 【中略】
 

ビューの作成。マイクロポスト検索でも使うのでパーシャル化しておく。

 【中略】
 
<div class="search">
  <%= form_with( url: yield(:path), method: :get, local: true) do |f|%>
      <%= f.text_field :keyword , class: 'form-control',placeholder: t('.search placeholder') %>
      <%= f.submit t('.search'), :name => nil , class: "btn btn-primary" %>
  <% end %>
</div>

【中略】

一覧ページから呼び込むようにする。

<% provide(:title, 'All users') %>
<h1>All users</h1>

<%= render 'shared/search' %>

<%= will_paginate %>

【中略】

ハイライト表示するようにユーザー一覧のビューも変更

<li>
  <%= gravatar_for user, size: 50 %>

  <%  u_link = link_to user.name, user %>

  <%= highlight(u_link,@highlight_keyword) %>
  <% if current_user.admin? && !current_user?(user) %>
    | <%= link_to "delete", user, method: :delete,
                                  data: { confirm: "You sure?" } %>

 【中略】

マイクロポスト検索機能の実装(ユーザープロフィールページ)

モデルの作成

 【中略】

  # 検索機能
  def self.search(keyword)
    if keyword.nil? || keyword.size > 0
      Micropost.where(['content LIKE ?', "%#{keyword}%"])
    else
      return nil
    end
  end

 【中略】

コントローラーの作成

 【中略】

  def show

    @user = User.find(params[:id])

    # 検索機能追加
    search_result = @user.microposts.search(params[:keyword]) if params[:keyword]

    if search_result && !search_result.empty?
      @microposts = search_result.paginate(page: params[:page])
      @highlight_keyword = params[:keyword]
      count_flash(search_result)
    else
      @microposts = @user.microposts.paginate(page: params[:page])
      flash.now[:info] = t('.not hit search') if params[:keyword]
    end

  end
 【中略】

ビューの作成 まずrenderを追加

 【中略】

  <div class="col-md-8">
    <%= render 'follow_form' if logged_in? %>
    <% if @user.microposts.any? %>
      <h3>Microposts (<%= @user.microposts.count %>)</h3>

        <%= render 'shared/search' %>

      <ol class="microposts">
        <%= render @microposts %>
      </ol>

 【中略】

ハイライト表示するようにマイクロポスト一覧のビューも変更

<li id="micropost-<%= micropost.id %>">
  <%= link_to gravatar_for(micropost.user, size: 50), micropost.user %>
  <span class="user"><%= link_to micropost.user.name, micropost.user %></span>
  <span class="content">
    <%= highlight(micropost.content,@highlight_keyword) %>
    <%= image_tag micropost.display_image if micropost.image.attached? %>
  </span>

 【中略】

マイクロポスト検索機能の実装(ホームページ)

モデルは変更ありません。

コントローラーの作成

 【中略】

  def home
    if logged_in?
      @micropost  = current_user.microposts.build
      search_result = current_user.feed.search(params[:keyword]) if params[:keyword]

        if search_result && !search_result.empty?
          @feed_items = search_result.paginate(page: params[:page])
          @highlight_keyword = params[:keyword]
          count_flash(search_result)
        else
          @feed_items = current_user.feed.paginate(page: params[:page])
          flash.now[:info] = t('.not hit search') if params[:keyword]
        end
    end
  end

 【中略】

ビューの作成 renderを追加するだけです。あとはユーザープロフィールページのマイクロポスト一覧のところの実装がそのまま使えます。

 【中略】

    <div class="col-md-8">
      <h3>Micropost Feed</h3>
      <%= render 'shared/search' %>
      <%= render 'shared/feed' %>
    </div>

 【中略】

i18n対応

ja:
  static_pages:
    home:
      not hit search:       '検索条件にヒットしませんでした。'
      search result count:  '%{search_result_count}件ヒットしました。'
ja:
  users:
    index:
      not hit search:       '検索条件にヒットしませんでした。'
      search result count:  '%{search_result_count}件ヒットしました。'
    show:
      not hit search:       '検索条件にヒットしませんでした。'
      search result count:  '%{search_result_count}件ヒットしました。'
ja:
  shared:

 【中略】

    search:
      search placeholder:             '検索したい文字を入力してください'
      search:                         '検索'

以上で実装が完了です。

お役に立てれば幸いです。

Ruby on Rails チュートリアル 拡張機能 ( 1 .エラーメッセージの i18n対応(日本語対応))

前置き

私は普段はインフラエンジニアなのですが、仕事でWebアプリケーションを触る機会があり、Webアプリケーションの基本を勉強しなおそうということで、ある講座でRuby On Rails チュートリアルを受講しました。Rubyを触る機会は仕事ではほぼ無いので、なかなか良い経験になりました。

railstutorial.jp

Railsチュートリアルは14の章からなる構成で、TwitterライクなWebサイトを1から作成するものです。ユーザーのログイン機能や投稿機能などを1から学べるため、Webアプリケーション機能の基礎を学びたい人にとっては良い教材だと思います。

拡張機能内容

14章まで終えると一通りのサイトはできるのですが、講座の最後に課題として機能を追加してみようというのがあり、私は以下の2つの機能を追加してみました。

(1) エラーメッセージの i18n対応(日本語対応)

(2) ユーザー検索・マイクロポスト検索機能追加

(1) のi18n (国際化・多言語化を意味する internationalization を短縮したもの)対応というのは、Rubyのデフォルトは英語なので、エラーメッセージなども全て英語です。それを極力日本語にするための対応です。

railsguides.jp

(2) のユーザー検索・マイクロポスト検索機能追加については、その名の通り、ユーザーとマイクロポストの投稿内容(ツイート内容)を検索できるようにした機能追加です。

動作イメージ

https://yusuke-sampleapp2.herokuapp.com/

testユーザーでログインして動作が確認できます。

  • メールアドレス:test@gmail.com
  • パスワード: foobar

実装

railsのバージョンは6.0.0です

$ rails version
Rails 6.0.0

こんな感じで日本語のエラー or 成功メッセージが出るようにします。また、フォームも日本語に置き換えます。所々コードや実装で抜けていろところがありますが、ご容赦ください。。。

小さくて見にくくてすみません。。

f:id:mukkun0824:20200628185301g:plain

Gemをインストール

i18n対応にはymlファイルで翻訳する語彙を作っていくのですが、一つ一つ単語や文をymlに書いても良いのですが、基本的なところは反映させてしまいたいので、Gemで rails-i18n というGemを入れます。

gem 'rails-i18n', '6.0.0'

bundle install 実施します。

$ bundle install

これでGemが入りました。なお、ymlファイルの階層はこんな感じにしました。これは拡張機能を全て実装した場合の最終的なものです。コントローラやviewごとに階層化します。

$ tree -A config/locales/
config/locales/
├── controllers
│   ├── account_activations_controller
│   │   └── ja.yml
│   ├── microposts
│   │   └── ja.yml
│   ├── password_resets_controller
│   │   └── ja.yml
│   ├── sessions_controller
│   │   └── ja.yml
│   └── users
│       └── ja.yml
├── en.yml
├── ja.yml
├── models
│   ├── micropost
│   │   └── ja.yml
│   └── user
│       └── ja.yml
└── views
    ├── sessions
    │   └── ja.yml
    ├── shared
    │   └── ja.yml
    └── users
        └── ja.yml

初期設定

ロケールや言語の設定をしておく。また、読み込みファイルの設定もしておきます。

module SampleApp2
  class Application < Rails::Application
【中略】
    # i18n対応
    # デフォルトのlocaleを日本語(:ja)にする
    config.i18n.default_locale = :ja

    config.time_zone = 'Tokyo'
    config.active_record.default_timezone = :local


    # 複数のロケールが読み込まれるようにする
    config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}').to_s]
  end
end

テスト

まずテストを書きます。基本的にflashやエラーメッセージの部分の表示を変更します。エラーメッセージは意外と色々なところに出てくるので、インテグレーションテストの追記が多くなります。

  test "micropost interface" do
    log_in_as(@user)

【中略】

    # 無効な送信
    assert_no_difference 'Micropost.count' do
      post microposts_path, params: { micropost: { content: "" } }
    end
    assert_select 'div#error_explanation'
    assert_select 'div.alert-danger','1個のエラーがあります。'

    assert_select 'a[href=?]', '/?page=2'  # 正しいページネーションリンク

    # 有効な送信
    content = "This micropost really ties the room together"
    assert_difference 'Micropost.count', 1 do
      post microposts_path, params: { micropost: { content: content } }
      assert_equal  '投稿しました!',flash[:success]
    end

【中略】

    # 投稿を削除する

    assert_select 'a', text: 'delete'
    first_micropost = @user.microposts.paginate(page: 1).first
    assert_difference 'Micropost.count', -1 do
      delete micropost_path(first_micropost)
      assert_equal '投稿が削除されました。',flash[:success]
    end

【中略】

  test "password resets" do
    get new_password_reset_path

【中略】

    # メールアドレスが無効
    post password_resets_path, params: { password_reset: { email: "" } }
    assert_not flash.empty?
    assert_select 'div.alert-danger','有効なメールアドレスが見つかりません。'
    assert_template 'password_resets/new'

    # メールアドレスが有効
    assert_not flash.empty?
    assert_equal 'パスワード再設定用のメールを送信しました。',flash[:info]

【中略】

    assert_equal 'パスワードが更新されました。',flash[:success]
    assert_redirected_to user
  end
end
  test "successful edit with friendly forwarding" do

【中略】

    patch user_path(@user), params: { user: { name:  name,
                                              email: email,
                                              password:              "",
                                              password_confirmation: "" } }
    assert_not flash.empty?
    assert_equal  'プロフィールが更新されました。',flash[:success]
    assert_redirected_to @user
【中略】
  test "index as admin including pagination and delete links" do
    log_in_as(@admin)

【中略】

    assert_difference 'User.count', -1 do
      delete user_path(@non_admin)
      assert_equal 'ユーザーが削除されました。',flash[:success]
    end
  #誤っているデータ ログインできないはず
  test "login with valid email/invalid password" do

【中略】

    assert_not flash.empty?
    assert_select 'div.alert-danger','メールアドレスとパスワードの組み合わせが間違っています。'
    get root_path
    assert flash.empty?
  end
  test "invalid signup information" do
    get signup_path

【中略】

    assert_select 'div.alert-danger','4個のエラーがあります。'
    assert_select 'div.field_with_errors'
  end

【中略】

  test "valid signup information with account activation" do
    get signup_path
    assert_equal 1, ActionMailer::Base.deliveries.size

    assert_equal 'アカウント有効化に関するメールを確認してください。',flash[:info]

    user = assigns(:user)

【中略】

コントローラーの日本語化

コントローラーに翻訳場所指定するためには、Rails#tヘルパー を使います 。この #tヘルパー に、各訳文の意味を適切に表すキーを与えます(Rails ガイド参照)。

こんな感じでエラーメッセージが日本語化されます。後ほど記載しますが、modelも日本語化しておきます。

基本的にコントローラー内でflashを使うところは全て書き換えます。

【中略】


        flash[:danger] = t('.please log in')
        redirect_to login_url
      end
    end
 【中略】

     flash[:success] = t('.micropost created')

 【中略】

     flash[:success] = t('.micropost deleted')

 【中略】
 【中略】

      flash[:info] = t('.sent email')

 【中略】

      flash[:success] = t('.password reset success')

 【中略】
 【中略】

      flash[:info] = t('.check email')

 【中略】

      flash[:success] = t('.profile updated')
 
 【中略】

    flash[:success] = t('.user deleted')

 【中略】

これらに対して以下のようにymlファイルを作成して対応させる

usersコントローラに対して config/locales/controllers/users/ja.yml

ja:
  users:
    create:
      check email:          'アカウント有効化に関するメールを確認してください。'
    edit:
      please log in:          'ログインしてください。'
    update:
      profile updated:       'プロフィールが更新されました。'
      please log in:          'ログインしてください。'
    destroy:
      user deleted:          'ユーザーが削除されました。'

password_resets_コントローラに対して

ja:
  password_resets:
    create:
      sent email:        'パスワード再設定用のメールを送信しました。'
      cannot sent email: '有効なメールアドレスが見つかりません。'
    update:
      password reset success:   'パスワードが更新されました。'

micropostsコントローラに対して

ja:
  microposts:
    create:
      micropost created:          '投稿しました!'
    destroy:
      micropost deleted:          '投稿が削除されました。'

account_activationsコントローラに対して

ja:
  account_activations:
    edit:
      activated:                     'アカウントが有効化されました'
      invalid activation link:       'アカウント有効化用のリンクが誤っています'

sessionsコントローラに対して

ja:
  sessions:
    create:
      not activated:        'アカウントが有効化されていません。 '
      check email:          'アカウント有効化に関するメールを確認してください。'
      invalid combination:  'メールアドレスとパスワードの組み合わせが間違っています。'

ビューの日本語化

ビューもコントローラーと同じようにRails#tヘルパー を使って日本語化します。また、フォームの部分も書き換えておきます。

 【中略】


      <%= f.label :email , t('.email')%>
      <%= f.email_field :email, class: 'form-control' %>

      <%= f.label :password , t('.password')%>
      <%= link_to t('.forgot password'), new_password_reset_path %>
      <%= f.password_field :password, class: 'form-control' %>

      <%= f.label :remember_me, class: "checkbox inline" do %>
        <%= f.check_box :remember_me %>
        <span> <%= t('.remember me') %> </span>
      <% end %>

      <%= f.submit t('.log in'), class: "btn btn-primary" %>
    <% end %>

 【中略】
<% if object.errors.any? %>
  <div id="error_explanation">
    <div class="alert alert-danger">
        <%= t('.errors count', errors_count: object.errors.count) %>
    </div>

 【中略】

f.label :password_confirmation, "Confirmation", "Confirmation" を削除しておく。

      <%= f.label :password_confirmation %>
      <%= f.password_field :password_confirmation, class: 'form-control' %>

      <%= f.submit t('.Create my account'), class: "btn btn-primary" %>

モデルの日本語化

ついでにモデルも日本語化してフォームを日本語にしておきます。

ja:
  activerecord:
    models:
      # view側: User.model_name.human => "ユーザ" / t("activerecord.models.user")と同じ
      micropost:          '投稿'
    attributes:
        micropost:
          content:        '投稿内容'
          image:          '画像'
          invalid format: 'jpeg,gif,png以外のフォーマットは使用できません'
          invalid size:   '1MB以上の画像は投稿できません'

  errors:
    messages:
      less_than_xmb:      'は1MBより小さいファイルをアップロードしてください'
ja:
  activerecord:
    models:
      user:                       'ユーザー'
    attributes:
        user:
          name:                   '名前'
          email:                  'メールアドレス'
          password:               'パスワード'
          password_confirmation:  'パスワード(確認用)'

以上で実装が完了です。

お役に立てれば幸いです。

MattermostのSSL証明書更新 (Let's Encrypt)

あまり日本語の(特にCentos)記事がないのでメモ

参考:

docs.mattermost.com

version

Mattermostのバージョン: 5.20.1

environment

コマンド

スタンドアロンモードで鍵を取得した場合の例です。

# /usr/local/bin/certbot/certbot-auto certonly --reinstall --nginx -d [domain] && systemctl reload nginx.service

Cron

# crontab -l
0 4 1 * * /usr/local/bin/certbot/certbot-auto certonly --reinstall --nginx -d [domain] && systemctl reload nginx.service

お役に立てれば幸いです。

HOWTO: Custom css and html of OpneNebula Sunstone.

You might to want to recognize which is environment of production and development if you have. In that case, you want to change html and css.

change background color

If you want to change background color , you can modify css file '/usr/lib/one/sunstone/public/css/custom.css' of line 26.

20 body{
 21         padding:0;margin:0;
 22         font-family:"Lato","Helvetica Neue",Helvetica,Roboto,Arial,sans-serif;
 23         font-weight:300;
 24         line-height:1.5;
 25         color:#0a0a0a;
 26         background:#dcdcdc;
 27 }

change html

For example , you want to set footer bar, you change html file '/usr/lib/one/sunstone/views/index.erb' of line 109 to 111 .

   109      <div style="position: fixed; bottom: 0px; width: 100%; height: 1.3em; line-height: 1.3em; z-index: 9999; background-color: red; text-align: center; font-weight:  bold; font-size: 1.3em; color: white;">
   110      This page is development env of OpenNebula.
   111      </div>
   112  
   113  
   114      <% if $conf[:env] == 'dev' %>
   115        <script src="bower_components/requirejs/require.js" data-main="app/main"></script>
   116      <% else %>
   117        <script src="dist/main.js?v=<%= OpenNebula::VERSION %>"></script>
   118      <% end %>
   119    </body>
   120  </html>

It looks like this. f:id:mukkun0824:20200523111932p:plain

I hope you helpful :)

HOWTO: Change oenadmin and serveradmin password in OpenNebula

version

version = 5.9.90

reference

  • oneadmin password change

Managing Users — OpenNebula 5.10.5 documentation

  • serveradmin password change

User Security and Authentication — OpenNebula 5.10.5 documentation

example my env

user list

[oneadmin@opennebula-cp ~]$ oneuser list
  ID NAME                                                                              GROUP    AUTH            VMS     MEMORY        CPU
   1 serveradmin                                                                       oneadmin server_c    0 /   -      0M /   0.0 /   -
   0 oneadmin                                                                          oneadmin core              -          -          -

oneadmin (ID=>0)

[oneadmin@opennebula-cp ~]$ oneuser passwd 0 password000
[oneadmin@opennebula-cp ~]$ echo 'oneadmin:password000' > /var/lib/one/.one/one_auth
[oneadmin@opennebula-cp ~]$ exit
exit
[root@opennebula-cp ~]# systemctl restart opennebula

If mm_sched didnt restart after you restarted opennebula, you might be better to stop it (optional).

[oneadmin@opennebula-cp ~]$ ps auxw | grep mm_sched
oneadmin  2245  0.0  0.0 112712   960 pts/0    S+   22:19   0:00 grep --color=auto mm_sched
oneadmin 29158  0.0  0.3 267504 14184 ?        Ssl  Apr23   3:03 /usr/bin/mm_sched
[oneadmin@opennebula-cp ~]$ kill 29158

Please exec mm_sched in background.

[oneadmin@opennebula-cp ~]$ mm_sched &
[1] 2248
[oneadmin@opennebula-cp ~]$ ps auxw | grep mm_sched
oneadmin  2248  1.0  0.1 193768  6052 pts/0    Sl   22:19   0:00 mm_sched
oneadmin  2254  0.0  0.0 112712   964 pts/0    S+   22:19   0:00 grep --color=auto mm_sched

Please confirm 'oneuser show' command by oneadmin. If you could not show this command, you may failed password change.

[root@opennebula-cp ~]# su oneadmin -
[oneadmin@opennebula-cp root]$ cd
[oneadmin@opennebula-cp ~]$ oneuser show
USER 0 INFORMATION
ID              : 0
NAME            : oneadmin
GROUP           : oneadmin

serveradmin (ID=>1)

*password must enough lengh

[oneadmin@opennebula-cp ~]$ oneuser passwd 1 --sha256 password0123hogehoge999
[oneadmin@opennebula-cp ~]$ echo 'serveradmin:password0123hogehoge999' > /var/lib/one/.one/oneflow_auth
[oneadmin@opennebula-cp ~]$ echo 'serveradmin:password0123hogehoge999' > /var/lib/one/.one/ec2_auth
[oneadmin@opennebula-cp ~]$ echo 'serveradmin:password0123hogehoge999' > /var/lib/one/.one/onegate_auth
[oneadmin@opennebula-cp ~]$ echo 'serveradmin:password0123hogehoge999' > /var/lib/one/.one/occi_auth
[oneadmin@opennebula-cp ~]$ echo 'serveradmin:password0123hogehoge999' > /var/lib/one/.one/sunstone_auth
[oneadmin@opennebula-cp ~]$ exit
exit
[root@opennebula-cp ~]# systemctl restart opennebula-sunstone

Sunstone login

Please confirm login sunstone using new password(oneadmin's password.NOT serveradmin password).

I hope your helpful.