2017年2月10日金曜日

Western Digital製HDDのIntelliParkの設定

HDDのSMART情報の「Load_Cycle_Count 」の値の上昇が激しい。この値は、Western DigitalのHDDの場合IntelliParkという機能の動作回数を示すようだ。

IntelliParkという機能は、HDDのアイドル時(一定時間アクセスがない)に自動的に記録ヘッドを退避させて空気抵抗を減らし、読み取り/書き込みチャンネルのエレクトロニクスを停止し、低消費電力を実現するものらしい。低消費電力は歓迎(と言っても2.5インチHDDの消費電力なんてたかが知れているのに、この機能でどれだけ消費電力が減るのかという疑問もあるが)だが、8秒間という設定値(8秒間アクセスがなければ記録ヘッド退避)もおかしい(短すぎる)し、メーカーの保証値もたった30万回程度というのも少なすぎでしょう。こんな設定値ではすぐ保障の上限回数に達してしまう。そこでこの設定値を変更することにした。

smartctlコマンドで読みだした「Load_Cycle_Count 」の値は以下の通り。

193 Load_Cycle_Count        0x0032   108   108   000    Old_age   Always       -       277343

約2カ月前に調べたSMART情報と比べて、約3万の増加。これではあと数か月で、メーカーの保証値30万回を突破してしまう。

Linux上でIntelliParkの設定の変更には、「idle3-tools」というツールがあるようだ。

http://idle3-tools.sourceforge.net/

CentOS7のyumでインストールできるパッケージは用意されていないようなので、ソールコードをダウンロードしてコンパイルして利用する。

先ずは、ソースコードをダウンロードして解凍。

$ wget https://sourceforge.net/projects/idle3-tools/files/idle3-tools-0.9.1.tgz/download
$ tar xzvf idle3-tools-0.9.1.tgz
idle3-tools-0.9.1/
idle3-tools-0.9.1/COPYING
idle3-tools-0.9.1/idle3ctl.8
idle3-tools-0.9.1/Makefile
idle3-tools-0.9.1/sgio.c
idle3-tools-0.9.1/idle3ctl.c
idle3-tools-0.9.1/sgio.h

次にコンパイル。

$ cd idle3-tools-0.9.1
$ make
cc -g -O2 -W -Wall -Wbad-function-cast -Wcast-align -Wpointer-arith -Wcast-qual -Wshadow -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -fkeep-inline-functions -Wwrite-strings -Waggregate-return -Wnested-externs -Wtrigraphs    -c -o idle3ctl.o idle3ctl.c
idle3ctl.c:47:5: 警告: 関数宣言がプロトタイプではありません [-Wstrict-prototypes]
 int check_WDC_drive()
     ^
idle3ctl.c:88:5: 警告: 関数宣言がプロトタイプではありません [-Wstrict-prototypes]
 int VSC_enable()
     ^
idle3ctl.c:112:5: 警告: 関数宣言がプロトタイプではありません [-Wstrict-prototypes]
 int VSC_disable()
     ^
idle3ctl.c:136:5: 警告: 前に ‘VSC_send_key’ 用のプロトタイプがありません [-Wmissing-prototypes]
 int VSC_send_key(char rw)
     ^
idle3ctl.c:166:5: 警告: 関数宣言がプロトタイプではありません [-Wstrict-prototypes]
 int VSC_send_write_key()
     ^
idle3ctl.c:173:5: 警告: 関数宣言がプロトタイプではありません [-Wstrict-prototypes]
 int VSC_send_read_key()
     ^
idle3ctl.c:182:5: 警告: 前に ‘VSC_get_timer’ 用のプロトタイプがありません [-Wmissing-prototypes]
 int VSC_get_timer(unsigned char *timer)
     ^
idle3ctl.c:213:5: 警告: 前に ‘VSC_set_timer’ 用のプロトタイプがありません [-Wmissing-prototypes]
 int VSC_set_timer(unsigned char timer)
     ^
