てくてっく

コマ撮り作家系エンジニアです。日々地味ぃぃぃにつまづく技術的な問題について、備忘録として作ります。

Debianへのapache2のインストール

vagrantを導入したので、Webサーバをインストールするところから始めます!
なにもないところから一から始めているようで楽しい。

sudo apt -y install apache2

コマンドでインストールしようとしたら

 vagrant@Debian-jessie-amd64-netboot:/$ apt -y install apache2 

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap
liblua5.1-0 ssl-cert
Suggested packages:
apache2-doc apache2-suexec-pristine apache2-suexec-custom openssl-blacklist
The following NEW packages will be installed:
apache2 apache2-bin apache2-data apache2-utils libapr1 libaprutil1 libaprutil1-dbd-sqlite3
libaprutil1-ldap liblua5.1-0 ssl-cert
0 upgraded, 10 newly installed, 0 to remove and 2 not upgraded.
Need to get 1,939 kB of archives.
After this operation, 6,623 kB of additional disk space will be used.
Get:1 http://ftp.uk.debian.org/debian/ jessie/main libapr1 amd64 1.5.1-3 [95.3 kB]
Get:2 http://ftp.uk.debian.org/debian/ jessie/main libaprutil1 amd64 1.5.4-1 [86.2 kB]
Get:3 http://ftp.uk.debian.org/debian/ jessie/main libaprutil1-dbd-sqlite3 amd64 1.5.4-1 [19.1 kB]
Get:4 http://ftp.uk.debian.org/debian/ jessie/main libaprutil1-ldap amd64 1.5.4-1 [17.2 kB]
Get:5 http://ftp.uk.debian.org/debian/ jessie/main liblua5.1-0 amd64 5.1.5-7.1 [108 kB]
Err http://ftp.uk.debian.org/debian/ jessie/main apache2-bin amd64 2.4.10-10
404 Not Found [IP: 78.129.164.123 80]
Err http://ftp.uk.debian.org/debian/ jessie/main apache2-utils amd64 2.4.10-10
404 Not Found [IP: 78.129.164.123 80]
Err http://ftp.uk.debian.org/debian/ jessie/main apache2-data all 2.4.10-10
404 Not Found [IP: 78.129.164.123 80]
Err http://ftp.uk.debian.org/debian/ jessie/main apache2 amd64 2.4.10-10
404 Not Found [IP: 78.129.164.123 80]
Get:6 http://ftp.uk.debian.org/debian/ jessie/main ssl-cert all 1.0.35 [20.9 kB]
Fetched 347 kB in 6s (51.9 kB/s)
E: Failed to fetch http://ftp.uk.debian.org/debian/pool/main/a/apache2/apache2-bin_2.4.10-10_amd64.deb 404 Not Found [IP: 78.129.164.123 80]

E: Failed to fetch http://ftp.uk.debian.org/debian/pool/main/a/apache2/apache2-utils_2.4.10-10_amd64.deb 404 Not Found [IP: 78.129.164.123 80]

E: Failed to fetch http://ftp.uk.debian.org/debian/pool/main/a/apache2/apache2-data_2.4.10-10_all.deb 404 Not Found [IP: 78.129.164.123 80]

E: Failed to fetch http://ftp.uk.debian.org/debian/pool/main/a/apache2/apache2_2.4.10-10_amd64.deb 404 Not Found [IP: 78.129.164.123 80]

E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

と、fix-missing?とか聞かれたので、調べた。

↓gitインストールのときの記事だが、
https://qiita.com/n0bisuke/items/75f5fd5459e7bf75fdac

参考にさせて頂くと、単純にapt-get updateが必要なだけだった。
sudo apt-get updateしてから
sudo apt -y install apache2すると、

vagrant@Debian-jessie-amd64-netboot:/$ sudo apt-get update

