Manual BPM Counter

*1 Ubuntuを基本に作成していますが、sudoコマンドは省いています。
*2 CentOSの場合は apt ではなく yum を使用して各ソフトウェアをインストールして下さい

【時刻同期設定】- crontab登録 –
root@linux: ~ # crontab -e
0 1 * * * /usr/sbin/ntpdate ntp1.jst.mfeed.ad.jp > /var/log/ntpdate.log 2>&1

【Network】- IP / MAC Address 確認 –
root@linux: ~ # ip address

【SSH】- OpenSSH –
# インストール
root@linux: ~ # apt install openssh-server

# 初期設定
root@linux: ~ # vi /etc/ssh/sshd_config
# 28行目:noに変更してrootログイン禁止
# デフォルトの「without-password」は rootログイン許可だが、鍵認証が必要な設定
PermitRootLogin no

# 再起動
root@linux: ~ # systemctl restart sshd.service

【DNS】- Bind9 –
# インストール
root@linux: ~ # apt install bind9 bind9utils

# 初期設定
root@linux: ~ # vi /etc/bind/named.conf
# コメント化
# include "/etc/bind/named.conf.default-zones";
# 追記
include "/etc/bind/named.conf.internal-zones";
include "/etc/bind/named.conf.external-zones";

# 内部向けの定義を作成
root@linux: ~ # vi /etc/bind/named.conf.internal-zones
view "internal"
{
  # 指定範囲内のホストが内部向けの定義を参照
  match-clients
  {
    localhost;
    192.168.1.0/24;
  };
  # 内部向け正引き情報を定義
  zone "server.world"
  {
    type master;
    file "/etc/bind/internal/int.server.world.db";
  };
  # 内部向け逆引き情報を定義 *注
  zone "1.168.192.in-addr.arpa"
  {
    type master;
    file "/etc/bind/internal/int.192.168.1.db";
    allow-update { none; };
  };
}

# 外部向けの定義を作成
root@linux: ~ # vi /etc/bind/named.conf.external-zones
view "external"
{
  # 内部向け範囲以外のホストが参照
  match-clients { any; };
  # 問い合わせは全て許可
  allow-query { any; };
  # 再帰検索禁止
  recursion no;
  # 外部向け正引き情報を定義
  zone "server.world"
  {
    type master;
    file "/etc/bind/external/ext.server.world.db";
  };
  # 外部向け逆引き情報を定義 *注
  zone "80.0.16.172.in-addr.arpa"
  {
    type master;
    file "/etc/bind/external/172.16.0.80.db";
  };
};

# *注:「*.*.*.*.in-addr.arpa」と指定するところはネットワークアドレスを逆にしたものを入力
192.168.1.0/24 の場合
ネットワークアドレス ⇒ 192.168.1.0
ネットワークの範囲 ⇒ 192.168.1.0 - 192.168.1.255
指定方法 ⇒ 1.168.192.in-addr.arpa

172.16.0.80/29 の場合
ネットワークアドレス⇒ 172.16.0.80
ネットワークの範囲 ⇒ 172.16.0.80 - 172.16.0.87
指定方法 ⇒ 80.0.16.172.in-addr.arpa

root@linux: ~ # /etc/init.d/bind9 restart

【www】- apache2 –
# リポジトリ追加
root@linux: ~ # add-apt-repository ppa:ondrej/apache2
# 最新Ver確認、インストール
root@linux: ~ # apt show apache2
root@linux: ~ # apt install apache2

# 初期設定
root@linux: ~ # vi /etc/apache2/apache2.conf
# 70行目:サーバー名追記
ServerName www.srv.world

# コンフィグ設定
root@linux: ~ # vi /etc/apache2/conf-available/security.conf
# 26行目:変更
ServerTokens Prod
# 37行目:変更
ServerSignature Off
# コンフィグ設定無効
root@linux: ~ # a2disconf {設定ファイル名}
# コンフィグ設定有効化
root@linux: ~ # a2ensite {設定ファイル名}

# モジュール設定
root@linux: ~ # vi /etc/apache2/mods-available/dir.conf
# 2行目:ディレクトリ名のみでアクセスできるファイル名を設定
DirectoryIndex index.html index.cgi index.php
# モジュール設定無効
root@linux: ~ # a2dismod {設定ファイル名}
# モジュール設定有効化
root@linux: ~ # a2enmod {設定ファイル名}

