zuntan02のはてなブログ

備忘録的なものです。時々職場の技術者ブログにも転記してますが、メインはこちらで。

confファイルのコメントを消してすっきりさせる:egrep -v '^(#|$)'

例)

cat /etc/httpd/conf.d/ssl.conf | egrep -v '^(#|$)' > /etc/httpd/conf.d/ssl.conf_edited

■コマンドについて

egrep

egrep [オプション] [検索文字列パターン] ファイル
grepよりも高度な正規表現を使用できる。

-v

マッチしない行を出力する。

'^(#|$)'

・行頭が#(^#)←コメント行
OR
・行頭が行末(^$)←空行

【メモ】Linuxのディレクトリ構造(FHS)

このプログラムどこに置いたらいいの?みたいな時に手癖でやってたらFHS(Filesystem Hierarchy Standard)理解しろと怒られた気がしたのでちゃんと見直したい。

Wikipediaより抜粋

ディレクト 説明
/ ファイルシステム階層全体の第一階層(ルートディレクトリ)
/bin シングルユーザモード(英語版)で必要となる一般ユーザー向けの基本コマンドの実行ファイル (binaries)。例えばcat、ls、cpなど。
/boot ブートローダー (boot loader) 関連のファイル群。例えば、カーネルや initrd(初期RAMディスク)。
/dev 基本デバイス(device)。例えば、/dev/nullなど。
/etc システム全体に関わる固有設定ファイル群。
/etc/opt /opt/のための設定ファイル群。
/etc/X11 X Window System, version 11 用の設定ファイル群。
/etc/sgml SGML の設定ファイル群。
/etc/xml XML の設定ファイル群。
/home ユーザーの ホームディレクトリ (home directory) 群。セーブファイル、個人用設定など。別パーティションとすることが多い。
/lib /bin/ や /sbin/ にある実行ファイルの基本となるライブラリ (library) 群。
/media CD-ROMなどのリムーバブル媒体 (media) のマウントポイント(FHS-2.3 で追加)
/mnt ファイルシステムの一時マウントポイント (mount)
/opt オプション (option) のアプリケーションソフトウェアパッケージのインストール用
/proc カーネルやプロセス (process) の状態に関する情報を主にテキストで示す仮想ファイルシステム(例えば、実行時間やネットワークなど) 用。procfsのマウントポイント。
/root rootユーザのホームディレクトリ。
/run 実行時の可変データー。FHS3.0より新設。
/sbin システム管理系コマンドの実行ファイル群(例えば、init、ip、mount)。(system binaries)
/srv システムによって提供された (served) サイト固有のデータ
/tmp 一時ファイル置場 (temporary files)。/var/tmp も参照されたい。リブート時に内容が保持されない。
/usr 大部分のマルチユーザ(全ユーザのための)ユーティリティとアプリケーションを格納する。ホスト固有の情報や時間の経過に伴い変化する情報は他の場所に保存される(前者は /etc、後者は /var の下)。共有可能でリードオンリーのデータであるべき。この事は /usr がFHS準拠の様々なホスト間で共有可能であるべき事を意味しており、書き込みができないようにしなければいけない
/usr/bin 一般ユーザ向けだが基本的ではないコマンドの実行ファイル
/usr/include 標準 includeファイル群
/usr/lib /usr/bin/ や /usr/sbin/ にある実行ファイルの基本となるライブラリ (library) 群。
/usr/sbin 基本的でないシステム実行ファイル群。例えば、各種ネットワークサービス用デーモンなど。
/usr/share アーキテクチャに依存しない共有 (shared) データ
/usr/src ソースコード (Source code)。例えば、カーネルソースコードとそのヘッダファイル群など。
/usr/X11R6 X Window System, Version 11 Release 6
/usr/local ホスト固有のローカル (local) データを格納する第三階層。通常、さらにサブディレクトリとして bin/、lib/、share/ などを持つ[29]
/var 可変 (Variable) なファイル群。内容が常に変化するようなファイル群を格納する。例えば、ログ、スプール、一時的電子メールファイルなど。別パーティションとすることもある。
/var/cache アプリケーションのキャッシュデータ。時間のかかるI/Oや計算によって生成されたデータなど。従って再度生成することも可能なので、削除してもデータが失われるわけではない(時間は無駄となる可能性がある)。
/var/lib 状態情報。プログラムの実行によって更新された永続性データなど。例えばデータベース、パッケージングシステムのメタデータなど。
/var/lock ロック(Lock)ファイル群。使用中リソースを保持するファイル。
/var/log ログ(Log)ファイル。各種ログ。
/var/mail ユーザーのメールボックス(mail-box)
/var/run 最近のブート以降の走行中(runing)システムに関する情報。例えば現在ログイン中のユーザー、走行中のデーモンなど。FHS3.0 では /var/run は /run に置き換えられる。システムは後方互換性のために /var/run を提供するか、/var/run から /run へのシンボリックリンクを提供しなければならない。
/var/spool 処理待ち状態のタスクのスプール(spool)。例えばプリントキュー、未読メールなど。
/var/spool/mail 互換のために残された、かつてのユーザーのメールボックス(mail-box)の場所。
/var/tmp 一時ファイル置場(Temporary files)。 /tmp と異なり、リブートしても内容が失われることはない。

