自己流マニュアル

はじめに

このマニュアルは今後自分の参考になりそうであったり、詰まったときの解決方法をまとめたものです。ただし調べながら書いたものであり、これが正しい解決方法とは限りません。また誤った解決方法を書いている可能性もあります。
また、バージョンごとに記載されているものがありますが、これはバージョン特有のものを意味するものではなく、単にその時に筆者が利用していたバージョンに過ぎません。すなわちバージョンが変わったから表記が変わったのではなく、単に私の利用方法が変わっただけであることも多々あるということです。 ここには Debian 系用のものと RedHat 系用のものが混在しています。
ここに記載されている内容を実行して、利用者様の環境に損害を与えても、筆者は責任を取ることはできません。あくまで参考程度にお願いします。

Linux

timezone の変更

timedatectl set-timezone Asia/Tokyo

スワップ領域の作成

dd if=/dev/zero of=/swapfile bs=1M count=2048
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
vi /etc/fstab
"/swapfile swap swap defaults 0 0"

cURL

curl をソースから / にインストールした場合 libcurl が複数となり、yum が実行できない問題が発生する。よって curl-devel を用いるか、インストールする場合はディレクトリを /opt/curl などに変更すること。

configure

./configure --prefix=/opt/curl-7.78.0 --enable-http --enable-ftp --enable-ipv6 --enable-cookies --enable-http-auth --enable-doh --with-openssl=/opt/openssl

結果で HTTP2 が有効となっていることを確認すること。

gpg

sora@home-ubuntu:/opt/src$ gpg --recv-keys 520A9993A1C052F8
gpg: Note: '--keyserver' is not considered an option
gpg: "--keyserver" not a key ID: skipping
gpg: "hkps://keyserverubuntu.com" not a key ID: skipping
gpg: key 520A9993A1C052F8: new key but contains no user ID - skipped
gpg: Total number processed: 1
gpg:           w/o user IDs: 1

こうなった場合はどこか別の keyserver を指定してやればよい。

  • keyserver.ubuntu.com
  • keys.gnupg.net

など。

gpg --keyserver keyserver.ubuntu.com --recv-keys 520A9993A1C052F8

※keyserverをrecv-keysより前に指定すること

zlib

./configure --prefix=/usr/local

–shared などのオプションは不要。

libzip

libzip
└cmake
 └gcc
  ├gmp
  │└m4
  ├mpfr
  └mpc

何かしらのインストール直後
基本的に何か(gmp mpfr mpc gcc 等)をインストールしたら ldconfig を実行すべき。

libxml2

Python.h が無いと怒られるので python-devel を yum でインストールする。 pythonのソースインストールはバージョンの問題で色々面倒なので推奨しない。

gcc

./configure --with-gmp=/usr/local --with-mpfr=/usr/local --with-mpc=/usr/local --disable-multilib

OpenSSL

configure

必ず –prefix=/opt/openssl を指定する。
/usr/local でもよいが、依存関係がおかしくなるのかたまに色々なものが利用できなくなり、結局 OS を再インストールするはめになった。

make test

yum install perl-Test-Simple

ldconfig

./openssl: /usr/lib/x86_64-linux-gnu/libssl.so.1.1: version `OPENSSL_1_1_1' not found (required by ./openssl)
./openssl: /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1: version `OPENSSL_1_1_1' not found (required by ./openssl)

libssl.so.1.1 や libcrypto.so.1.1 は /usr/local/lib64 に存在しているが、パスが通っていない。

echo "/usr/local/lib" > /etc/ld.so.conf.d/usr-local-lib.conf
echo "/usr/local/lib64" > /etc/ld.so.conf.d/usr-local-lib64.conf
ldconfig

OpenSSH

configure

8.6p1

./configure --prefix=/opt/openssh-8.6p1 --with-ssl-dir=/opt/openssl --with-ssl-engine

8.0p1

./configure --with-zlib=/usr/local --with-ssl-dir=/usr/local/ssl --with-ssl-engine

エラーケース1

make install にて

recipe for target 'check-config' failed
Privilege separation user sshd does not exist
Makefile:328: recipe for target 'check-config' failed
make: [check-config] Error 255 (無視されました)

解決方法
エラーに記載されている通り sshd というユーザを作成する。
以下はホームディレクトリを作らず、ユーザ名と同じグループを作成し、ログインは

useradd --no-create-home --user-group --shell /bin/false sshd

libgd

https://qiita.com/Soora_JP/private/1a322392006e003a4e96

nsd

chown -R nsd:nsd /usr/local/var/db/nsd

nghttp2