idle3ctl.c:244:6: 警告: 前に ‘cleanup’ 用のプロトタイプがありません [-Wmissing-prototypes]
 void cleanup(void)
      ^
idle3ctl.c:252:6: 警告: 前に ‘show_version’ 用のプロトタイプがありません [-Wmissing-prototypes]
 void show_version(void)
      ^
idle3ctl.c:258:6: 警告: 前に ‘show_usage’ 用のプロトタイプがありません [-Wmissing-prototypes]
 void show_usage(void)
      ^
cc -g -O2 -W -Wall -Wbad-function-cast -Wcast-align -Wpointer-arith -Wcast-qual -Wshadow -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -fkeep-inline-functions -Wwrite-strings -Waggregate-return -Wnested-externs -Wtrigraphs    -c -o sgio.o sgio.c
cc -s -o idle3ctl idle3ctl.o sgio.o
#strip idle3ctl

コンパイル時に警告が出まくったけど、問題はなさそう。

どうせ今回しか使わないのでこの場所に置いたまま直接実行することにする。

プログラムを実行し、現在のIntelliParkの設定値を表示させて確認。

$ sudo ./idle3ctl -g /dev/sda
Idle3 timer set to 80 (0x50)

8秒ということですね。メーカーの規定値のままです。

IntelliParkの機能をdisable(無効)に設定する。

$ sudo ./idle3ctl -d /dev/sda
Idle3 timer disabled
Please power cycle your drive off and on for the new setting to be taken into account. A reboot will not be enough!

電源を入れ直すと新しい設定が有効になるようだ。リブートでは、not be enough!。

ということで、電源を入れ直してIntelliParkの設定確認。

$ sudo ./idle3ctl -g /dev/sda
Idle3 timer is disabled

IntelliParkの機能をdisable(無効)に設定できました。

idle3ctlコマンドの指定方法は以下の通り。

idle3ctl [options] /dev/device

-h : display help
-l : show license and exit immediately
-V : show version and exit immediately
-v : verbose output
--force : force even if no Western Digital HDD are detected
-g : get raw idle3 timer value (default action)
-g100 : get idle3 timer value as wdidle3 v1.00 would display it
-g103 : get idle3 timer value as wdidle3 v1.03/v1.05 would display it
-d : disable idle3 timer
-s : set idle3 timer raw value (1-255)

2017年1月21日土曜日

Blogger登録メールアドレスの変更

Bloggerに登録メールアドレスの変更方法。

無いみたい。

以下のページに案内があった。

https://support.google.com/blogger/answer/42673

ブログを新しいオーナーに移行する
ブログをオーナー間で移行するには:
1.ブログの編集権限を他のユーザーに付与する上記の手順を行います。
2.元のブログオーナーの権限を取り消します。
3.元のブログオーナーの投稿の名前を変更する場合、新しいブログオーナーは投稿を削除してから再公開する必要があります。

登録メールアドレスを変更したければ、変更先のメールアドレスを編集者として追加。元のアドレスを削除。って手順でやれってことのようだ。

Bloggerに登録メールアドレスの変更手順は以下の通り。

1.元のメールアドレスでBloggerにログイン。

2.メールアドレスを変更するするブログを選択。

3.メニューの〔設定〕→〔基本〕のページの〔許可〕のところで、投稿者として新しいメールアドレスを追加。〔執筆者を招待〕をクリック。

4.新しいメールアドレスに招待メールが届くので〔招待に応じる〕のURLを開く。

5.〔招待に応じる〕のURLを開くと、再度、招待に応じるかの確認があるのでこれをクリック。新しいメールアドレスでBloggerにログインされる。

6.元のメールアドレスでBloggerにログインして、メニューの〔設定〕→〔基本〕のページの〔許可〕のところで、新しいメールアドレスに管理者としての権限を与える。

7.新しいメールアドレスに管理者としての権限を与えると、元のメールアドレスが削除可能になるので削除する。

これでBloggerの登録メールアドレスを変更できる。

が、これだけではコメント通知メールに元のメールアドレスが残っているので、メニューの〔設定〕→〔メール〕のページでコメント通知メールのメールアドレスの変更を行う。

