少し古い環境を用意した


検証のため少し古めの環境を用意したので備忘録。コンテナではなく仮想マシンで作業した。
apacheとphpはconfig.niceを使ってコンパイルした。
Python27や新しめのAnsible2.9のインストールには一工夫必要だった。

作ろうとしている環境

  • CentOS 6.8
  • Apache 2.2
  • PHP 5.2
  • Python2.7(何もしないと2.6が入っている)
  • Ansible2.9(yumでは入らない)

CentOS 6.8

下記のアーカイブを使った。CentOS-6.8-x86_64-minimal.isoを利用。
http://ftp.riken.jp/Linux/centos-vault/6.8/isos/x86_64/

こちらにもアーカイブはあるがダウンロードに時間がかかり使えなかった。
https://archive.kernel.org/centos-vault/

よくやること(やっていたこと)

  • IPv6無効化
  • ifcfg-ethXのHWADDRやUUIDコメントアウト, ONBOOT=yesにする
  • IP疎通できないときは /etc/udev/rules.d/70-persistent-net.rules 削除してOS再起動。
  • SELinux無効化(Apache起動と動作確認あたりで問題が出たら無効化してみるのがよさそう)

yum設定

yumコマンドを使えるようにするため /etc/yum.repos.d/CentOS-Base.repo を編集した。

既存のmirrorlistをコメントアウト。baseurlもarchive.kernel.orgの6.8指定で書き換えた
[base]
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
baseurl=http://archive.kernel.org/centos-vault/6.8/os/$basearch/

[updates]
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
baseurl=http://archive.kernel.org/centos-vault/6.8/updates/$basearch/

[extras]
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
baseurl=http://archive.kernel.org/centos-vault/6.8/extras/$basearch/

[centosplus]
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
baseurl=http://archive.kernel.org/centos-vault/6.8/centosplus/$basearch/

[contrib]
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/
baseurl=http://archive.kernel.org/centos-vault/6.8/contrib/$basearch/

OSバージョン固定

/etc/yum/vars/releasever を用意して6.8とだけ書いておき、yum updateした。

/etc/yum/vars/releaseverを作成
# vi /etc/yum/vars/releasever
---内容ここから---
6.8
---ここまで---

# yum update

これらも入れておく

 # yum install wget make which

Apache2.2

ダウンロードはこちらのアーカイブを使った
https://archive.apache.org/dist/httpd/httpd-2.2.29.tar.gz

configureしたときに何度も出たエラーにそれぞれ対処で必要だったもの。

必要だったもの
# yum install gcc glibc g++ zlib zlib-devel openssl-devel
ダウンロード
# cd /usr/local/src
# wget https://archive.apache.org/dist/httpd/httpd-2.2.29.tar.gz
# tar zxf httpd-2.2.29.tar.gz
# cd httpd-2.2.29

古い環境にあった/usr/local/src/httpd-2.2.29/config.niceの中身をコピー。

vi config.nice

config.nice
#! /bin/sh
#
# Created by configure

"./configure" \
"--enable-so" \
"--enable-ssl" \
"--enable-mods-shared=all" \
"--with-expat=builtin" \
"--with-included-apr" \
"$@"
インストール
# sh config.nice
# make
# make install
グループとユーザー追加
# groupadd -g 48 apache
# useradd -g apache -u 48 apache

httpd.conf編集

# vi /usr/local/apache2/conf/httpd.conf
---とりあえず3箇所編集---
User apache
Group apache
ServerName サーバーのホストネーム:80
---

動作確認

# /usr/local/apache2/bin/apachectl configtest
# /usr/local/apache2/bin/apachectl start

iptablesを止めるか、80番をあけてから
ブラウザで http://[サーバーのIP]/ にアクセス、It Works!を確認。

PHP5.2

configureしたときに何度も出たエラーにそれぞれ対処して必要だったもの。

必要だったもの_その1
# yum install libxml2 libxml2-devel libcurl libcurl-devel
# yum install gcc-c++

(参考)http://re2c.org/install/install.html#build-cmake
# cd /usr/local/src
# wget https://github.com/skvadrik/re2c/releases/download/0.13.6/re2c-0.13.6.tar.gz
# gunzip re2c-0.13.6.tar.gz
# tar xvf re2c-0.13.6.tar
# cd re2c-0.13.6
# ./configure
# make
# make install
必要だったもの_その2
(参考)https://qiita.com/soundws/items/cc84da42419f1ab3443b
# cd ~
# wget http://ftp.riken.jp/Linux/fedora/epel/RPM-GPG-KEY-EPEL-6
# rpm --import RPM-GPG-KEY-EPEL-6 
# rm -f RPM-GPG-KEY-EPEL-6 

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

---内容ここから---
[epel]
name=EPEL RPM Repository for Red Hat Enterprise Linux
baseurl=http://ftp.riken.jp/Linux/fedora/epel/6/$basearch/
gpgcheck=1
enabled=0
---ここまで---

# yum --enablerepo=epel install libmcrypt-devel
  これをしないと出たエラー:configure: error: mcrypt.h not found. Please reinstall libmcrypt.

# yum --enablerepo=epel install mysql-devel
  これをしないと出たエラー
configure: error: Cannot find MySQL header files under /usr/bin/mysql.
Note that the MySQL client library is not bundled anymore!
必要だったもの_その3
# vi /usr/local/apache2/bin/apxs
一行目を
#!/usr/bin/perl -w
にする

 (参考)https://orebibou.com/ja/home/201506/20150617_001/
