2
3

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 5 years have passed since last update.

CentOSで種々のサーバを構築するドキュメント

Last updated at Posted at 2019-11-10

目次

  • Apacheの構築
  • opensslでhttps化
  • Postfixの構築 (途中)
  • Dovecotの構築 (途中)
  • Bindの構築 (途中)
  • Tomcatの構築 (途中)
  • Struts2の構築 (途中)
  • WordPressの構築 (途中)
  • PostgreSQLの構築
  • Oracle WebLogicの構築 (途中)
  • Squidの構築 (途中)
  • syslogの構築 (途中)

前提

  • OSはCentOS 7 以降を想定

  • 構築環境はVMware Workstaion ProでのVM環境

  • 外部に公開とかするわけではないので,本当にざっと構築するだけ

  • ローカル環境なので,すべてrootユーザで実行※

    ※本番環境では推奨しません.あくまでもこれは,私の実行環境の話です.

背景

本記事を投稿しようと思ったきっかけは2つあります.

  • いつもQiitaはじめ,インターネットの方々にお世話になっているので,自分のような人が助かるような記事を投稿したい,という気持ち
  • 技術者として,そして忘れん坊な自分のために実際に構築した時の記録を残しておきたい

以上のようなモチベーションから始めました.少しずつサーバのほうを完成させ,本記事も完成させます.

※一気に完成させようとすると,いつ公開できるかわからないので,作成途中ながら少しずつ更新していきます※
内容は今後も更新予定です.

はじめに

おまじないを実行します.

実行コマンド
# yum -y update
# yum -y upgrade

Apacheの構築

初めに,Apacheをインストールします.

実行コマンド
# yum -y install httpd

次に,Apacheを起動します.

実行コマンド
# systemctl start httpd

起動しているかどうかステータスを確認します.

実行コマンド
# systemctl status httpd

次のようにactive (running)と表示されれば,起動しています.

実行結果
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since 水 2019-06-19 06:31:47 JST; 17min ago

そして,ApacheをOSの電源を入れたら自動的に起動するように設定します.

実行コマンド
# systemctl enable httpd

最後に,fiewallの設定をしてアクセスできるようにします.

実行コマンド
# firewall-cmd --parmanent --add-service=http

以上で,Apacheの構築は完了です.
Webブラウザで"http://[VMのIPアドレス]"と入力し,以下のようなページが表示されれば,ちゃんとアクセスできています.

centos_test.PNG

opensslでhttpsにする

httpsにするために必要な,mod_sslをインストールします.

実行コマンド
# yum -y install mod_ssl

次に,opensslを使ってTLS通信に必要な秘密鍵とサーバ証明書,その元となる証明書署名要求を作成します.今回は構築を目指すため,いわゆるオレオレ証明書を作成します.

まずは,秘密鍵を作成します.

実行コマンド
# openssl genrsa 2048 > server.key

次に,証明書署名要求を作成します.

実行コマンド
# openssl req -new -key server.key > server.csr

最後に,サーバ証明書を作成します.

実行コマンド
# openssl x509 -days 3650 -req -signkey server.key < server.csr > server.crt

これで,必要なものが用意できました.

次に,作成したファイルの設置場所を作成します.
server.crtは,/etc/httpd/conf/ssl.crtに,server.keyは/etc/httpd/conf/ssl.keyディレクトリにそれぞれ設置します.

実行コマンド
# mkdir /etc/httpd/conf/ssl.crt
# mkdir /etc/httpd/conf/ssl.key

次は,設定ファイルに秘密鍵とサーバ証明書の場所を記述します.以下のコマンドで,設定ファイルを編集してください.

実行コマンド
# vim /etc/httpd/conf.d/ssl.conf

設定ファイルを以下のように編集します.
コマンドモードで / を入力した後に所定の文字列を入力すると検索できます.

ssl.conf
SSLCertificateFile /etc/httpd/conf/ssl.crt/server.crt
SSLCertificateKeyFile /etc/httpd/conf/ssl.key/server.key

そして,ファイルを設定ファイルに記載した場所に移動します.
server.csrは不要なので,削除しても構いません.

実行コマンド
# mv server.crt /etc/httpd/conf/ssl.crt/
# mv server.key /etc/httpd/conf/ssl.key/

次に,firewallで443ポートへのアクセスを許可しておきます.

実行コマンド
# firewall-cmd --parmanent --add-service=https
# firewall-cmd --reload

最後に,Apacheを再起動します.

実行コマンド
# systemctl restart httpd

Webブラウザで,"https://[VMのIPアドレス]"でアクセスして,ページが表示されればhttpsの構築は完了です.オレオレ証明書なので,httpsでも"Not secure"とGoogle Chrome上で表示されます.
※IPアドレスはマスクしてあります.

centos_test_https.PNG

Postfixの構築

実行コマンド
# yum -y install postfix
実行コマンド
# firewall-cmd --parmanent --add-service=smtp
# firewall-cmd --reload