/usr/localのopensslを利用するには、pkgconfigを設定する。

configure

PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/lib64/pkgconfig:/opt/curl/lib/pkgconfig \
./configure --with-libxml2=/usr/local --with-systemd

エラーケース1

configure: error: in `/usr/local/src/nghttp2-1.43.0':
configure: error:
  Could not link test program to Python. Maybe the main Python library has been
  installed in some non-standard library path. If so, pass it to configure,
  via the LIBS environment variable.
  Example: ./configure LIBS="-L/usr/non-standard-path/python/lib"
  ============================================================================
   ERROR!
   You probably have to install the development version of the Python package
   for your distribution.  The exact name of this package varies among them.
  ============================================================================

解決方法

apt install python3-dev

Apache

apr と apr-util

それぞれダウンロードし、srclib ディレクトリの中に apr と apr-util として解凍してビルドする。
もし先に apr-devel や apr-util-devel を yum でインストールしていた場合は削除するようにする。

mpm

PHP をモジュール版で利用する場合は prefork を、fpm で利用する場合は woeker もしくは event をそれぞれ –with-mpm= で指定する。
ただし HTTP2 を利用する場合は mpm は event でなければならない。

configure

./configure --prefix=/opt/httpd-2.4.48 --enable-proxy --enable-ssl --enable-http2 --enable-proxy-http2 --enable-systemd --enable-vhost-alias --enable-rewrite --with-ssl=/opt/openssl --with-mpm=event --with-libcurl=/opt/curl --with-included-apr
./configure --prefix=/opt/httpd-2.4.46 --enable-proxy --enable-ssl --enable-http2 --enable-proxy-http2 --enable-systemd --enable-vhost-alias --enable-rewrite --with-libxml2=/usr/local --with-ssl=/usr/local --with-nghttp2=/usr/local --with-curl=/opt/curl --with-mpm=event

エラーケース1

configure にて

checking for pcre-config... false
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

解決方法

apt install libpcre3-dev

libpcre2-dev ではないので注意

エラーケース2

configure にて

checking for nghttp2... checking for user-provided nghttp2 base directory... none
checking for nghttp2 version >= 1.2.1... FAILED
configure: WARNING: nghttp2 version is too old
no
checking whether to enable mod_http2... configure: error: mod_http2 has been requested but can not be built due to prerequisite failures

解決方法

apt install libnghttp2-dev

バージョンが古いとか書かれているが、騙されてはいけない。
ソースコードからビルドする必要はない。

nginx

configure

./configure --prefix=/opt/nginx-1.17.6 --with-http_ssl_module --with-http_v2_module --with-openssl=/usr/local/src/openssl-OpenSSL_1_1_1-stable --with-cc=/usr/local/bin/gcc --with-cpp=/usr/local/bin/gcc-c++

–with-openssl や –with-zlib 、 –with-pcre で指定するのは未コンパイルのソースが入っているディレクトリ。恐らくそのディレクトリの中でコンパイルされるので別で用意したほうが良い。というより少なくとも既にインストールしたディレクトリだと make distclean が実行されるため、インストールの際の関連データは上書きされてしまう。

dhparam

/opt/nginx/ssl/dhparam を生成する。

/usr/local/bin/openssl dhparam -out dhparam.pem 2048

oniguruma

autoconf と automake(多分) が必要。
epel repos を利用することで oniguruma-devel が利用できる。

PHP

Apache の所でも書いたが Apache で HTTP2 を使うためには fpm である必要があり、モジュール版は利用できない。

configure

8.0.*

PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/lib64/pkgconfig:/opt/openssl/lib/pkgconfig:/opt/curl/lib/pkgconfig \
./configure --prefix=/opt/php-8.0.* --enable-fpm --with-fpm-systemd --with-openssl=/opt/openssl --without-sqlite3 --with-zlib --with-curl=/opt/curl --with-ffi --with-openssl-dir=/opt/openssl --enable-gd --with-external-gd --with-webp --with-jpeg --with-freetype --enable-mbstring --with-mysqli --with-pdo-mysql --enable-sockets --with-zip

依存ライブラリ(ubuntu 20.04)

apt install pkg-config libsystemd-dev libxml2-dev libcurl4-openssl-dev libffi-dev libgd-dev libonig-dev libsqlite3-dev libzip-dev 

7.4.*

PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/lib64/pkgconfig:/opt/curl/lib/pkgconfig \
./configure --prefix=/opt/php-7.4.3 --enable-fpm --with-openssl=/usr/local --without-sqlite3 --with-zlib=/usr/local --with-curl --with-ffi --with-openssl-dir=/usr/local --enable-gd --with-external-gd --with-webp --with-jpeg --with-xpm --with-freetype --enable-mbstring --with-mysqli --with-pdo-mysql --with-zlib-dir=/usr/local --with-zip --enable-sockets

7.3.*

./configure --with-openssl=/usr/local/ --with-curl --with-pdo-mysql --with-mysqli --with-zlib --enable-mbstring

注意

–with-mysql は 7.3 では既に無効
–with-pdo-mysql と –with-mysqli はパラメータ mysqlnd を渡すと良い。

–with-apxs2=/opt/httpd/bin/apxs
Apache でモジュール版として利用する場合に必要

–enable-fpm
FastCGI で動くようにする。(nginx用)

–with-gd
–with-freetype-dir
wordpress の SiteGuard での画像認証
yum で php-gd と libpng-devel と ? のインストール

–enable-sockets
composer で linecorp/line-bot-sdk をインストールする際に要求された。

–enable-zip
composer で larabel/installer をインストールする際に要求された。

make install 後、opensslが利用できない場合は、libtools をインストールし

libtool --finish /usr/local/src/php-7.3.6.cp/libs

を実行する。

openssl のライブラリが読み込めない時

--with-libdir=lib64

Postfix

Install

PostfixをTLSとSASLありでビルドする
https://note.soora.jp/post/56

yum で libdb-devel をインストールしてから tar.gz を展開したディレクトリの中で make を実行。

yum install libdb-devel
cd /opt/src/postfix-*.*.*/
make

vmail ユーザの作成

groupadd -g 5000 vmail
useradd -m -d /var/spool/vmailbox -s /bin/false -u 5000 -g vmail vmail

vmailbox ディレクトリの作成

mkdir /var/spool/vmailbox
chmod -R 2770 /var/spool/vmailbox

エラーケース1

warning: maildir access problem for UID/GID=5000/5000: create maildir file /var/spool/vmailbox/example.com/username/tmp/*****: Permission denied

解決方法

SELinux の影響。

setenforce 0

で一時的に無効化できる。(厳密には無効化ではなく、チェックはするが処理は通す Permissive という状態らしい。) 永続的にその状態にするには

vi /etc/selinux/config
SELINUX=enforcing

ただし、SELinux 本来の目的から外れているので、これを行うときはよく考える事。

Recieved ヘッダのローカルIPを非表示にする

header_checks = regexp:/etc/postfix/header_checks
/^Received:.*192\.168\..*/ IGNORE
/^Received:.*127\.0\.0\.1.*/ IGNORE

↑改良の余地、かなりあり

Dovecot

エラーケース1

make check にて

CLIENT: Panic: file smtp-client-connection.c: line 1309 
(smtp_client_connection_established): assertion failed: 
(!conn->connect_succeeded)
.
.
.

解決方法

ディレクトリを削除して、もう一度 configure からやり直す。 (make clean と make distclean でも大丈夫?)

エラーケース2

no such files or directories

解決方法

dovecot ユーザで実行する

tar zxf dovecot-*.*.*.*.tar.gz
chown -R dovecot:dovecot dovecot-*.*.*.*
su dovecot
cd dovecot-*.*.*.*
./configure --with-ssldir=/usr/local/ssl
make
make check
exit # root
make install

ClamAV

./configure --prefix=/opt/clamav-0.103.0 --with-openssl=/usr/local --with-libcurl=/opt/curl --enable-milter

エラーケース1

configure: error: Cannot find libmilter

解決方法

sendmail をソースからビルドする以外方法がないよう。

wget [sendmail.*.*.*.tar.gz]
...
cd libmilter
make
make check
make install

certbot

yum install epel-release
yum install certbot

phpMyAdmin

HTTPSの不一致

config.sample.inc.phpconfig.inc.php にコピーして……

$_SERVER['HTTPS'] = 'on';

を先頭に書き足す。

WordPress

https で CSS や JS 、画像が正常に表示されない場合

wp-config.php の冒頭に

define('FORCE_SSL_LOGIN', true);
define('FORCE_SSL_ADMIN', true);
$_SERVER['HTTPS'] = 'on';

更新などに ftp アカウントを求められる場合

chown -R httpd:httpd /var/www/[dir]

セキュリティ上あまりよろしくない。

番外

network:
        version: 2
        renderer: networkd
        ethernets:
                enp1s0:
                        dhcp4: true
                        dhcp6: true
                        addresses:
                                - 192.168.0.3/24
                                - fe80::192:168:0:3/64

コメントを残す