2012年12月29日土曜日

httpd.conf : Apache2+mod_fastcgi+php-fpm

Apache + mod_fastcgi + php-fpm Server version: Apache/2.2.15 (Unix)
ServerTokens Prod

KeepAlive On

<IfModule prefork.c>
StartServers       8
MinSpareServers    5
MaxSpareServers   20
ServerLimit      256
MaxClients       256
MaxRequestsPerChild  4000
</IfModule>

LoadModule authz_host_module modules/mod_authz_host.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule mime_module modules/mod_mime.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule dir_module modules/mod_dir.so
LoadModule actions_module modules/mod_actions.so
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so

ServerAdmin root@localhost
ServerName www.luiukko.jp:80

<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>

<Directory "/var/www/html">
    Options -Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

ServerSignature Off

2012年12月28日金曜日

SL6+mysql+php+apache+mod_fastcgi+php-fpm

WordPressをインストールするために、必要なモジュールをインストールしていきます。

mysql

yum install mysql-server mysql
chkconfig mysqld on
次に/etc/my.cnfを編集します。ファイルの内容は、VPS 2GB用のmy.cnfを参考にしてください。
service mysqld start
/usr/bin/mysql_secure_installation

PHP 5.3 + php-fpm

PHP 5.3をインストールします。
yum install php54 php54-common php54-mysql php54-mbstring php54-gd php54-xml php54-fpm
/etc/php.iniを編集します。内容は、VPS 2GB用のphp.iniを参考にしてください。 mod_fastcgiをインストールします。
yum install mod_fastcgi
mod_fastcgiを有効にします。 /etc/httpd/conf.d/fastcgi.conf
User apache
Group apache

LoadModule fastcgi_module modules/mod_fastcgi.so

FastCgiExternalServer /var/www/fcgi-bin/php-fpm -socket /var/run/php-fpm.sock
AddHandler php-fastcgi .php
ScriptAlias /fcgi-bin/ /var/www/fcgi-bin/
Action php-fastcgi /fcgi-bin/php-fpm
AddType application/x-httpd-php .php
DirectoryIndex index.php
php.confを無効にする。
$ mv php.conf php.conf.bak
php-fpmをUnix Socketでリッスンするように設定します。
listen = /var/run/php-fpm.sock
listen.owner = apache
listen.group = apache
listen.mode = 0666
apacheの設定で、ExecCGIを有効にする。 /etc/httpd/conf/httpd.conf

    Options +ExecCGI

サービスをリスタートする。
# service php-fpm restart
# service httpd restart

Permission denied: FastCGI: failed to connect to server "/var/www/fcgi-bin/php-fpm": connect() failed

原因は、SELinuxであることまでは分かりましたが、有効にしたまま動作するようにする方法は分かりません。 しばらくは、SELinuxを無効にしておきます。
# getenforce
Enforcing
# setenforce 0

2012年12月24日月曜日

VPS 2GB用のphp.ini

お名前.com VPSの2GBプラン用のphp.iniファイルです。
post_max_size = 15M
upload_max_filesize = 15M

allow_url_fopen = On

[Date]
; Defines the default timezone used by the date functions
; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
date.timezone = "Asia/Tokyo"

VPS 2GB用のmy.cnf

お名前.com VPSの2GBプラン用のmy.cnfファイルです。
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
character-set-server = utf8
skip-name-resolve
skip-innodb
default-storage-engine=MyISAM

interactive_timeout = 50
join_buffer = 1M
key_buffer = 250M
max_connections = 100
max_heap_table_size = 32M
myisam_sort_buffer_size = 96M
query_cache_limit = 4M
query_cache_size = 250M
query_prealloc_size = 65K
query_alloc_block_size = 128K
read_buffer_size = 1M
read_rnd_buffer_size = 768K
sort_buffer_size = 1M
table_cache = 4096
thread_cache_size = 1024
tmp_table_size = 32M
wait_timeout = 500

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[mysql]
default-character-set = utf8

[isamchk]
key_buffer = 64M
sort_buffer = 64M
read_buffer = 16M
write_buffer = 16M

[myisamchk]
key_buffer = 64M
sort_buffer = 64M
read_buffer = 16M
write_buffer = 16M

お名前.com VPSにSL6.3をインストールした時のメモ

お名前.comのVPSサーバーにSL6をインストールした時のメモ。
cat /etc/redhat-release
Scientific Linux release 6.3 (Carbon)

ID関連

一般ユーザーを作って、sshを使ったrootログインを制限して、suできるユーザーを限定する。
useradd hoge
passwd hoge
usermod -G wheel hoge
vi /etc/ssh/sshd_config
Port 2022
Protocol 2
SyslogFacility AUTHPRIV
PermitRootLogin no
PasswordAuthentication yes
PermitEmptyPasswords no
ChallengeResponseAuthentication no
UsePAM yes
Subsystem       sftp    /usr/libexec/openssh/sftp-server
service sshd restart
vi /etc/pam.d/su
#%PAM-1.0
auth            sufficient      pam_rootok.so
# Uncomment the following line to implicitly trust users in the "wheel" group.
#auth           sufficient      pam_wheel.so trust use_uid
# Uncomment the following line to require a user to be in the "wheel" group.
auth            required        pam_wheel.so use_uid
auth            include         system-auth
account         sufficient      pam_succeed_if.so uid = 0 use_uid quiet
account         include         system-auth
password        include         system-auth
session         include         system-auth
session         optional        pam_xauth.so
ついでにロケールを変更。
vi /etc/sysconfig/i18n
LANG="ja_JP.UTF-8"
SYSFONT="latarcyrheb-sun16"

IPv6関連

IPv6が有効になっているかを確認。
ifconfig -a
eth0      Link encap:Ethernet  HWaddr 52:54:01:00:62:10  
          inet addr:49.212.122.248  Bcast:49.212.123.255  Mask:255.255.254.0
          inet6 addr: fe80::5054:1ff:fe00:6210/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
IPv6を無効にする。
echo 'options ipv6 disable=1' >/etc/modprobe.d/disable-ipv6.conf
chkconfig ip6tables off
reboot

APIPA関連

APIPAが有効になっているかを確認する。
netstat -nr
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
49.212.122.0    0.0.0.0         255.255.254.0   U         0 0          0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth0
0.0.0.0         49.212.122.1    0.0.0.0         UG        0 0          0 eth0
netowkを編集して無効にする。
vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=v103-3-18-170.myvps.jp
GATEWAY=49.212.122.1
NOZEROCONF=yes
service network restart

yumリポジトリ関連

yumのプラグインを追加。
yum install yum-plugin-fastestmirror yum-plugin-priorities
sl.repoとsl-other.repoのプライオリティを1に設定し最優先にする。
cd /etc/yum.repos.d
vi sl.repo
それぞれのセクションの最後に以下の行を追加
priority=1
EPELをリポジトリに追加する。
yum install epel-release
IUS Yumリポジトリを追加する
wget http://dl.iuscommunity.org/pub/ius/stable/Redhat/6/x86_64/ius-release-1.0-10.ius.el6.noarch.rpm
rpm -Uvh ius-release-1.0-8.ius.el6.noarch.rpm
RPMforgeを追加する。
wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
rpm -Uvh rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
全てのパッケージをアップデートしておきます。
yum update

