X

ブログサーバー再構築 CentOS7.2(1511)

足の怪我でほとんど外に遊びにいけないので、

このブログを動かしているサーバーを再構築しました。

今回はハードウェア的な入れ替えは全くなく、

OS含むソフトウェア全般の総入れ替えです。

メインとなるLinuxOSはCentOS7.2(1511)

ミドルウェア周りはApache2.4、PHP7.0、MySQL5.7という組み合わせです。

Nginxを使っても良いしMariaDBを使っても良かったのですが、

近々仕事で使う環境に近い方が良いと思い、選びました。

入れ替え作業は、節目ごとにVMのスナップショットを撮りながら進めました。

いろいろ調べながら作業したので、だいぶ時間をかけましたが、

VMのスナップショットは本当に便利ですね。

失敗しても直前の工程に戻れるのはありがたいです。

作業手順

・基本パッケージインストール

yum update
yum groupinstall base
yum groupinstall network-tools

 

・ホストネーム記述

vi /etc/hostname

sshdの初期設定

vi /etc/ssh/sshd_config

# コメント解除(rootでのログインを許可しない)

PermitRootLogin no

# コメント解除(パスワード無しを許可しない)

PermitEmptyPasswords no

# 追記(sshでログイン可能なユーザをhogeのみにする)

AllowUsers hoge

systemctl restart sshd

・時刻

vi /etc/chrony.conf

#server 0.centos.pool.ntp.org iburst # コメントアウト

#server 1.centos.pool.ntp.org iburst # コメントアウト

#server 2.centos.pool.ntp.org iburst # コメントアウト

#server 3.centos.pool.ntp.org iburst # コメントアウト

#以下追記

server ntp1.jst.mfeed.ad.jp iburst

server ntp2.jst.mfeed.ad.jp iburst

server ntp3.jst.mfeed.ad.jp iburst

systemctl restart chronyd.service

systemctl enable chronyd.service


chronyc sources       # chronydの動作状況を調べられます。そのうち時刻が合うはずです。

・ハードウェアクロック

vi /etc/adjtime

#UTC # UTC等利用しないタイムゾーンがある場合削除

# 下記追記

LOCAL

SELinuxの停止

vi /etc/selinux/config

# 変更

SELINUX=disabled

vmware-toolsインストール

OS再起動

■外部リポジトリ登録

・外部リポジトリ達を登録(epelremi

#epelCentOS7標準リポジトリから入れられます。

yum install epel-release

#remi

wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

rpm -Uvh remi-release-7.rpm

以下のそれぞれenabled=0にする

/etc/yum.repos.d/epel.repo

/etc/yum.repos.d/remi.repo

・whoisインストール

yum --enablerepo=epel install jwhois

■ミドルウェア

Apache2.4

yum install httpd

httpd -v

Server version: Apache/2.4.6 (CentOS)

Server built:   Jul 18 2016 15:30:14

MySQL5.7

yum remove mysql*

wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm

rpm -ivs mysql57-community-release-el7-7.noarch.rpm

yum install mysql-community-devel

yum install mysql-community-server

vim /etc/my.cnf

最終行に以下を追記

default_password_lifetime=0

log_timestamps=SYSTEM

explicit_defaults_for_timestamp=TRUE

skip-character-set-client-handshake

character-set-server=utf8mb4

validate-password=OFF <<—非推奨だけど今までのパスワードがゆるふわだからね♪

systemctl start mysqld

systemctl enable mysqld

grep password /var/log/mysqld.log

2016-09-18T13:41:39.108126+09:00 1 [Note] A temporary password is generated for root@localhost: =mtd*3%=T2qf

mysql_secure_installation

対話形式

Securing the MySQL server deployment.

Enter password for user root: <初期パスワード>

The existing password for the user account root has expired. Please set a new password.

New password: <パスワード>

Re-enter new password: <パスワード>

Estimated strength of the password: 100

Change the password for root ? ((Press y|Y for Yes, any other key for No) : <空エンター>

(略)

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y

(略)

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y

(略)

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y

(略)

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y

Success.

All done!

PHP7

依存関係

yum --enablerepo=epel install libmcrypt

まるっとインストール

yum --enablerepo=remi-php70 install php php-cli php-devel php-common php-mbstring php-mysql php-phpunit-PHPUnit php-pecl-xdebug php-fpm php-gd php-gmp php-mcrypt php-opcache php-pdo php-xml

vi /etc/php.ini

date.timezone = Asia/Tokyo

mbstring.language = Japanese

upload_max_filesize = 30M  # 踏襲

Apache再起動して設定反映

systemctl restart httpd.service

firewalld設定

HTTP(80/tcp) と HTTPS(443/tcp) を開けておきます。

firewall-cmd --add-port=80/tcp --permanent

firewall-cmd --add-port=443/tcp --permanent

firewall-cmd --reload

sysstatを1分単位にする

vi /etc/cron.d/sysstat

Cronメールの無効化

crontab -e

vi /etc/crontab

vi /etc/anacrontab

以上3箇所にMAILTO=“” を設定(rootの記述は無効化しておく)

Git

gitバージョンアップ(yumをアンインストールして最新版をソースで入れる)

yum remove git

yum install curl-devel expat-devel openssl-devel zlib-devel perl-ExtUtils-MakeMaker  ※これが無いと後のmakeが失敗する

cd /usr/local/src

wget https://www.kernel.org/pub/software/scm/git/git-2.10.0.tar.gz  ※2016/9/24時点の最新

tar -zxf git-2.10.0.tar.gz

cd git-2.10.0

make prefix=/usr/local all

make prefix=/usr/local install

git --version

 git version 2.10.0


参考にさせていただいたサイト

https://adan.jp.net/blog/program/1235

https://blog.apar.jp/linux/3798/

みずいろ:
Related Post