【メモ】MySQLでDBとテーブルのサイズを確認するSQL

【参考】

MySQLでDBとテーブルのサイズを確認するSQL - Qiita
じょうきのまんまコピペです。自分メモ用。

SQL

DB
SELECT 
    table_schema, sum(data_length) /1024/1024 AS mb 
FROM 
    information_schema.tables  
GROUP BY 
    table_schema 
ORDER BY       
    sum(data_length+index_length) DESC;
テーブル
use 対象DB;

SELECT  
    table_name, engine, table_rows AS tbl_rows,
    avg_row_length AS rlen,  
    floor((data_length+index_length)/1024/1024) AS 総容量(MB),
    floor((data_length)/1024/1024) AS データ容量(MB),
    floor((index_length)/1024/1024) AS インデックス容量(MB)
FROM 
    information_schema.tables  
WHERE
    table_schema=database()  
ORDER BY
    (data_length+index_length) DESC;  
binlogの確認

DBが増える可能性が低いのであれば、update/insertが増えたことによる
レプリケーション用のbinlogの増大が考えられます。
# binlogの確認
mysqlbinlog [options] LOG_FILE

【macOS】MacBook12インチに有線LAN:エレコム 有線LANアダプタEDC-GUA3-B→ドライバ有効化までのメモ

【状況】

MacBook12インチ(USB-CハブとしてAnskp HDMI/USB3.0/Type-Cハブ接続済み)に有線LANをつけたくて

エレコム 有線LANアダプタEDC-GUA3-B
を買って、説明書通りドライバをDLしてインストール、の後USBポートに繋いでみたけどネットワーク機器として有効にならない。OSXもといmacOSに慣れていないので半日ほどハマってしまった。

【原因及び解決】

エレコムのドライバをインストールしたが、macOSのセキュリティ設定で無効化されていた。
[システム環境設定]-[セキュリティとプライバシー]-[一般]でドライバがブロックされていたため解除した
→接続できた。

以上

【お名前.com】メール転送設定メモ

【参考】
https://www.onamae.com/guide/details.php?g=31#autoreply

example.jpのメール転送設定で

  • hoge@example.jpへのメールをhoge@aaa.bbb.jpに転送
  • fuga@example.jpへのメールをhoge@aaa.bbb.jpに転送したうえで自動返信

としたい
※上記によれば転送は必須みたい。

上記の場合の設定

■転送設定

転送元メールアドレス 転送先メールアドレス 状態 自動返信
hoge@example.jp hoge@aaa.bbb.jp 有効 設定なし
fuga@example.jp hoge@aaa.bbb.jp 有効 以下の様に設定

■自動返信設定設定

状態 有効
自動返信期間 2007/01/01 00時 ~ 2017/12/31 23:00まで
メール件名(Subject) fuga@example.comは送信専用です
メール本文(Body) fuga@example.comは送信専用です。……

【SVN】authzSVNによるディレクトリごとの閲覧コントロール