iptables

iptablesを一括設定するファイルを作成しておきます。 ここでは、sshd, http, smtpを開けておきます。
#!/bin/sh
/sbin/iptables -F
/sbin/iptables -X

/sbin/iptables -P INPUT DROP
/sbin/iptables -P OUTPUT ACCEPT
/sbin/iptables -P FORWARD DROP

/sbin/iptables -A INPUT -i lo -j ACCEPT
/sbin/iptables -A OUTPUT -o lo -j ACCEPT

/sbin/iptables -A INPUT -s 10.0.0.0/8 -j DROP
/sbin/iptables -A INPUT -s 172.16.0.0/12 -j DROP
/sbin/iptables -A INPUT -s 192.168.0.0/16 -j DROP

/sbin/iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
/sbin/iptables -A INPUT -p tcp --dport 2022 -j ACCEPT
/sbin/iptables -A INPUT -p tcp --dport 25 -j ACCEPT
/sbin/iptables -A INPUT -p tcp --dport 80 -j ACCEPT

/sbin/iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

/etc/rc.d/init.d/iptables save

2012年9月22日土曜日

PDFファイルをEvernoteに保存する

PDFファイルをDropboxに保存すると、自動的にEvernoteに連携される仕組みを作ってみました。 WappwolfのDropbox Automatorというサービスを使います。既にDropboxとEvernoteはアカウントを持っていますので、Wappwolfのアカウントを作るところからです。 Try now! をクリックして、Login with dropbox "one folder" accessを選びます。

Dropboxにサインインして、Wappwolf Automator からの接続リクエストを許可します。 DropboxにWappwolfフォルダが作成され、その下に自動化するためのフォルダを指定する画面になりますので、適当な名前を入力します。

次に画面をスクロールして、Any fileにある Upload it to Evernoteを選択して、Connect to Evernoteをクリックします。

Evernoteにサインインして、Wappwolfのアクセスを承認します。 画面が戻ったら上に表示されている、Finishedをクリックします。 次の画面が表示されたら完了のようです。うまく行かなかった場合には、もう一回やってみるといいかもしれません。

これで準備完了です。 EvernoteにアップロードしたいファイルをDropboxの¥Apps¥Wappwolf¥Evernoteに保存すればOKです。

2012年8月5日日曜日

install php5 on OpenSUSE 12

# zypper install php5 php5-mysql php5-mbstring php5-gd php5-fpm
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following NEW packages are going to be installed:
  libsqlite3-0 php5 php5-ctype php5-dom php5-fpm php5-gd php5-iconv php5-json 
  php5-mbstring php5-mysql php5-pdo php5-sqlite php5-tokenizer php5-xmlreader 
  php5-xmlwriter sqlite2 t1lib 

The following recommended packages were automatically selected:
  php5-ctype php5-dom php5-iconv php5-json php5-sqlite php5-tokenizer 
  php5-xmlreader php5-xmlwriter 

The following packages are suggested, but will not be installed:
  php5-gettext php5-pear php5-suhosin 

17 new packages to install.
Overall download size: 3.6 MiB. After the operation, additional 13.6 MiB will 
be used.
Continue? [y/n/?] (y): y
Retrieving package t1lib-5.1.2-15.7.1.x86_64 (1/17), 152.0 KiB (405.0 KiB unpacked)
Retrieving: t1lib-5.1.2-15.7.1.x86_64.rpm [done]
Retrieving package php5-5.3.8-4.24.1.x86_64 (2/17), 1.1 MiB (4.6 MiB unpacked)
Retrieving: php5-5.3.8-4.24.1.x86_64.rpm [done (7.1 MiB/s)]
Retrieving package php5-xmlwriter-5.3.8-4.24.1.x86_64 (3/17), 29.0 KiB (47.0 KiB unpacked)
Retrieving: php5-xmlwriter-5.3.8-4.24.1.x86_64.rpm [done]
Retrieving package php5-tokenizer-5.3.8-4.24.1.x86_64 (4/17), 24.0 KiB (19.0 KiB unpacked)
Retrieving: php5-tokenizer-5.3.8-4.24.1.x86_64.rpm [done]
Retrieving package php5-pdo-5.3.8-4.24.1.x86_64 (5/17), 54.0 KiB (120.0 KiB unpacked)
Retrieving: php5-pdo-5.3.8-4.24.1.x86_64.rpm [done]
Retrieving package php5-mbstring-5.3.8-4.24.1.x86_64 (6/17), 402.0 KiB (2.1 MiB unpacked)
Retrieving: php5-mbstring-5.3.8-4.24.1.x86_64.rpm [done]
Retrieving package php5-json-5.3.8-4.24.1.x86_64 (7/17), 31.0 KiB (35.0 KiB unpacked)
Retrieving: php5-json-5.3.8-4.24.1.x86_64.rpm [done]
Retrieving package php5-iconv-5.3.8-4.24.1.x86_64 (8/17), 33.0 KiB (39.0 KiB unpacked)
Retrieving: php5-iconv-5.3.8-4.24.1.x86_64.rpm [done]
Retrieving package php5-gd-5.3.8-4.24.1.x86_64 (9/17), 100.0 KiB (333.0 KiB unpacked)
Retrieving: php5-gd-5.3.8-4.24.1.x86_64.rpm [done]
Retrieving package php5-fpm-5.3.8-4.24.1.x86_64 (10/17), 1.0 MiB (4.2 MiB unpacked)
Retrieving: php5-fpm-5.3.8-4.24.1.x86_64.rpm [done]
Retrieving package php5-dom-5.3.8-4.24.1.x86_64 (11/17), 64.0 KiB (173.0 KiB unpacked)
Retrieving: php5-dom-5.3.8-4.24.1.x86_64.rpm [done]
Retrieving package php5-ctype-5.3.8-4.24.1.x86_64 (12/17), 23.0 KiB (15.0 KiB unpacked)
Retrieving: php5-ctype-5.3.8-4.24.1.x86_64.rpm [done]
Retrieving package php5-mysql-5.3.8-4.24.1.x86_64 (13/17), 69.0 KiB (200.0 KiB unpacked)
Retrieving: php5-mysql-5.3.8-4.24.1.x86_64.rpm [done]
Retrieving package php5-xmlreader-5.3.8-4.24.1.x86_64 (14/17), 29.0 KiB (31.0 KiB unpacked)
Retrieving: php5-xmlreader-5.3.8-4.24.1.x86_64.rpm [done]
Retrieving package libsqlite3-0-3.7.8-1.1.2.x86_64 (15/17), 262.0 KiB (798.0 KiB unpacked)
Retrieving: libsqlite3-0-3.7.8-1.1.2.x86_64.rpm [done]
Retrieving package sqlite2-2.8.17-179.1.2.x86_64 (16/17), 148.0 KiB (346.0 KiB unpacked)
Retrieving: sqlite2-2.8.17-179.1.2.x86_64.rpm [done]
Retrieving package php5-sqlite-5.3.8-4.24.1.x86_64 (17/17), 62.0 KiB (160.0 KiB unpacked)
Retrieving: php5-sqlite-5.3.8-4.24.1.x86_64.rpm [done (0 B/s)]
Installing: t1lib-5.1.2-15.7.1 [done]
Installing: php5-5.3.8-4.24.1 [done]
Installing: php5-xmlwriter-5.3.8-4.24.1 [done]
Installing: php5-tokenizer-5.3.8-4.24.1 [done]
Installing: php5-pdo-5.3.8-4.24.1 [done]
Installing: php5-mbstring-5.3.8-4.24.1 [done]
Installing: php5-json-5.3.8-4.24.1 [done]
Installing: php5-iconv-5.3.8-4.24.1 [done]
Installing: php5-gd-5.3.8-4.24.1 [done]
Installing: php5-fpm-5.3.8-4.24.1 [done]
Installing: php5-dom-5.3.8-4.24.1 [done]
Installing: php5-ctype-5.3.8-4.24.1 [done]
Installing: php5-mysql-5.3.8-4.24.1 [done]
Installing: php5-xmlreader-5.3.8-4.24.1 [done]
Installing: libsqlite3-0-3.7.8-1.1.2 [done]
Installing: sqlite2-2.8.17-179.1.2 [done]
Installing: php5-sqlite-5.3.8-4.24.1 [done]
# chkconfig php-fpm on
phpの内容を確認します。
# cd /srv/www/htdocs
# echo '<?php phpinfo(); ?>' >info.php