# サイト設定 ~詳細略~
root@linux: ~ # cp /etc/apache2/sites-available/default.conf /etc/apache2/sites-available/{設定ファイル名}.conf
# 初期サイト設定無効
root@linux: ~ # a2dissite default
# サイト設定有効化
root@linux: ~ # a2ensite {設定ファイル名}


# 再起動
root@linux: ~ # systemctl restart apache2.service

# PHP インストール
root@linux: ~ # apt install php php-cgi libapache2-mod-php php-common php-pear php-mbstring

# Apache2に設定反映
root@linux: ~ # a2enconf php7.*-cgi
Enabling conf php7.*-cgi.
To activate the new configuration, you need to run:
  service apache2 reload

# iniファイル修正
root@linux: ~ # vi /etc/php/7.*/apache2/php.ini
# 912行目:コメント解除しタイムゾーン設定
date.timezone = "Asia/Tokyo"

root@linux: ~ # systemctl restart apache2.service

# Basic認証 パスワード設定
root@linux: ~ # htpasswd -C /etc/apache2/.htpasswd [username]
[-C]は初回のみ(ファイルの新規作成)。[-C]を外すと追記。

【www】- Let’s Encrypt –
# インストール
root@linux: ~ # apt update
root@linux: ~ # apt install certbot python-certbot-apache

# 証明書発行
root@linux: ~ # certbot --apache
# 以降、指示に従って実行

# 複数ドメイン対応の場合
root@linux: ~ # certbot certonly --webroot -w %ドメインのルートパス% -d %ドメイン名% -w %ドメインへのルートパス% -d %ドメイン名% ・・・

# 証明書更新
root@linux: ~ # certbot renew

【DataBase】- MySQL –
root@linux: ~ # apt install mysql-server
root@linux: ~ # vi /etc/mysql/my.cnf
# サーバー側、クライアント側の文字コードを utf8 にセット(追記)
[mysqld]
character-set-server = utf8
[client]
default-character-set = utf8
# 外部接続を許可する場合、bind-address を追加
bind-address = *

# 再起動
root@linux: ~ # systemctl restart mysql

# 変更されているか確認
root@linux: ~ # mysql -u root -p
mysql> show variables like 'chara%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+

# rootパスワード変更
root@linux: ~ # mysql -u root -p
mysql> update user set authentication_string=password('{新規パスワード}') where user='root';

# ユーザー権限変更
mysql> grant {権限} on {対象Database}.* to {ユーザー名}@localhost identified by '{パスワード}';

【VNC】- x11vnc –
# インストール
root@linux: ~ # apt install x11vnc

# パスワード設定
root@linux: ~ # x11vnc -storepasswd /etc/.x11vnc.passwd

# Virtual Display 設定追加
root@linux: ~ # vi /etc/mdm/Init/Default
# 追記
# Virtual Display
xrandr --newmode "1440x900" 106.50 1440 1528 1672 1904 900 903 909 934 -hsync +vsync
xrandr --addmode VIRTUAL1 "1440x900"
xrandr --output VIRTUAL1 --mode "1440x900"

# VNC起動
/usr/bin/x11vnc -display :0 -xkb -cursor arrow -noxrecord -noxfixes -noxdamage -rfbauth /etc/.x11vnc.passwd -shared -forever -bg -rfbport 5900 -o /var/log/x11vnc.log

# VNC終了
/usr/bin/x11vnc -R stop

[lightdm]
# インストール
root@linux: ~ # apt install lightdm

# VNC起動
/usr/bin/x11vnc -auth /var/run/lightdm/root/:0 -xkb -cursor arrow -noxrecord -noxfixes -noxdamage -rfbauth /etc/.x11vnc.passwd -shared -forever -bg -rfbport 5900 -o /var/log/x11vnc.log

【File】- samba –
root@linux: ~ # apt install samba
root@linux: ~ # mkdir /mnt/share
root@linux: ~ # chmod 777 /mnt/share
root@linux: ~ # vi /etc/samba/smb.conf
# 25行目:以下2行追記
unix charset = UTF-8
dos charset = CP932