招待メールの内容は以下の通り。

Google をご利用いただきありがとうございます。
このメールは、 ○○さんが自身のブログ「 "□□"」の投稿ユーザーになるようあなたを招待していることをお知らせするものです。この招待に応じる場合は、下のボタンをクリックしてください。
招待に応じる
重要: 招待に応じてこのブログの投稿ユーザーになるには、Google アカウントを使用してログインする必要があります。Google アカウントをお持ちでない場合は、こちらから作成できます。
ブログをお楽しみください。
Blogger チーム

最後に重要なこと。

新しいメールアドレスを登録する時にユーザープロフィールの新規作成を行った場合は、規定値の設定でプロフィール公開となっているので注意。必要ならメニューの〔設定〕→〔ユーザー設定〕のページからユーザー プロフィールを編集しておく。

あと、元のメールアドレスでのBloggerだが、Blogger自体には元のメールアドレスが登録されたままのようだ。メールアドレスは登録が残っているが管理しているブログは一つも無いという状態。気持ち悪いなあ。登録消したい。誰か方法教えて。

2017年1月16日月曜日

tcpdumpでHTTPリクエストパケットを表示する方法

tcpdumpコマンドでHTTPリクエストパケットを表示するには以下のような指定をすれば良い。

# tcpdump -i enp5s0 'src host 192.168.000.000 and dst port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)' -A

「ip[2:2]」は、パケット全体の長さ。

「ip[0]&0xf」は、IPパケットのヘッダの長さ(4bit)。

「tcp[12]&0xf0」は、TCPヘッダの長さ(4bit)。

「ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0」の意味は、パケット全体の長さからIPヘッダ長とTCPヘッダ長を引いた結果が0でない。つまりデータが存在するパケット。

実行例は以下のような感じ。