2012年8月4日土曜日

install nginx on OpenSUSE 12

# zypper install nginx
Loading repository data...
Reading installed packages...
'nginx' not found in package names. Trying capabilities.
Resolving package dependencies...

The following NEW packages are going to be installed:
  GeoIP libGeoIP1 libxslt1 nginx-1.0 

The following recommended package was automatically selected:
  GeoIP 

4 new packages to install.
Overall download size: 1.3 MiB. After the operation, additional 4.0 MiB will be 
used.
Continue? [y/n/?] (y): y
Retrieving package libxslt1-1.1.26-15.8.1.x86_64 (1/4), 149.0 KiB (402.0 KiB unpacked)
Retrieving: libxslt1-1.1.26-15.8.1.x86_64.rpm [done (6.2 KiB/s)]
Retrieving package libGeoIP1-1.4.7-3.1.2.x86_64 (2/4), 75.0 KiB (242.0 KiB unpacked)
Retrieving: libGeoIP1-1.4.7-3.1.2.x86_64.rpm [done]
Retrieving package GeoIP-1.4.7-3.1.2.x86_64 (3/4), 481.0 KiB (1.2 MiB unpacked)
Retrieving: GeoIP-1.4.7-3.1.2.x86_64.rpm [done]
Retrieving package nginx-1.0-1.0.10-3.4.1.x86_64 (4/4), 581.0 KiB (2.1 MiB unpacked)
Retrieving: nginx-1.0-1.0.10-3.4.1.x86_64.rpm [done]
Installing: libxslt1-1.1.26-15.8.1 [done]
Installing: libGeoIP1-1.4.7-3.1.2 [done]
Installing: GeoIP-1.4.7-3.1.2 [done]
Installing: nginx-1.0-1.0.10-3.4.1 [done]

# chkconfig nginx on
# rcnginx start
SuSEfirewall2を設定して、ポート80へのInboundを許可します。
# cd /etc/sysconfig/SuSEfirewall2.d/services
# echo 'TCP="80"' >httpd
# vi /etc/sysconfig/SuSEfirewall2
FW_CONFIGURATIONS_EXT="sshd smtp dovecot httpd"
設定を反映します。
# rcSuSEfirewall2 restart

Install MySQL on OpenSUSE 12

パッケージをインストールします。
# zypper install mysql-community-server mysql-community-client
Loading repository data...
Reading installed packages...
'mysql-community-client' not found in package names. Trying capabilities.
No provider of 'mysql-community-client' found.
Resolving package dependencies...

The following NEW packages are going to be installed:
  mysql-community-server mysql-community-server-client 
  mysql-community-server-errormessages 