/etc/postfix/main.cf ファイルの内容

私の環境で動作した際のファイルの設定は以下の通りです.
"#★add a configuration★" と記述されている次の行の設定をデフォルトから変更しています.

/etc/postfix/main.cf
queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
mail_owner = postfix
# ★add a configuration★
myhostname = [your mail server host name]
# ★add a configuration★
mydomain = [your domain name]
myorigin = $mydomain
inet_interfaces = all
inet_protocols = all
# ★add a configuration★
mydestination = [your mail server host name], $myhostname, localhost.$mydomain, localhost
unknown_local_recipient_reject_code = 550
# ★add a configuration★
mynetworks = 127.0.0.0/8, [your IP Address]
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
# ★add a configuration★
home_mailbox = Maildir/
debug_peer_level = 2
debugger_command =
	 PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
	 ddd $daemon_directory/$process_name $process_id & sleep 5
sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/share/man
sample_directory = /usr/share/doc/postfix-2.10.1/samples
readme_directory = /usr/share/doc/postfix-2.10.1/README_FILES

Dovecotの構築

実行コマンド
# yum -y install dovecot

Bindの構築

実行コマンド
# yum -y install bind

Tomcatの構築

Struts2の構築

WordPressの構築

PostgreSQLの構築

まず初めに,PostgreSQLをインストールします.

実行コマンド
# yum -y install postgresql-server

次に,データベースを初期化します.

実行コマンド
# postgresql-setup initdb

サービスを起動します.

実行コマンド
# systemctl start postgresql

サービスが起動されたかを確認します.

実行コマンド
# systemctl status postgresql

firewallのポートを開放します.

実行コマンド
# firewall-cmd --add-service=postgresql --zone=public --permanent
# firewall-cmd --reload

postgres ユーザーに変更します.
※postgres ユーザーは,PostgreSQLをインストールした際に作成されます.

実行コマンド
# su - postgres

データベースにアクセスします.

実行コマンド
# psql

お遊び用のテーブルを作成します.

実行コマンド
postgres=# \i members.sql

作成したテーブルの中身を確認します.

実行コマンド
postgres=# select * from members;
実行結果
 id  |  name   | height | gender 
-----+---------+--------+--------
 101 | Algo    |    170 | M
 102 | Bianchi |    170 | F
 103 | Ceaser  |    163 | M
 104 | Dangon  |    175 | M
 105 | Elen    |    168 | M
 106 | Flan    |    158 | F
 107 | Gangan  |    165 | M
 108 | Han     |    150 | F
 109 | Ian     |    143 | F
 110 | Jan     |    175 | M
 111 | Kit     |    155 | F
 112 | Lolen   |    165 | M
 113 | Moon    |    150 | F
 114 | Nue     |    168 | M
 115 | Ox      |    150 | M
 116 | Peatan  |    155 | M
 117 | Quantum |    170 | M
 118 | Rex     |    190 | M
 119 | Satarn  |    190 | M
 120 | Tat     |    195 | M
 121 | Ute     |    152 | M
 122 | Violete |    152 | F
 123 | Wat     |    155 | M
 124 | Xeon    |    165 | M
 125 | Yean    |    151 | F
 126 | Zett    |    170 | M
(26 )

作成したテーブルのソースファイル

作成したテーブルのソースファイルの内容は下記の通りです.

members.sql
create table members (
      id integer     primary key
    , name text      not null
    , height integer not null
    , gender char(1) not null
);
insert into members(id, name, height, gender)
values (101, 'Algo',    170, 'M')
    , (102, 'Bianchi', 170, 'F')
    , (103, 'Ceaser' , 163, 'M')
    , (104, 'Dangon',  175, 'M')
    , (105, 'Elen',    168, 'M')
    , (106, 'Flan',    158, 'F')
    , (107, 'Gangan',  165, 'M')
    , (108, 'Han',     150, 'F')
    , (109, 'Ian',     143, 'F')
    , (110, 'Jan',     175, 'M')
    , (111, 'Kit',     155, 'F')
    , (112, 'Lolen',   165, 'M')
    , (113, 'Moon',    150, 'F')
    , (114, 'Nue',     168, 'M')
    , (115, 'Ox',      150, 'M')
    , (116, 'Peatan',  155, 'M')
    , (117, 'Quantum', 170, 'M')
    , (118, 'Rex',     190, 'M')
    , (119, 'Satarn',  190, 'M')
    , (120, 'Tat',     195, 'M')
    , (121, 'Ute',     152, 'M')
    , (122, 'Violete', 152, 'F')
    , (123, 'Wat',     155, 'M')
    , (124, 'Xeon',    165, 'M')
    , (125, 'Yean',    151, 'F')
    , (126, 'Zett',    170, 'M')
;

SQLコマンドを使ったデータベース操作等は,別の記事にて投稿予定です.

Oracle WebLogicの構築

Squidの構築

実行コマンド
# yum -y install squid

syslogの構築

参考文献

2
3
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
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?