# tcpdump -i enp5s0 'src host 192.168.000.000 and dst port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)' -A
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on enp5s0, link-type EN100MB (Ethernet), capture size 65535 bytes
18:05:33.277701 IP localhost.localdomain.44996 > www.yahoo.co.jp.http: Flags [P.], seq 1905887331:1905887471, ack 295056756, win 229, options [nop,nop,TS val 752892287 ecr 90996223], length 140
E.....@.@........O.|...Pq..c..5t...........
,.9..l}.GET / HTTP/1.1
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.2)
Host: searchranking.yahoo.co.jp
Accept: */*

この例でのHTTPリクエストはphpからcurlを使って発生させたもの。以下のようなプログラム。

    $url = 'http://searchranking.yahoo.co.jp/';
    $ch = curl_init();
    curl_setopt( $ch, CURLOPT_URL, $url );
    curl_setopt( $ch, CURLOPT_USERAGENT,
        'Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.2)' );
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
    $c = curl_exec( $ch )

ブラウザからのHTTPリクエストとはかなり違うようだ。

tcpdump: WARNING: SIOCGIFADDR: nflog: No such device

CentOS7でhttpのリクエストを見ようとtcpdumpを実行したら以下のエラーになった。

# tcpdump
tcpdump: WARNING: SIOCGIFADDR: nflog: No such device
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on nflog, link-type NFLOG (Linux netfilter log messages), capture size 65535 bytes

CentOS7ではtcpdumpの-iでinterfaceを指定する必要があるようだ。interfaceを指定しないとtcpdump -Dで表示される先頭のデバイスが選択される。

CentOS7でのtcpdump -Dの実行結果は以下の通り。

# tcpdump -D
1.nflog (Linux netfilter log (NFLOG) interface)
2.nfqueue (Linux netfilter queue (NFQUEUE) interface)
3.usbmon1 (USB bus number 1)
4.usbmon2 (USB bus number 2)
5.usbmon3 (USB bus number 3)
6.usbmon4 (USB bus number 4)
7.enp5s0
8.usbmon5 (USB bus number 5)
9.any (Pseudo-device that captures on all interfaces)
10.lo

先頭が「nflog (Linux netfilter log (NFLOG) interface)」なのでtcpdumpの-iでのinterfaceを指定を省略した場合には、この「nflog (Linux netfilter log (NFLOG) interface)」が選択される。

以下のようにtcpdumpの-iでEthernetのinterfaceを指定すればEthernetのパケットの内容が見れる。

# tcpdump -i enp5s0
# tcpdump -i 7

CentOS6.7で確認してみた。CentOS6.7でのtcpdump -Dの実行結果は以下の通り。

/tcpdump -D
1.eth0
2.nflog (Linux netfilter log (NFLOG) interface)
3.nfqueue (Linux netfilter queue (NFQUEUE) interface)
4.eth1
5.any (Pseudo-device that captures on all interfaces)
6.lo

CentOS6.7では先頭がEthernetのinterfaceなので、tcpdumpの-iでのinterfaceを指定を省略してもEthernetが選択されてEthernetのパケットの内容が見れたようだ。

CentOS7になってネットワーク関係は微妙に変わっているようだ。

2016年12月25日日曜日

HDDのSMART情報チェック

またHDDが壊れたりすると嫌なので、HDDのSMART(Self-Monitoring, Analysis and Reporting Technology)情報をチェックしてみた。

CentOSで実行するには「smartmontools」パッケージが必要である。

物理HDDの確認。

# smartctl --scan
/dev/sda -d scsi # /dev/sda, SCSI device

HDDがSMART対応かの確認。

# smartctl -i /dev/sda
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.10.0-327.el7.x86_64] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Model Family:     Western Digital Scorpio Blue Serial ATA
Device Model:     WDC WD800BEVS-08RST2
Serial Number:    WD-WXE208EU0000
LU WWN Device Id: 5 0014ee 201000000
Firmware Version: 08.01G08
User Capacity:    80,026,361,856 bytes [80.0 GB]
Sector Size:      512 bytes logical/physical
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   ATA/ATAPI-7 (minor revision not indicated)
Local Time is:    Sun Dec 25 12:02:10 2016 JST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

SMART情報の表示。

# smartctl -A /dev/sda
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.10.0-327.el7.x86_64] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF READ SMART DATA SECTION ===
SMART Attributes Data Structure revision number: 16
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  1 Raw_Read_Error_Rate     0x000f   200   200   051    Pre-fail  Always       -       0
  3 Spin_Up_Time            0x0003   159   145   021    Pre-fail  Always       -       1008
  4 Start_Stop_Count        0x0032   090   090   000    Old_age   Always       -       10178
  5 Reallocated_Sector_Ct   0x0033   200   200   140    Pre-fail  Always       -       0
  7 Seek_Error_Rate         0x000f   200   200   051    Pre-fail  Always       -       0
  9 Power_On_Hours          0x0032   080   080   000    Old_age   Always       -       15137
 10 Spin_Retry_Count        0x0013   100   100   051    Pre-fail  Always       -       0
 11 Calibration_Retry_Count 0x0012   100   100   051    Old_age   Always       -       0
 12 Power_Cycle_Count       0x0032   093   093   000    Old_age   Always       -       7986
192 Power-Off_Retract_Count 0x0032   200   200   000    Old_age   Always       -       357
193 Load_Cycle_Count        0x0032   119   119   000    Old_age   Always       -       243633
194 Temperature_Celsius     0x0022   115   087   000    Old_age   Always       -       28
196 Reallocated_Event_Count 0x0032   200   200   000    Old_age   Always       -       0
197 Current_Pending_Sector  0x0012   200   200   000    Old_age   Always       -       0
198 Offline_Uncorrectable   0x0010   100   253   000    Old_age   Offline      -       0
199 UDMA_CRC_Error_Count    0x003e   200   200   000    Old_age   Always       -       0
200 Multi_Zone_Error_Rate   0x0009   200   200   051    Pre-fail  Offline      -       0

HDDの実行可能な自己診断の表示。

# smartctl -c /dev/sda
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.10.0-327.el7.x86_64] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF READ SMART DATA SECTION ===
General SMART Values:
Offline data collection status:  (0x00) Offline data collection activity
                                        was never started.
                                        Auto Offline Data Collection: Disabled.
Self-test execution status:      (   0) The previous self-test routine completed
                                        without error or no self-test has ever
                                        been run.
Total time to complete Offline
data collection:                ( 3600) seconds.
Offline data collection
capabilities:                    (0x7b) SMART execute Offline immediate.
                                        Auto Offline data collection on/off support.
                                        Suspend Offline collection upon new
                                        command.
                                        Offline surface scan supported.
                                        Self-test supported.
                                        Conveyance Self-test supported.
                                        Selective Self-test supported.
SMART capabilities:            (0x0003) Saves SMART data before entering
                                        power-saving mode.
                                        Supports SMART auto save timer.
Error logging capability:        (0x01) Error logging supported.
                                        General Purpose Logging supported.
Short self-test routine
recommended polling time:        (   2) minutes.
Extended self-test routine
recommended polling time:        (  49) minutes.
Conveyance self-test routine
recommended polling time:        (   6) minutes.
SCT capabilities:              (0x103f) SCT Status supported.
                                        SCT Error Recovery Control supported.
                                        SCT Feature Control supported.
                                        SCT Data Table supported.

今のところ異常は無いようである。

2016年12月22日木曜日

CodeIgniterのログがSELinuxの制限で書き込まれていない

サーバの移行が完了したものと思っていたが、CodeIgniterのログがSELinuxの制限で書き込まれていない問題があった。

今回はたまたまCodeIgniterのログを見ようと思って発見したのだが、CodeIgniter以外のフレームワーク(CakePHPやlaravel、zendframework、Symfony)でも同様の現象が発生するはず。

検索して調べるとSELinuxを使うのをやめるとか本来の対策になってないことを書いているページばかり・・・

Auditのログファイル「/var/log/audit.log」を見てみる。こんなエラーが出ているが・・・人間には意味不明。logsへのwriteがdeniedなのは判る。

type=AVC msg=audit(1482000000.454:1179): avc:  denied  { write } for  pid=1325 comm="httpd" name="logs" dev="sda2" ino=659616 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:httpd_sys_content_t:s0 tclass=dir
type=SYSCALL msg=audit(1482000000.454:1179): arch=c000003e syscall=21 success=no exit=-13 a0=7f21419efe38 a1=2 a2=0 a3=1 items=0 ppid=1065 pid=1325 auid=4294967295 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) ses=4294967295 comm="httpd" exe="/usr/sbin/httpd" subj=system_u:system_r:httpd_t:s0 key=(null)

CentODでSELinuxのエラー情報を「/var/log/message」に表示するための「setroubleshoot」パッケージはインストール済みなので「/var/log/message」を見てみる。以下のようなメッセージが大量に出力されていた。

Dec 22 10:10:46 localhost setroubleshoot: SELinux is preventing httpd from write access on the directory logs. For complete SELinux messages. run sealert -l 972e9c6a-24c8-4621-8153-94c6267ee76e

「run sealert」と言っているのでsealertコマンドを実行する。結果は以下の通り。

# sealert -l 972e9c6a-24c8-4621-8153-94c6267ee76e

sealert -l 972e9c6a-24c8-4621-8153-94c6267ee76e
SELinux is preventing httpd from write access on the directory logs.

*****  Plugin httpd_write_content (92.2 confidence) suggests   ***************

If you want to allow httpd to have write access on the logs directory
Then 'logs' のラベルを変更する必要があります
Do
# semanage fcontext -a -t httpd_sys_rw_content_t 'logs'
# restorecon -v 'logs'

*****  Plugin catchall_boolean (7.83 confidence) suggests   ******************

If allow httpd to unified がしたい
Then 'httpd_unified' boolean を有効にすることにより、 これを SELinux に伝える必 要があります。
詳細情報については、'None' man ページをご覧下さい。
Do
setsebool -P httpd_unified 1

*****  Plugin catchall (1.41 confidence) suggests   **************************

If httpd に、 logs directory の write アクセスがデフォルトで許可されるべきです。
Then バグとして報告してください。
ローカルのポリシーモジュールを生成すると、
 このアクセスを許可することができます。
Do
allow this access for now by executing:
# ausearch -c 'httpd' --raw | audit2allow -M my-httpd
# semodule -i my-httpd.pp


Additional Information:
Source Context                system_u:system_r:httpd_t:s0
Target Context                unconfined_u:object_r:httpd_sys_content_t:s0
Target Objects                logs [ dir ]
Source                        httpd
Source Path                   httpd
Port                          
Host                          localhost.localdomain
Source RPM Packages
Target RPM Packages
Policy RPM                    selinux-policy-3.13.1-102.el7_3.7.noarch
Selinux Enabled               True
Policy Type                   targeted
Enforcing Mode                Enforcing
Host Name                     localhost.localdomain
Platform                      Linux localhost.localdomain 3.10.0-327.el7.x86_64
                              #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64
Alert Count                   24
First Seen                    2016-12-22 10:10:38 JST
Last Seen                     2016-12-22 10:14:00 JST
Local ID                      972e9c6a-24c8-4621-8153-94c6267ee76e

Raw Audit Messages
type=AVC msg=audit(1482000000.769:1679): avc:  denied  { write } for  pid=2794 comm="httpd" name="logs" dev="sda2" ino=787019 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:httpd_sys_content_t:s0 tclass=dir


Hash: httpd,httpd_t,httpd_sys_content_t,dir,write

最初の***** - *****のところのDoに記載されている以下のコマンドを実行する。

# cd /var/www/エラーになっているCodeIgniterの場所
# semanage fcontext -a -t httpd_sys_rw_content_t 'logs'
# restorecon -v 'logs'

Webサイトにアクセスしてみる。CodeIgniterのログが出力されるのを確認。

作業完了。

2016年12月20日火曜日

ftp_put(): Unable to build data connection: No route to host

無料のレンタルサーバにftpするプログラムをphpで作成し使っていたのだが、OSをCentOS 7に変更した影響かエラーで動かなくなった。コマンドラインから実行し、指定のディレクトリ内の全フファイルをUploadするプログラムです。

エラーの内容は以下の通り。

A PHP Error was encountered

Severity: Warning
Message:  ftp_put(): Unable to build data connection: No route to host
Filename: controllers/xxxxxxxx.php
Line Number: xxx

phpのプログラムは以下の通り。エラーチェックを一切行っていない手抜きプログラム。

    $ftp_server = 'xxxx.xxxxxxxx.jp';
    $ftp_user   = 'xxxxxxxx';
    $ftp_pass   = 'xxxxxxxx';

    $ftp_stream = ftp_connect( $ftp_server );
    $ftp_result = ftp_login( $ftp_stream, $ftp_user, $ftp_pass );
    foreach( $files as $val ) {
      ftp_put( $ftp_stream, './'. $val, $base . $val, FTP_ASCII );
      echo "Upload: " . $val . "\n";
    }
    ftp_close( $ftp_stream );

なんだかなあと思いながら

    ftp_pasv( $ftp_stream, true );

を追加してみる。

動いたよ。

修正後のプログラムは以下の通り。

    $ftp_server = 'xxxx.xxxxxxxx.jp';
    $ftp_user   = 'xxxxxxxx';
    $ftp_pass   = 'xxxxxxxx';

    $ftp_stream = ftp_connect( $ftp_server );
    $ftp_result = ftp_login( $ftp_stream, $ftp_user, $ftp_pass );
    ftp_pasv( $ftp_stream, true );
    foreach( $files as $val ) {
      ftp_put( $ftp_stream, './'. $val, $base . $val, FTP_ASCII );
      echo "Upload: " . $val . "\n";
    }
    ftp_close( $ftp_stream );

パッシブモードの指定が必要になったようだ。CentOS 7にしてPHPのバージョンが変わって規定値が変わったのかな?それともレンタルサーバ側が変わったのだろうか。動いたからいいか。