3 new packages to install.
Overall download size: 8.0 MiB. After the operation, additional 60.5 MiB will 
be used.
Continue? [y/n/?] (y): y
Retrieving package mysql-community-server-errormessages-5.5.25-3.12.1.x86_64 (1/3), 146.0 KiB (1.0 MiB unpacked)
Retrieving: mysql-community-server-errormessages-5.5.25-3.12.1.x86_64.rpm [done]Retrieving package mysql-community-server-client-5.5.25-3.12.1.x86_64 (2/3), 736.0 KiB (17.1 MiB unpacked)
Retrieving: mysql-community-server-client-5.5.25-3.12.1.x86_64.rpm [done]Retrieving package mysql-community-server-5.5.25-3.12.1.x86_64 (3/3), 7.1 MiB (42.4 MiB unpacked)
Retrieving: mysql-community-server-5.5.25-3.12.1.x86_64.rpm [done]
Installing: mysql-community-server-errormessages-5.5.25-3.12.1 [done]
Installing: mysql-community-server-client-5.5.25-3.12.1 [done]
Installing: mysql-community-server-5.5.25-3.12.1 [done]
自動起動をOnにします。
# systemctl enable mysql.service
mysql.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig mysql on
サービスを起動します。
# systemctl start mysql.service
Failed to issue method call: Unit mysql.service failed to load: No such file or directory. See system logs and 'systemctl status mysql.service' for details.
エラーで起動できず。。。 原因がわからないので、一旦アンインストールして、パッケージの入手からやり直すことにします。 アンインストール。
# zypper remove mysql-community-server mysql-community-server-client mysql-community-server-errormessages
パッケージをMySQLのサイトからダウンロードします。SLESを選択して、MySQL ServerとClient Utilitiesをダウンロードします。 http://dev.mysql.com/downloads/mysql/5.5.html rpmパッケージをインストールします。
# rpm -ivh MySQL-server-5.5.27-1.sles11.x86_64.rpmPreparing...                ########################################### [100%]
ls: cannot access /var/lib/mysql/*.err: No such file or directory
ls: cannot access /var/lib/mysql/*.err: No such file or directory
   1:MySQL-server           ########################################### [100%]
insserv: Service network is missed in the runlevels 2 4 to use service mysql

Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.

mysql                     0:off  1:off  2:on   3:on   4:on   5:on   6:off

# rpm -ivh MySQL-client-5.5.27-1.sles11.x86_64.rpm
Preparing...                ########################################### [100%]
   1:MySQL-client           ########################################### [100%]
セキュリティ設定用のスクリプトを実行します。
# mysql_secure_installation 




NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!


In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] 
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] 
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] 
 ... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] 
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] 
 ... Success!

Cleaning up...



All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!
お終い!

telnetでIMAPアクセス

# telnet localhost 143
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
* OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE STARTTLS AUTH=CRAM-MD5 AUTH=LOGIN AUTH=PLAIN] Dovecot ready.
1 login mascotpark@lool.jp password
1 OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS MULTIAPPEND UNSELECT IDLE CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS] Logged in
2 list "" *
* LIST (\HasNoChildren) "." "INBOX"
2 OK List completed.
3 select INBOX
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft $NotJunk)
* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft $NotJunk \*)] Flags permitted.
* 1 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1342696244] UIDs valid
* OK [UIDNEXT 2] Predicted next UID
* OK [HIGHESTMODSEQ 1] Highest
3 OK [READ-WRITE] Select completed.
4 fetch 1 body[]
* 1 FETCH (BODY[] {523}
Return-Path: 
X-Original-To: mascotpark@lool.jp
Delivered-To: mascotpark@lool.jp
Received: by mail.lool.jp (Postfix, from userid 0)
 id 4B8482003D4; Sat,  4 Aug 2012 14:20:25 +0900 (JST)
Date: Sat, 04 Aug 2012 14:20:25 +0900
To: mascotpark@lool.jp
Subject: hello
User-Agent: Heirloom mailx 12.5 7/5/10
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Message-Id: <20120804052025.4B8482003D4@mail.lool.jp>
From: root@mail.lool.jp (root)

test

)
4 OK Fetch completed.
5 logout
* BYE Logging out
5 OK Logout completed.
Connection closed by foreign host.
# 

2012年7月16日月曜日

[RESOLVED] warning: not set-gid or not owner+group+world executable:

postfix起動時に以下のメッセージが表示されます。
Jul 16 11:10:25 v103-3-189-170 postfix/postfix-script[3588]: warning: not set-gid or not owner+group+world executable: /usr/sbin/postqueue
Jul 16 11:10:25 v103-3-189-170 postfix/postfix-script[3589]: warning: not set-gid or not owner+group+world executable: /usr/sbin/postdrop
それぞれのファイルのパーミッションは以下の通りです。
-rwxr-xr-x 1 root maildrop 15064 May 10 18:44 postdrop
-rwxr-xr-x 1 root maildrop 15016 May 10 18:44 postqueue
パーミッションを以下の通り変更します。
# cd /usr/sbin
# chmod g+s postdrop postqueue
# ls -l postqueue postdrop 
-rwxr-sr-x 1 root maildrop 15064 May 10 18:44 postdrop
-rwxr-sr-x 1 root maildrop 15016 May 10 18:44 postqueue

[RESOLVED] warning: not owned by group maildrop:

メッセージの内容は以下の通り。
Jul 16 10:59:28 v103-3-189-170 postfix/postfix-script[3316]: warning: not owned by group maildrop: /usr/sbin/postqueue
Jul 16 10:59:28 v103-3-189-170 postfix/postfix-script[3317]: warning: not owned by group maildrop: /usr/sbin/postdrop
この時の各ファイルのオーナーは次の通り。
-rwxr-xr-x 1 root root 15064 May 10 18:44 postdrop
-rwxr-xr-x 1 root root 15016 May 10 18:44 postqueue
グループをmaildropに変更します。
# chgrp maildrop postqueue postdrop
# ls -l
-rwxr-xr-x 1 root maildrop 15064 May 10 18:44 postdrop
-rwxr-xr-x 1 root maildrop 15016 May 10 18:44 postqueue

openSUSE12.1 メールサーバー インストール postfix dovecot

openSUSE12.1に、postfixとdovecotをインストールして、メールサーバーを構築します。
# zypper install --no-recommends postfix dovecot12
Loading repository data...
Reading installed packages...
'postfix' is already installed.
No update candidate for 'postfix-2.8.8-3.13.1.x86_64'. The highest available version is already installed.
Resolving package dependencies...

The following NEW package is going to be installed:
  dovecot12 

The following packages are recommended, but will not be installed:
  dovecot12-backend-mysql dovecot12-backend-pgsql dovecot12-backend-sqlite 

1 new package to install.
Overall download size: 2.6 MiB. After the operation, additional 14.4 MiB will 
be used.
Continue? [y/n/?] (y): y
Retrieving package dovecot12-1.2.17-7.1.3.x86_64 (1/1), 2.6 MiB (14.4 MiB unpacked)
Retrieving: dovecot12-1.2.17-7.1.3.x86_64.rpm [done]
Installing: dovecot12-1.2.17-7.1.3 [done]
postfixはインストールされていました。 今回は次のようなメールサーバーを構築します。
  • SASL認証はdovecotで行う
  • virtual mailboxを使う
  • SSLによる暗号化
  • IMAPを使う
postfixがdovecot SASLをサポートしていることを確認します。
# postconf -a
cyrus
dovecot
SSLの自己証明書と秘密鍵を作ります。
# cd /etc/ssl/private
# openssl req -new -x509 -nodes -days 3650 -out mail.crt -keyout mail.key
Generating a 1024 bit RSA private key
.....++++++
...........................................++++++
writing new private key to 'mail.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, YOUR name) []:mail.lool.jp  
Email Address []:

# chmod 600 mail.key
次にvirtual mailbox用に、ユーザーとグループを作成します。
# groupadd -g 1001 vmail
# useradd -u 1001 -g 1001 -d /var/spool/vmail -r -s /sbin/nologin vmail
virtual mailboxディレクトリを作成します。
# mkdir /var/spool/vmail
# chown vmail.vmail /var/spool/vmail
# chmod 700 /var/spool/vmail
/etc/postfix/main.cfを編集します。
setgid_group = maildrop
daemon_directory = /usr/lib/postfix

myhostname = mail.lool.jp
mydomain = lool.jp
myorigin = $mydomain
mydestination = $myhostname localhost.$mydomain localhost
smtpd_recipient_restrictions =
        permit_mynetworks,
        permit_sasl_authenticated,
        reject_unauth_destination,
        permit_auth_destination,
        reject

debug_peer_level = 3

home_mailbox = Maildir/

virtual_alias_maps = hash:/etc/postfix/virtual
virtual_mailbox_maps = hash:/etc/postfix/vmailbox
virtual_gid_maps = static:1001
virtual_uid_maps = static:1001
virtual_mailbox_base = /var/spool/vmail
virtual_mailbox_domains = lool.jp

smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/dovecot-auth
/etc/postfix/vmailboxにvirtual mailboxを定義します。
mascotpark@lool.jp mascotpark/Maildir/
# cd /etc/postfix
# postmap vmailbox
/etc/postfix/master.cfを編集します。
smtp      inet  n       -       n       -       -       smtpd
submission inet n       -       n       -       -       smtpd
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
次に/etc/dovecot/dovecot.confを編集します。
protocols = imap imaps

   protocol imap {
     listen = *:143
     ssl_listen = *:993
   }
listen = *

disable_plaintext_auth = yes

ssl = yes
ssl_cert_file = /etc/ssl/private/mail.crt
ssl_key_file = /etc/ssl/private/mail.key
verbose_ssl = yes

mail_location = maildir:/var/spool/vmail/%u/Maildir

mail_uid = 1001
mail_gid = 1001

mail_debug = yes
lock_method = fcntl

protocol imap {
  mail_plugin_dir = /usr/lib64/dovecot/modules/imap
}

auth_username_format = %Ln

auth default {
  mechanisms = cram-md5 login plain
  passdb passwd-file {
    args = scheme=CRAM-MD5 username_format=%u /etc/dovecot/passwd
  }
  user = root
  socket listen {
    master {
      path = /var/run/dovecot/auth-master
      mode = 0600
      user = postfix
      group = postfix
    }
    client {
      path = /var/spool/postfix/private/dovecot-auth
      mode = 0660
      user = postfix
      group = postfix
    }
  }
}

dict {
}

plugin {
}
/etc/dovecot/passwdファイルを作ります。
mascotpark:{CRAM-MD5}477934589a58e54b516c742aff2e8a77019df50f3b33f134385b875047370666
サービスを再起動します。
# systemctl restart postfix.service
# systemctl restart dovecot.service
Firewallを設定します。 smtpとdovecotで使用するポート番号を設定します。 /etc/sysconfig/SuSEfirewall2.d/services/smtp
TCP="25 465 587"
/etc/sysconfig/SuSEfirewall2.d/services/dovecot
TCP="imap imaps pop3 pop3s sieve 4190"
/etc/sysconfig/SuSEfirewall2を編集し、サービスを再起動します。
FW_CONFIGURATIONS_EXT="sshd smtp dovecot"
# /sbin/SuSEfirewall2 stop
SuSEfirewall2: Firewall rules unloaded.
# /sbin/SuSEfirewall2 start
SuSEfirewall2: Setting up rules from /etc/sysconfig/SuSEfirewall2 ...
SuSEfirewall2: using default zone 'ext' for interface eth0
SuSEfirewall2: Firewall rules successfully set
telnetを使って動作を確認します。
# telnet localhost 25
EHLO localhost
250-mail.lool.jp
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
MAIL FROM:root
250 2.1.0 Ok
RCPT TO:mascotpark@lool.jp
250 2.1.5 Ok
DATA
354 End data with .
TEST
.
250 2.0.0 Ok: queued as 6EC272003DA
quit
221 2.0.0 Bye
Connection closed by foreign host.
# telnet localhost 143
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
* OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE STARTTLS AUTH=CRAM-MD5 AUTH=PLAIN AUTH=LOGIN] Dovecot ready.
x LOGIN mascotpark@lool.jp password
x OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS MULTIAPPEND UNSELECT IDLE CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS] Logged in
x LOGOUT
* BYE Logging out
x OK Logout completed.
Connection closed by foreign host.

2012年7月10日火曜日

SUSE sshdのポートを変更したのでFirewallの設定を変える

sshdのポートを20から2022に変更したので、それに合わせてFirewallのポートも20から2022に変更します。 /etc/sysconfig/SuSEfirewall2.d/servicesディレクトリの下に、サービス名のファイル名があります。 今回は、sshdですので、その内容を以下に変更します。
## Name: Secure Shell Server
## Description: Open ports for Secure Shell Server

# space separated list of allowed TCP ports
#TCP="ssh"
TCP=2022
設定の変更を反映する方法はまだ分かっていません。。。リブートしました。

2012年7月9日月曜日

SUSE ホスト名の変更 固定IPアドレス デフォルトゲートウェイ設定 DNS設定

ホスト名を変更するには、/etc/HOSTNAMEファイルを編集します。
myhostname
/etc/sysconfig/network/ifcfg-eth0を編集して、ネットワークを設定します。
BOOTPROTO='static'
BROADCAST='103.3.189.255'
ETHTOOL_OPTIONS=''
IPADDR='103.3.189.170'
MTU=''
NAME='Ethernet Card 0'
NETMASK='255.255.255.0'
NETWORK='103.3.189.0'
REMOTE_IPADDR=''
STARTMODE='auto'
USERCONTROL='no'
デフォルトゲートウェイを設定します。 /etc/sysconfig/network/routesファイルを作成します。
default 103.3.189.1 - -
/etc/resolv.confを編集して、DNSサーバーを設定します。/etc/resolv.confを手動で編集する際には、/etc/sysconfig/network/configファイルを編集します。
NETCONFIG_DNS_POLICY=""
search myvps.jp
nameserver 210.157.1.170
nameserver 210.172.133.178

お名前.com VPSにopenSUSEをインストール

お名前.comのVPS(2GB)を借りたので、openSUSEをインストールしてみました。

まずはOS Imageをダウンロードします。
software.opensuse.org: openSUSE 12.1 のダウンロード
次にダウンロードしたISOイメージをアップロードします。そのために、コントロールパネルの画面から、ssh private keyをダウンロードします。ページの下の方にあります。

接続先サーバー名、ユーザー名、ダウンロードした公開鍵ファイルを使って、SFTPで接続します。接続したらimagesディレクトリの下に、ダウンロードしたISOイメージファイルをアップロードします。
次にOS再インストールのタブを選択して、OSにアップロードしたopenSUSEを選択します。パーティションはお好みで。

実行すると、サーバーリストが表示されますので、IPアドレスと初期ホスト名をメモしておきます。起動をクリックして、VMをブートします。


installationを選択します。
言語とキーボードレイアウトを日本語に設定して、次へ。

新規インストールと手動設定を選んで、次へ。

ハードウェアの時刻はUTCに設定のチェックを外します。

私はサーバー用途でインストールしますので、最小限のサーバ(テキストモード)を選びます。

パーティションを任意に設定して、次へ。

ユーザー名とパスワードなどこちらもお好みで。

インストール設定を確認します。最後のsshを有効にしました。

問題がなければインストールをGO!

ホスト名とドメイン名を設定しますが、とりあえずデフォルトのまま進みます。

デフォルトのままでもいいですが、IPv6を無効にしてから次に進みます。

インターネットへの接続テストはお好みで。

エラーが表示されてもあまり気にせず前に進みます。

オンライン更新を実行するのまま、次に進みます。

了解して次へ進みます。

修正のダウンロードとインストールが完了したら次へ進みます。

途中おかしくなったら再起動します。次の画面が表示されたらインストールは終わりです。

2012年7月8日日曜日

postfix + dovecot on SL6

postfixの設定

# postconf -n
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
home_mailbox = Maildir/
html_directory = no
inet_interfaces = all
inet_protocols = ipv4
local_recipient_maps = proxy:unix:passwd.byname $alias_maps $virtual_mailbox_maps
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
mydestination = $myhostname, localhost
myhostname = mail.lumiukko.jp
mynetworks = 49.212.129.72
mynetworks_style = host
myorigin = $myhostname
newaliases_path = /usr/bin/newaliases.postfix
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES
relay_domains = $mydestination
sample_directory = /usr/share/doc/postfix-2.6.6/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_path = private/dovecot-auth
smtpd_sasl_security_options = noanonymous
smtpd_sasl_type = dovecot
smtpd_tls_auth_only = yes
smtpd_tls_cert_file = /etc/pki/tls/certs/mail.crt
smtpd_tls_key_file = /etc/pki/tls/certs/mail.key
smtpd_use_tls = yes
unknown_local_recipient_reject_code = 550
virtual_alias_maps = hash:/etc/postfix/virtual
virtual_gid_maps = static:502
virtual_mailbox_base = /var/spool/vmail
virtual_mailbox_domains = lumiukko.jp
virtual_mailbox_maps = hash:/etc/postfix/vmailbox
virtual_uid_maps = static:502
/etc/postfix/master.cfの内容
smtp      inet  n       -       n       -       -       smtpd
submission inet n       -       n       -       -       smtpd
  -o smtpd_tls_security_level=encrypt
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
  -o milter_macro_daemon_name=ORIGINATING
#smtps     inet  n       -       n       -       -       smtpd
#  -o smtpd_tls_wrappermode=yes
#  -o smtpd_sasl_auth_enable=yes
#  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
#  -o milter_macro_daemon_name=ORIGINATING
/etc/postfix/vmailboxの内容
nordenlife@lumiukko.jp lumiukko.jp/nordenlife/Maildir/

dovecotの設定

# doveconf -n
# 2.0.9: /etc/dovecot/dovecot.conf
# OS: Linux 2.6.32-220.7.1.el6.x86_64 x86_64 Scientific Linux release 6.2 (Carbon) 
auth_mechanisms = cram-md5 login
auth_username_format = %Lu
auth_verbose = yes
listen = *
mail_debug = yes
mail_location = maildir:~/Maildir
mbox_write_locks = fcntl
passdb {
  args = scheme=CRAM-MD5 username_format=%u /etc/dovecot/passwd
  driver = passwd-file
}
protocols = imap
service auth {
  unix_listener /var/spool/postfix/private/dovecot-auth {
    group = postfix
    mode = 0600
    user = postfix
  }
}
ssl = required
ssl_cert = </etc/pki/tls/certs/mail.crt
ssl_key = </etc/pki/tls/certs/mail.key
userdb {
  args = uid=vmail gid=vmail home=/var/spool/vmail/%d/%n
  driver = static
}
/etc/dovecot/passwdの内容
nordenlife@lumiukko.jp:{CRAM-MD5}c68d3329d0db55548a14e9d7

2012年7月7日土曜日

[RESOLVED] Recipient address rejected: User unknown in local recipient tabl

postfix + dovecotでメールサーバーを構築中ですが、以下のメッセージが表示されうまくメールが送信できません。 ユーザー認証は、dovecot側でバーチャルユーザーを使っています。
# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 mail.lumiukko.jp ESMTP Postfix
HELO mail.lumiukko.jp
250 mail.lumiukko.jp
MAIL FROM:root
250 2.1.0 Ok
RCPT TO:nordenlife@lumiukko.jp
550 5.1.1 : Recipient address rejected: User unknown in local recipient table
上記のテストで、/var/log/maillogに出力されるエラーメッセージは以下の通り。
Jul  7 23:01:17 www4298uf postfix/smtpd[19280]: NOQUEUE: reject: RCPT from localhost[127.0.0.1]: 550 5.1.1 : Recipient address rejected: User unknown in local recipient table; from= to= proto=SMTP helo=
dovecotにimapで接続する際の認証はうまく行ってる気がするのですが。。。
# telnet localhost 143
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
* OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE AUTH=CRAM-MD5 AUTH=PLAIN AUTH=LOGIN] Dovecot ready.
x LOGIN nordenlife@lumiukko.jp password
x OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS MULTIAPPEND UNSELECT CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS] Logged in
x LOGOUT
* BYE Logging out
x OK Logout completed.
Connection closed by foreign host.
postfixの認証を試してみるとうまく行きます。うーん。 ログイン認証はbase64でエンコードする必要があります。
# echo -n "nordenlife@lumiukko.jp" | base64
bm9yZGVubGlmZUBsdW1pdWtrby5qcA==
# echo -n "password" | base64
cGFzc3dvcmQ=
[root@www4298uf ~]# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 mail.lumiukko.jp ESMTP Postfix
AUTH LOGIN
334 VXNlcm5hbWU6
bm9yZGVubGlmZUBsdW1pdWtrby5qcA==
334 UGFzc3dvcmQ6
cGFzc3dvcmQ=
235 2.7.0 Authentication successful
QUIT
221 2.0.0 Bye
Connection closed by foreign host.

原因判明

local_recipient_mapsを設定していなかったことが原因でした。 /etc/postfix/main.cf
local_recipient_maps = proxy:unix:passwd.byname $alias_maps $virtual_mailbox_maps
alias_maps = hash:/etc/aliases
virtual_mailbox_maps = hash:/etc/postfix/vmailbox
ちなみに、/etc/postfix/vmailboxの内容は以下になっています。
nordenlife@lumiukko.jp lumiukko.jp/nordenlife/Maildir/

2012年6月11日月曜日

お名前.com VPS scientific linuxをインストール

お名前.comのVPS(2GB)を借りたので、Scientific Linuxをインストールしてみました。

まずはコントロールパネルから「OS再インストール」を選びます。OSとして、Scientific Linux 6.2 (64bit)を選び、ディスク構成はお好みで。私は1パーティションにします。

確認、実行と進んでいきます。
次にコントロールパネルの「コンソール画面」を選びます。


上に並んでいる「起動」をクリックします。


カーソルを一番上の「Install or upgrade an existing system」に合わせて、リターンキーを押します。


メディアチェックはどちらでも構わないと思いますので、OKかSkip好きな方を選択します。

次のインストール中の言語設定は、日本語は使えないので英語のままでも問題ないのですが、Japaneseを選んでおくと、タイムゾーン設定が少し楽になります。


次のキーボードタイプは、環境にもよりますが、jp106の日本語キーボードを選択します。


次が一番はまりやすいインストールイメージの選択画面です。正解は「URL」ですのでお間違い無く!

ネットワークの設定ですが、私はまだIPv6を使っていないので無効にしますが、どちらでも構わないと思います。


さて、次にイメージを置いてあるサーバーのURLを指定するのですが、公式サイトから最寄りのミラーサイトを見つけます。私は埼玉のKDDIにしました。64bitをインストールするので、入力するアドレスは、http://ftp.ne.jp/Linux/distributions/scientificlinux/6.2/x86_64/os/
となります。

正しく入力すれば次の画面になります。


分かりにくいのですが、右下にスクロールすると、「次⇒」というのが表示されていますので、それをクリックします。


どんどん画面を進めていきます。

タイムゾーンの設定ですが、ここは次のように設定し、デフォルトでついている「システムクロックでUTCを使用」のチェックを外した方がすっきりしていいと思います。



インストールパーティションは次のようにしておきます。


パーティションのレイアウトは、最初このようになっていると思います。


LVMをrootとhomeで分ける必要を感じないので、削除して1つにまとめます。
まず、lv_homeを選択して削除。そして、lv_rootを選択して編集。サイズを最大に変更します。



これで次へ進みます。


Write changes to diskを押して変更を書き込みます。

これで次へ進みます。


このまま次へ進みます。


必要最低限のパッケージだけをインストールしたいので、Minimalを選びます。
インストールが開始されますので、しばらくお待ち下さい。
終わったら、インストールイメージを取り出して、リブートします。

以上で無事にインストールできました。

2012年6月4日月曜日

WordPressのページタイトルをいじりたい

URLパラメータとして ?keyword=hogehoge が指定されたら、ページタイトルにそのパラメータを追加するということをやってみました。 function.phpの中で、wp_titleをhookしてあげればいいようです。
function yk_title_filter($title, $sep, $seplocation) {
    // If it's a item_search page                                                                                  
    if (isset($_GET['keyword'])) {
        if ('right' == $seplocation) {
            $title = $_GET['keyword'] . " $sep " . $title;
 } else {
            $title = $title . " $sep " . $_GET['keyword'];
 }
    }

    return $title;
}
add_filter('wp_title', 'yk_title_filter', 10, 3);

http://r.hatena.ne.jp/rpc could not be pinged. Error message: "transport error - HTTP status code was not 200"

http://r.hatena.ne.jp/rpc could not be pinged. Error message: "transport error - HTTP status code was not 200"
サービス終了のお知らせ

http://hamo-search.com/ping.php could not be pinged. Error message: "transport error - HTTP status code was not 200"

http://hamo-search.com/ping.php could not be pinged. Error message: "transport error - HTTP status code was not 200"
HARMONY SEARCHにつきまして5/6にサービスを終了いたしました。 今までのご利用ありがとうございました。
ということで、サービス終了ですので、エントリーを削除しました。

http://ping.ask.jp/xmlrpc.m could not be pinged. Error message: "transport error - could not open socket"

http://ping.ask.jp/xmlrpc.m could not be pinged. Error message: "transport error - could not open socket"
どうやらpingサーバーは廃止されているようです。 sitemapは受け付けているようなので、そちらで代用することにしました。
http://submissions.ask.com/ping?sitemap=http%3A//www.the URL of your sitemap here.xml

http://blog.goo.ne.jp/XMLRPC could not be pinged. Error message: "transport error - HTTP status code was not 200"

http://blog.goo.ne.jp/XMLRPC could not be pinged. Error message: "transport error - HTTP status code was not 200"
PingのUser-Agentを以下のように変更することで、成功するようになります。 私はWordPress Ping Optimizerを使っているので、以下のファイルを編集します。 cbnet-ping-optimizer.php
$client->useragent .= ' lumiukkoblog/1.0.0';
結果は以下の通り。
http://blog.goo.ne.jp/XMLRPC was successfully pinged
WordPressは嫌われているらしい;;

http://ping.bloggers.jp/rpc/ could not be pinged. Error message: "parse error. not well formed"

http://ping.bloggers.jp/rpc/ could not be pinged. Error message: "parse error. not well formed"
サービス終了のようです。 エントリーを削除。

CLICKYのAPIを使って逆アクセスリンクを作る

CLICKY web analyticsのAPIを使って、逆アクセスリンクを作ってみます。 詳細は、HELP->API->Analytics APIに書いてあります。
<?php
// prereq                                                                                                        
require 'scrape_func.php';
mb_language("Japanese");

// parameters                                                                                                    
$base_url = 'http://api.getclicky.com/api/stats/4';
$params['site_id'] = '99999999';
$params['sitekey'] = 'XXXXXXXXXXXXXXXX';
$params['type'] = 'links';
$params['output'] = 'xml';
$params['limit'] = 5;
$params['date'] = 'last-7-days';

// canonical string                                                                                              
$canonical_string = '';
foreach ($params as $k => $v) {
    $canonical_string .= '&' . $k . '=' . $v;
}
$canonical_string = substr($canonical_string, 1);

// make request                                                                                                  
$request = $base_url . '?' . $canonical_string;
//print_r($request);                                                                                             

// catch the response                                                                                            
$response = file_get_contents($request);
$xml = simplexml_load_string($response);
?>
<ul class="recentcomments">
<?php
for ($rank = 0; $rank < 5; $rank++) :
    $item = $xml->type->date->item[$rank];
//    var_dump($item);                                                                                           
    if (empty($item)) break;
    $url = $item->url;
    $contents = getURL($url);
    $contents = mb_convert_encoding($contents, "UTF-8", "auto");
    $contents = cleanString($contents);
    $title = getElement("title", $contents);
?>
<li class="recentcomments">
      <a href="<?php echo $url; ?>" class="url"><?php echo $rank+1;?>位 <?php echo $title; ?></a>
</li>
<?php
endfor
?>
</ul>
Clickyはスパイなど機能も充実していてお気に入りの分析サービスです。

WordPress: タグ入力の際にエンターキーで入力してしまう

WordPressのタグ入力の際に、エンターキーを押すと変換を確定するのと同時にタグも確定して入力してしまう。 それを回避するには、/wp-admin/js/post.jsの.keyupを.keypressに変換する。

記事に画像を連続して挿入できるようにする

記事に画像を追加する度に、メディア挿入の画面が閉じてしまうので、非常に効率が悪いです。

メディアアップロードを別ウィンドウに

/wp-admin/includes/media.php
        echo '<a href="' . esc_url( get_upload_iframe_src() ) . '" class="thickbox add_media" id="' . esc_attr( $editor_id ) . '-add_media" title="' . esc_attr__( 'Add Media' ) . '" onclick="return false;">' . sprintf( $context, $img ) . '</a>';
        echo "<a href=\"javascript:w=window.open('" . str_replace('TB_iframe=1', 'TB_iframe=0', esc_url(get_upload_iframe_src())) . "','','scrollbars=yes,Width=650,Height=700,top=0,left=0');w.focus();\" id=\"add_image\" title='" . esc_attr__('Add Media') . "' onclick='return true;'><img src='images/media-button-image.gif' alt='' /></a>";
もしくはこっちでもいいかもしれません。
        echo '<a href="' . esc_url( get_upload_iframe_src() ) . '" class="thickbox add_media" id="' . esc_attr( $editor_id ) . '-add_media" title="' . esc_attr__( 'Add Media' ) . '" onclick="return false;">' . sprintf( $context, $img ) . '</a>';
        echo "<a href=\"javascript:w=window.open('" . esc_url(get_upload_iframe_src()) . "','','scrollbars=yes,Width=650,Height=700,top=0,left=0');w.focus();\" id=\"add_image\" title='" . esc_attr__('Add Media') . "' onclick='return true;'><img src='images/media-button-image.gif' alt='' /></a>";

挿入した後に戻る

私は、Custom Field Templateプラグインを使用しているため、media_send_to_editorがフックされています。 そのため、修正するのは/wp-content/plugins/custom-field-template/custom-field-template.phpとなります。
        function media_send_to_custom_field($html) {
                $out =  '<script type="text/javascript">' . "\n" .
                                        '       /* <![CDATA[ */' . "\n" .
                                        '       var win = window.dialogArguments || opener || parent || top;' . "\n" .
                                        '   if ( typeof win.send_to_custom_field == "function" ) ' . "\n" .
                                        '           win.send_to_custom_field("' . addslashes($html) . '");' . "\n" .
                                        '   else ' . "\n" .
                                        '       win.send_to_editor("' . addslashes($html) . '");' . "\n" .
                    '   history.back();' . "\n" .
                                        '/* ]]> */' . "\n" .
                                        '</script>' . "\n";

                echo $out;
                exit();