Get:1 http://security.debian.org jessie/updates InRelease [44.9 kB]
Ign http://ftp.uk.debian.org jessie InRelease
Get:2 http://security.debian.org jessie/updates/main Sources [310 kB]
Get:3 http://ftp.uk.debian.org jessie-updates InRelease [7,340 B]
Get:4 http://security.debian.org jessie/updates/contrib Sources [1,439 B]
Get:5 http://ftp.uk.debian.org jessie Release.gpg [2,420 B]
Get:6 http://security.debian.org jessie/updates/non-free Sources [1,631 B]
Get:7 http://ftp.uk.debian.org jessie Release [148 kB]
Get:8 http://security.debian.org jessie/updates/main amd64 Packages [678 kB]
Get:9 http://security.debian.org jessie/updates/contrib amd64 Packages [2,506 B]
Get:10 http://security.debian.org jessie/updates/non-free amd64 Packages [4,556 B]
Get:11 http://security.debian.org jessie/updates/contrib Translation-en [1,211 B]
Get:12 http://security.debian.org jessie/updates/main Translation-en [342 kB]
Get:13 http://security.debian.org jessie/updates/non-free Translation-en [11.8 kB]
Get:14 http://ftp.uk.debian.org jessie/main Sources [7,063 kB]
Get:15 http://ftp.uk.debian.org jessie/contrib Sources [50.4 kB]
Get:16 http://ftp.uk.debian.org jessie/non-free Sources [99.2 kB]
Get:17 http://ftp.uk.debian.org jessie/main amd64 Packages [6,818 kB]
Get:18 http://ftp.uk.debian.org jessie/contrib amd64 Packages [49.8 kB]
Get:19 http://ftp.uk.debian.org jessie/non-free amd64 Packages [83.2 kB]
Get:20 http://ftp.uk.debian.org jessie/contrib Translation-en [38.3 kB]
Get:21 http://ftp.uk.debian.org jessie/main Translation-en [4,581 kB]
Get:22 http://ftp.uk.debian.org jessie/non-free Translation-en [72.0 kB]
Fetched 20.4 MB in 27s (735 kB/s)
W: Failed to fetch http://ftp.uk.debian.org/debian/dists/jessie-updates/InRelease Unable to find expected entry 'main/source/Sources' in Release file (Wrong sources.list entry or malformed file)
Enabling module authn_file.
Enabling module authz_user.
Enabling module alias.
Enabling module dir.
Enabling module autoindex.
Enabling module env.
Enabling module mime.
Enabling module negotiation.
Enabling module setenvif.
Enabling module filter.
Enabling module deflate.
Enabling module status.
Enabling module reqtimeout.
Enabling conf charset.
Enabling conf localized-error-pages.
Enabling conf other-vhosts-access-log.
Enabling conf security.
Enabling conf serve-cgi-bin.
Enabling site 000-default.
Setting up ssl-cert (1.0.35) ...
Processing triggers for libc-bin (2.19-18) ...
Processing triggers for systemd (215-17) ...

無事インストールできました!

DBeaverでreadonlyしたい

[ざっくり下書き]
DBeaverというSQLクライアントを使ってみた。

様々な接続のしかたが使い勝手良い。

SQLエディタの下部に「書き込み可能」という文言があるので、
readonly設定もクライアントで選択できそう

→見つからない

探した。GRANT・・・
obel.hatenablog.jp

Issueにあった。
Use DBeaver as a Read Only SQL Query Tool · Issue #4112 · dbeaver/dbeaver · GitHub

「書き込み可能」の文言は変わらなかったが、動きを確認したらreadonlyになっていた。
ロケールの問題かと思い一応英語版表示にして確認したが「Writable」のままだった。
「Read only」になってほしい。

とりあえず解決。

SQLのORDER BY句で複数列を指定したい

Postgresqlで、SQLのクエリ結果をソートしたい。

SELECT * FROM [テーブル名] ORDER BY [ソート対象列名] DESC;

DESC:降順
→大きい順に並べる(値が降りてくる)

ASC:昇順
→小さい順に並べる(値が昇っていく)


複数の列をキーとしてソートする場合は、

SELECT * FROM [テーブル名] ORDER BY [ソート対象列名1] DESC , [ソート対象列名2] DESC;

と、それぞれの列名に対して昇順、降順を書く。

参考URL
d.hatena.ne.jp

ログインシェルを書く

パスワードをコピペしたり覚える必要がない

ここ半年ほどでシェルコマンドには慣れてきましたが、
じつはシェルスクリプトは組んでいませんでした。

