1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Apacheのマルチインスタンス稼働

Last updated at Posted at 2023-03-09

はじめに

Webサーバを複数建てたいけど物理的なサーバを幾つも用意したくない
Apacheのマルチインスタンス化で解決すべ
ユニットファイルその他コピーしてどうにかならんか→なった
他のプロセスにも応用できそうなので備忘録
似たようなことやってるブログあったから(参考文献参照)Ubuntu22.10でやってみた
数日前に投稿したやつの改訂版

管理コマンド作成

cd /usr/sbin/
cp apache2ctl apache3ctl
ln -s apache3ctl apachectl3
cp apache2 apache3

apache3ctlを開いて各行のapache2をapache3、apache2ctlをapache3ctlに書き換え(修正箇所多すぎるので省略)
sedでもいいだろうけどなんか怖いから僕は手動変更

モジュール設定変更

cdしたついでにやっとく

cp a2enmod a3enmod
ln -s a3enmod a3enconf

a3enmodの$basenameを以下の通り編集
このとき先程と同様に各行のapache2をapache3に書き換え
sedでもいいだろうけど(ry

/usr/sbin/a3enmod
$basename =~ /^a3(en|dis)(mod|site|conf)((?:-.+)?)$/

この後作成するユニットファイルにさっき貼ったシンボリックリンクapachectl3を参照させる

ユニットファイル作成

cp -a /lib/systemd/system/apache2.service /etc/systemd/system/apache3.service

ExecStartを書き換え

/etc/systemd/system/apache3.service
ExecStart=/usr/sbin/apachectl3 start
ExecStop=/usr/sbin/apachectl3 graceful-stop
ExecReload=/usr/sbin/apachectl3 graceful

続いてメインの設定ファイルを配置する/etc/apache3等を作っていく

各種ファイル複製

環境によって違うかもしれんけどこの辺のコピー漏れとかあったらコメントで指摘してちょ

cp -a /etc/apache2 /etc/apache3
cp -r /run/apache2 /run/apache3
cp -r /run/lock/apache2 /run/lock/apache3
cp -r /usr/lib/apache2 /usr/lib/apache3
cp /usr/share/bash-completion/completions/a2enconf /usr/share/bash-completion/completions/a3enconf
cp -r /usr/share/doc/apache2 /usr/share/doc/apache3
cp -r /var/lib/apache2 /var/lib/apache3
cp -r /var/log/apache2 /var/log/apache3
cp /etc/init.d/apache2 /etc/init.d/apache3

各種ファイル編集

/etc/init.d/apache3と環境変数ファイル(/etc/apache3/envvars)は編集箇所多すぎるので省略
sedでも(ry
他は以下の通り

/etc/apache3/apache2.conf
ServerRoot "/etc/apache3"
/etc/apache3/ports.conf
Listen 8080
/usr/share/bash-completion/completions/a3enconf
command ls /etc/apache3/$1 2>/dev/null

リロード

systemctl daemon-reload

apache2とapache3起動した後にss叩いてプロセスID分かれてれば成功

参考文献

https://natswell.com/techcolumn/2012/08/23/apacheを複数のプロセスで起動する方法/
https://tech-lab.sios.jp/archives/12738
https://neil-sk.hatenadiary.org/entry/20110602/1307024490

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?