history.back();を追加するということですね。 Good Luck!

APCインストールと設定

前提モジュールをインストール。
# yum -y install php53u-devel httpd-devel
Loaded plugins: fastestmirror, priorities, security
Loading mirror speeds from cached hostfile
 * epel: ftp.iij.ad.jp
 * ius: mirror.sothatswhy.org.uk
 * sl: ftp.riken.jp
 * sl-security: ftp.riken.jp
99 packages excluded due to repository priority protections
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package httpd-devel.x86_64 0:2.2.15-15.sl6.1 will be installed
--> Processing Dependency: apr-util-devel for package: httpd-devel-2.2.15-15.sl6.1.x86_64
--> Processing Dependency: apr-devel for package: httpd-devel-2.2.15-15.sl6.1.x86_64
---> Package php53u-devel.x86_64 0:5.3.10-1.ius.el6 will be installed
--> Running transaction check
---> Package apr-devel.x86_64 0:1.3.9-3.el6_1.2 will be installed
---> Package apr-util-devel.x86_64 0:1.3.9-3.el6_0.1 will be installed
--> Processing Dependency: openldap-devel for package: apr-util-devel-1.3.9-3.el6_0.1.x86_64
--> Processing Dependency: db4-devel for package: apr-util-devel-1.3.9-3.el6_0.1.x86_64
--> Processing Dependency: expat-devel for package: apr-util-devel-1.3.9-3.el6_0.1.x86_64
--> Running transaction check
---> Package db4-devel.x86_64 0:4.7.25-16.el6 will be installed
--> Processing Dependency: db4-cxx = 4.7.25-16.el6 for package: db4-devel-4.7.25-16.el6.x86_64
--> Processing Dependency: libdb_cxx-4.7.so()(64bit) for package: db4-devel-4.7.25-16.el6.x86_64
---> Package expat-devel.x86_64 0:2.0.1-9.1.el6 will be installed
---> Package openldap-devel.x86_64 0:2.4.23-20.el6 will be installed
--> Processing Dependency: cyrus-sasl-devel >= 2.1 for package: openldap-devel-2.4.23-20.el6.x86_64
--> Running transaction check
---> Package cyrus-sasl-devel.x86_64 0:2.1.23-13.el6 will be installed
---> Package db4-cxx.x86_64 0:4.7.25-16.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================
 Package                     Arch              Version                     Repository              Size