そこで、いままでコマンドを保存して使っていたところを、
順次シェルスクリプトに置き換えていくことにしました。

たとえばログイン時のコマンドをシェルスクリプトにすると、
パスワードを入力してEnterを押す手間が省けます。

タイポを乗り越えたら成功

結果として、いままで使っていたコマンドをほぼそのまま実行するだけ。

しかしコピペのタイミングでなぜかSSHの接続先IPアドレスが間違えていて、
原因がわからないままコマンドを弄っていた。そこが治ったら問題なかった・・・。

jsonをcsvに変換する方法

csvkitを使う

qiita.com

y0m0r.hateblo.jp


整形する

in2csv -f json {ファイル名.json}
で叩いてみると、jsonの形式がおかしいとエラーが出たので、
単純なjsonを作成しcsvに変換してみて見比べた。

すると最初と最後を[]で囲むのと、
レコードごとに「,」で区切るのが抜けていた。

それらを一括置換で追加するとうまくcsvになった。

Excelで開いてもらう場合は文字化けを考慮したり。

UTF-8でできたcsvを単純にExcelで開くと、日本語部分が文字化けするので、
対応方法が2種類ある。

Excelで読み込むときにエンコードを指定する。
csvファイル自体のエンコードを変えておく。

前者は読み込む項目の多さでとても重かったので、
おとなしく後者で「xlsx形式(Windows, DOS)」と指定をした。

 一応参考
global-wing.com

課題

pythonの機能を利用したcsvkitだが、in2csvの他にも
csvlook、csvcutなど、csvを利用するうえで使いやすそうなコマンドがたくさんあった。
そこを少し理解したい。
jsoncsvcsv→xlsx、xmlcsvと、変換はなかなか奥が深い。
そして文字コード、改行コードが理解必須。文字コードについて勉強したい。

catコマンドの使い方(復習)

名前は concatenate and print files

cat -- concatenate and print files

concatenateは「連結する」
連結してファイルを表示するコマンド?
表示だけじゃなかったん?

オプションは [-benstuv]

cat [-benstuv] [file ...]

-b 行番号をつける

-b Number the non-blank output lines, starting at 1.

1 CAT(1) BSD General Commands Manual CAT(1)

2 NNAAMMEE
3 ccaatt -- concatenate and print files

4 SSYYNNOOPPSSIISS
5 ccaatt [--bbeennssttuuvv] [_f_i_l_e _._._.]

-e non-printing charactersを表示する。行末に$をつける。

-e Display non-printing characters (see the -v option), and display
a dollar sign (`$') at the end of each line.

$
CAT(1) BSD General Commands Manual CAT(1)$
$
N^HNA^HAM^HME^HE$
c^Hca^Hat^Ht -- concatenate and print files$

NAMEとか一文字ずつなんか囲まれてる・・・。
col -b でこれを取り除いてたのか。


-n 出力行の行番号を表示する

-n Number the output lines, starting at 1.

1
2 CAT(1) BSD General Commands Manual CAT(1)
3
4 NNAAMMEE
5 ccaatt -- concatenate and print files
6

cat -b は、non-blankの出力行のみ、-nは出力行すべての、
行番号を表示する。
たしかに-nのほうが番号にふさわしい。

-s 空白行を整理する

-s Squeeze multiple adjacent empty lines, causing the output to be
single spaced.

Squeezeは「絞る」、adjacentは「隣接」、causingは「(結果を生み出す)原因」、
複数の空白行があるとき、それを1行だけに絞って表示する。
空白行が多くて見辛いときは良いかも。

-t non-printing charactersを表示する。タブは~Iで表示する。

-t Display non-printing characters (see the -v option), and display
tab characters as `^I'.

-u出力のバッファをdisableにする

-u Disable output buffering.

よくわからん

-v non-printing charactersを表示する。いくつか表示されるものが他と違う。

-v Display non-printing characters so they are visible. Control
characters print as `^X' for control-X; the delete character
(octal 0177) prints as `^?'. Non-ASCII characters (with the high
bit set) are printed as `M-' (for meta) followed by the character
for the low 7 bits.