【概要】

Subversionで、リポジトリ単位でbasic認証による認証は行っていたが、その下階層について、階層ごとに閲覧権限を制限したいという要望があった。authzsvnが使えたのでメモ。

【今回の要望】

ユーザグループ:

mgr:マネージャ。下記のすべてのリポジトリを閲覧、更新可能
gp?u:/reporoot/gpxディレクトリ以下のみ閲覧、更新可能

階層
reporoot/ …….htpasswdで一括Basic認証を設定
|-- gp1 ……mgrとgp1userのみ閲覧、更新可能
|-- gp2 ……mgrとgp2userのみ閲覧、更新可能
|-- mgr ……mgrのみ閲覧、更新可能
【作業メモ】
# モジュール確認
apachectl -M
#  dav_svn_module (shared)
# →OK


vi /etc/httpd/conf.d/httpd-ssl.conf

 <Location /reporoot>
  DAV svn
  SVNPath /var/www/svn/reporoot/repository
  AuthType Basic
  AuthName "Restricted Area"
  Require valid-user
  AuthUserFile "/var/www/svn/reporoot/.htpasswd"
  AuthzSVNAccessFile "/var/www/svn/reporoot/authzsvn.conf"
 </Location>

vi /srv/projects/reporoot/root.authzsvn.conf

[groups]
# Managers
mgr = mgr1,mgr2

# group users
gp1u = user1, user2
gm2u = user3, user4

[/]
@mgr = rw

[reporoot:/gp1]
@gp1u = rw

[reporoot:/gp2]
@gp2u = rw

[reporoot:/mgr]

【ACM】SSL証明書年次更新について

【概要】

ELBに設置していたワイルドカードSSL証明書ACM)について、年次更新の案内メールが来た。FQDNならメールもなく自動更新らしいがワイルドカード証明書だとメール確認が必要。
新規取得時と同様のメールアドレスに承認メールが届くため、承認URLから承認すると、証明書の期限が自動的に1年延長される
(マネージドコンソールでの作業は不要)


【案内メール】

タイトル:Certificate renewal for example.com requires approval
メール本文:

Greetings from Amazon Web Services,

An SSL/TLS certificate for example.com is nearing its expiration date and requires your approval to renew.

Verify that the following domain, AWS account ID, AWS Region, certificate identifier, and expiration date correspond to a certificate that you or someone in your organization is using.

Domain: *.example.com
AWS account ID: xxxx-xxxx-xxxx
AWS Region name: us-east-1
Certificate identifier: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Expiration date: Dec 07, 2017 at 12:00:00 UTC

To approve this request, go to Amazon Certificate Approvals
<承認URL>
and follow the instructions on the page. 

If you choose not to approve this request, you do not need to do anything; however, the certificate will expire, which might make your website unreachable. To prevent future approval requests for this certificate, delete the certificate. See the AWS Certificate Manager User Guide for details.

This email is intended solely for authorized individuals for example.com. To express any concerns about this email or if this email has reached you in error, forward it along with a brief explanation of your concern to validation-questions@amazon.com.

Sincerely,
Amazon Web Services

【更新完了案内メール】

タイトル:Your certificate is renewed
メール本文:

Greetings from Amazon Web Services,

This notification is to notify you that AWS Certificate Manager (ACM) has completed the renewal of an SSL/TLS certificate for the following domains: 
*.example.com

AWS account ID: Xxxxxxxxxx
AWS Region name: us-east-1
Certificate identifier: arn:aws:acm:us-east-1:xxxxxxxxxx:certificate/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Your new certificate expires on Nov 25, 2018 at 12:00:00 UTC. 
If you have questions about this process, please use the Support Center at https://console.aws.amazon.com/support to contact AWS Support. If you don’t have an AWS support plan, post a new thread in the AWS Certificate Manager discussion forum at https://forums.aws.amazon.com/forum.jspa?forumID=206

This notification is intended solely for authorized individuals for *.legend-of-war.com. To express any concerns about this notification or if it has reached you in error, forward it along with a brief explanation of your concern to validation-questions@amazon.com.

Sincerely,
Amazon Web Services