========================================================================================================
Installing:
 httpd-devel                 x86_64            2.2.15-15.sl6.1             sl-security            146 k
 php53u-devel                x86_64            5.3.10-1.ius.el6            ius                    613 k
Installing for dependencies:
 apr-devel                   x86_64            1.3.9-3.el6_1.2             sl                     175 k
 apr-util-devel              x86_64            1.3.9-3.el6_0.1             sl                      68 k
 cyrus-sasl-devel            x86_64            2.1.23-13.el6               sl                     301 k
 db4-cxx                     x86_64            4.7.25-16.el6               sl                     589 k
 db4-devel                   x86_64            4.7.25-16.el6               sl                     6.6 M
 expat-devel                 x86_64            2.0.1-9.1.el6               sl                     118 k
 openldap-devel              x86_64            2.4.23-20.el6               sl                     1.1 M

Transaction Summary
========================================================================================================
Install       9 Package(s)

Total download size: 9.6 M
Installed size: 37 M
Downloading Packages:
(1/9): apr-devel-1.3.9-3.el6_1.2.x86_64.rpm                                      | 175 kB     00:00     
(2/9): apr-util-devel-1.3.9-3.el6_0.1.x86_64.rpm                                 |  68 kB     00:00     
(3/9): cyrus-sasl-devel-2.1.23-13.el6.x86_64.rpm                                 | 301 kB     00:00     
(4/9): db4-cxx-4.7.25-16.el6.x86_64.rpm                                          | 589 kB     00:00     
(5/9): db4-devel-4.7.25-16.el6.x86_64.rpm                                        | 6.6 MB     00:01     
(6/9): expat-devel-2.0.1-9.1.el6.x86_64.rpm                                      | 118 kB     00:00     
(7/9): httpd-devel-2.2.15-15.sl6.1.x86_64.rpm                                    | 146 kB     00:00     
(8/9): openldap-devel-2.4.23-20.el6.x86_64.rpm                                   | 1.1 MB     00:00     
(9/9): php53u-devel-5.3.10-1.ius.el6.x86_64.rpm                                  | 613 kB     00:02     
--------------------------------------------------------------------------------------------------------
Total                                                                   1.6 MB/s | 9.6 MB     00:05     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : apr-devel-1.3.9-3.el6_1.2.x86_64                                                     1/9 
  Installing : expat-devel-2.0.1-9.1.el6.x86_64                                                     2/9 
  Installing : db4-cxx-4.7.25-16.el6.x86_64                                                         3/9 
  Installing : db4-devel-4.7.25-16.el6.x86_64                                                       4/9 
  Installing : cyrus-sasl-devel-2.1.23-13.el6.x86_64                                                5/9 
  Installing : openldap-devel-2.4.23-20.el6.x86_64                                                  6/9 
  Installing : apr-util-devel-1.3.9-3.el6_0.1.x86_64                                                7/9 
  Installing : httpd-devel-2.2.15-15.sl6.1.x86_64                                                   8/9 
  Installing : php53u-devel-5.3.10-1.ius.el6.x86_64                                                 9/9 