phpインストール
# cd /usr/local/src
# wget https://museum.php.net/php5/php-5.2.17.tar.gz
# tar zxf php-5.2.17.tar.gz
# cd php-5.2.17
# vi config.nice
---内容ここから---
#! /bin/sh
#
# Created by configure

'./configure' \
'--with-apxs2=/usr/local/apache2/bin/apxs' \
'--with-mysql=/usr/bin/mysql' \
'--with-mcrypt' \
'--with-curl=/usr/local/bin' \
'--with-zlib' \
'--with-openssl' \
'--enable-mbstring' \
'--enable-mbregex' \
'--enable-force-cgi-redirect' \
'--disable-short-tags' \
'--with-libdir=lib64' \
"$@"
---ここまで---

# sh config.nice
# make
# make install

Apacheとphpの連携

apache側

# vi /usr/local/apache2/conf/httpd.conf
---
<IfModule mime_module>
    TypesConfig conf/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php ##### このAddTypeを追加 ####
</IfModule>
---

httpd.confに LoadModule php5_module modules/libphp5.so があることも確認。なければ106行目あたりに追加。

再起動(restartは使えない)
# /usr/local/apache2/bin/apachectl stop
# /usr/local/apache2/bin/apachectl configtest
# /usr/local/apache2/bin/apachectl start

php側

php.iniは最終的には古い環境からもってくるが、とりあえず動作確認のために以下だけ実施。コメント;を外すだけの箇所もある。

# cp -p /usr/local/src/php.ini-recommended /usr/local/lib/php.ini
# vi /usr/local/lib/php.ini

---変更したところ--- 
output_buffering = On
error_reporting = E_ALL & ~E_NOTICE
default_charset = "UTF-8"
include_path = ".:/usr/local/include/php:/usr/local/lib"
extension_dir = "/usr/local/lib/php/ext"
date.timezone = Asia/Tokyo
mbstring.language = Japanese
mbstring.internal_encoding = UTF-8
mbstring.http_input = auto
mbstring.http_output = pass
mbstring.encoding_translation = Off
mbstring.detect_order = UTF-8, SJIS, EUC-JP, JIS, ASCII
mbstring.substitute_character = none;
------

動作確認

# vi /usr/local/apache2/htdocs/info.php
---内容ここから---
<?php phpinfo(); ?>
---ここまで---

ブラウザで http://[サーバーのIP]/info.php にアクセス

表示を確認

Python2.7とAnsible2.9.5

必要だったもの
# yum install centos-release-scl-rh scl-utils scl-utils-build
Python27_インストール
# yum install python27
確認(この時点ではまだpython26)
# which python
/usr/bin/python

# python --version
Python 2.6.6

# pip --version
-bash: pip: コマンドが見つかりません
python27を使うようにする
# scl enable python27 bash

# which python
/opt/rh/python27/root/usr/bin/python

# python --version
Python 2.7.17

# pip --version
pip 8.1.2 from /opt/rh/python27/root/usr/lib/python2.7/site-packages (python 2.7)
ansible2.9.5インストール
# pip install ansible==2.9.5

# 確認
# ansible --version
/opt/rh/python27/root/usr/lib/python2.7/site-packages/ansible/parsing/vault/__init__.py:41: CryptographyDeprecationWarning: Python 2 is no longer supported by the Python core team. Support for it is now deprecated in cryptography, and will be removed in a future release.
  from cryptography.exceptions import InvalidSignature
ansible 2.9.5
  config file = None
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/rh/python27/root/usr/lib/python2.7/site-packages/ansible
  executable location = /opt/rh/python27/root/usr/bin/ansible
  python version = 2.7.17 (default, Nov 29 2019, 13:22:37) [GCC 4.4.7 20120313 (Red Hat 4.4.7-23)]
python27をOS起動時に使えるようにしておく
# vi /etc/profile.d/python27.sh
---内容ここから---
source /opt/rh/python27/enable
---ここまで---
ansible実行時に必要になったもの
# yum install ibselinux-python  ##(参考)https://kokichiblog.com/it/1003/

### sshpassインストール
# rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
# yum clean all
# yum --enablerepo=epel install sshpass

## 上記でも問題なかったけどx86_64のほう選ぶべきだったかも
## rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

その他やったこと

git version 1から2

# yum install -y sqlite-devel bzip2-devel xz-libs gcc g++ build-essential kernel-headers kernel-devel
# yum install -y gcc curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-ExtUtils-MakeMaker

# cd /usr/local/src
# wget https://www.kernel.org/pub/software/scm/git/git-2.29.2.tar.gz 
# tar zxf git-2.29.2.tar.gz
# cd git-2.29.2
# make prefix=/usr/local all
# make prefix=/usr/local install

VSCodeでCentOS6にRemote-SSHするときに必要だったもの

書ききれてないもの

  • SELinuxを無効化しておくと、Apahce起動時に警告が出る。
[Sun Nov 29 15:41:40 2020] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
[Sun Nov 29 15:41:40 2020] [notice] Digest: generating secret for digest authentication ...
[Sun Nov 29 15:41:40 2020] [notice] Digest: done
[Sun Nov 29 15:41:41 2020] [notice] Apache/2.2.29 (Unix) mod_ssl/2.2.29 OpenSSL/1.0.1e-fips DAV/2 configured -- resuming normal operations
  • Ansible実行のたびに警告が出る
CryptographyDeprecationWarning: Python 2 is no longer supported by the Python core team. 
Support for it is now deprecated in cryptography, and will be removed in a future release.
  from cryptography.exceptions import InvalidSignature
  • インストール理由忘れ
    • yum install libstdc++