# 30行目:必要があれば変更(Windows側に合わせる)
workgroup = WORKGROUP

# 51行目:コメント解除しアクセス許可IP追記
interfaces = 127.0.0.0/8 192.168.1.0/24

# 58行目:コメント解除
bind interfaces only = yes

# 122行目:コメント解除
map to guest = Bad User

# 最終行に以下7行追記
[share] # 作成した共有フォルダ名
   path = /mnt/share      # 共有フォルダのパス指定
   writable = yes         # 書き込みOK
   guest ok = yes         # ゲストユーザーOK
   guest only = yes       # 全てゲストとして扱う
   create mode = 0764     # ファイル作成時の権限設定
   directory mode = 0775  # ディレクトリ作成時の権限設定
   share modes = yes

root@linux: ~ # systemctl restart smbd

# ネットワークドライブをマウント
root@linux: ~ # mount -t cifs //ホスト名/ディレクトリ名 /mnt/ディレクトリ名 -o username="ユーザー名",password="パスワード"

# アンマウント
root@linux: ~ # umount /mnt/ディレクトリ名

【Proxy】- Squid –
root@linux: ~ # apt install squid3
root@linux: ~ # vi /etc/squid/squid.conf
# 989行目:追記(内部用ACL定義)
acl lan src 192.168.1.0/24

# 1172行目:追記(内部用ACL設定)
http_access allow lan

# 1599行目:Port変更
http_port 8080

# 5157行目:以下4行追記(匿名サーバー化)
request_header_access Referer deny all
request_header_access X-Forwarded-For deny all
request_header_access Via deny all
request_header_access Cache-Control deny all

# 5508行目:追記(ホスト名定義)
visible_hostname proxy.domain.com

# 7622行目:追記(IP非表示)
forwarded_for off

root@linux: ~ # systemctl restart squid

【仮想化】- KVM –
# KVM をインストール
root@linux: ~ # apt install -y qemu-kvm libvirt-bin virtinst bridge-utils libosinfo-bin libguestfs-tools virt-top

# 仮想マシン管理ツール(GUI)をインストール
root@linux: ~ # apt install -y virt-manager qemu-system

【WindowsAPI】- WineHQ –
# If your system is 64 bit, enable 32 bit architecture (if you haven't already)
root@linux: ~ # dpkg --add-architecture i386

# Add the repository
root@linux: ~ # wget -nc https://dl.winehq.org/wine-builds/Release.key
root@linux: ~ # apt-key add Release.key
root@linux: ~ # apt-add-repository https://dl.winehq.org/wine-builds/ubuntu/(*)
# * On Linux Mint 17.x, the last line should be the following
root@linux: ~ # apt-add-repository 'deb https://dl.winehq.org/wine-builds/ubuntu/ trusty main'
# * On Linux Mint 18.x, the last line should be the following
root@linux: ~ # apt-add-repository 'deb https://dl.winehq.org/wine-builds/ubuntu/ xenial main'
# * On Linux Mint 19.x, the last line should be the following
root@linux: ~ # apt-add-repository 'deb https://dl.winehq.org/wine-builds/ubuntu/ bionic main'

# Update packages
root@linux: ~ # apt update

# Then install one of the following packages
root@linux: ~ # apt install --install-recommends winehq-stable

【JavaScript】- Nodejs & forever –
# Nodejs をインストール
root@linux: ~ # apt install nodejs npm

# n package を導入
root@linux: ~ # npm cache clean
root@linux: ~ # npm install n -g

# n package から Nodejs の最新版をインストール
root@linux: ~ # n stable
# シンボリックリンクを作成
root@linux: ~ # ln -sf /usr/local/bin/node /usr/bin/node

# forever を npm からインストール
root@linux: ~ # npm install forever

# discord.js を npm からインストール
root@linux: ~ # npm install discord.js

# apt でインストールした古いバージョンを削除
root@linux: ~ # apt purge  nodejs npm

【一括変更】- find & xargs –
# ファイルやディレクトリに対して一括操作を行う
root@linux: ~ # find -name * -type f(or d) -print | xargs chmod(or chown) 664