Installed:
  httpd-devel.x86_64 0:2.2.15-15.sl6.1              php53u-devel.x86_64 0:5.3.10-1.ius.el6             

Dependency Installed:
  apr-devel.x86_64 0:1.3.9-3.el6_1.2                 apr-util-devel.x86_64 0:1.3.9-3.el6_0.1           
  cyrus-sasl-devel.x86_64 0:2.1.23-13.el6            db4-cxx.x86_64 0:4.7.25-16.el6                    
  db4-devel.x86_64 0:4.7.25-16.el6                   expat-devel.x86_64 0:2.0.1-9.1.el6                
  openldap-devel.x86_64 0:2.4.23-20.el6             

Complete!
APCモジュールをインストール。
# pecl install apc
/etc/php.d/にapc.iniファイルを作成。
extension=apc.so
[APC]
apc.enabled = 1
apc.shm_size = 64M
サービスを再読込。
# service php-fpm reslaod

ab: apr_poll: The timeout specified has expired (70007)

ab -c 100 -n 100 あたりで実行していると、以下のメッセージがでて計測できない。
$ ab -c 100 -n 100 http://blog.lumiukko.jp/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking blog.lumiukko.jp (be patient)...apr_poll: The timeout specified has expired (70007)
ab -c 40 -n 100 は問題なし。ab -c 50 -n 100 はエラー。 調査中。

セッションディレクトリのパーミッション

Warning: Unknown: open(/var/lib/php/session/sess_1puk89hmb1sbsp6qi96laldnb7, O_RDWR) failed: Permission denied (13) in Unknown on line 0 Warning: Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php/session) in Unknown on line 0 /var/lib/php/sessionのパーミッションを確認。
# ls -l /var/lib/php/
合計 4
drwxrwx--- 2 root apache 4096  2月  3 08:37 2012 session
グループをnginxに変更。
# chgrp nginx session

strtotime()で警告メッセージ

PHP Warning: strtotime(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Tokyo' for 'JST/9.0/no DST' instead in /var/www/html/blog/wp-content/themes/lumiukko/make_ranking_inboundlink.php on line 16 /etc/php.iniファイルを編集。
[Date]
; Defines the default timezone used by the date functions
; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
date.timezone = "Asia/Tokyo"