ラベル apache の投稿を表示しています。 すべての投稿を表示
ラベル apache の投稿を表示しています。 すべての投稿を表示

2012年7月24日火曜日

さくらのVPS1G移設作業 phpMyAdminインストール(CentOS6.2)



■phpMyAdminのインストール

# cd ~
# wget http://downloads.sourceforge.net/project/phpmyadmin/phpMyAdmin/3.3.8.1/phpMyAdmin-3.3.8.1-all-languages.tar.gz?r=http%3A%2F%2Fwww.phpmyadmin.net%2Fhome_page%2Fdownloads.php&ts=1291797693&use_mirror=jaist
# tar -zxvf phpMyAdmin-3.3.8.1-all-languages.tar.gz
# mv ./phpMyAdmin-3.3.8.1-all-languages /var/lib/phpMyAdmin
# cd /var/lib/phpMyAdmin/
# cp /var/lib/phpMyAdmin/config.sample.inc.php /var/lib/phpMyAdmin/config.inc.php
# vi /var/lib/phpMyAdmin/config.inc.php
# diff config.inc.php config.sample.inc.php
17c17
< $cfg['blowfish_secret'] = 'gqearjgjbykdc.sgS8zjdtayjz3fmgezncxxbRxzoxstvx'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
---
> $cfg['blowfish_secret'] = 'a8b7c6d'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
44,45c44,45
< $cfg['Servers'][$i]['controluser'] = 'pma';
< $cfg['Servers'][$i]['controlpass'] = 'hogepass';
---
> // $cfg['Servers'][$i]['controluser'] = 'pma';
> // $cfg['Servers'][$i]['controlpass'] = 'pmapass';
48,61c48,61
< $cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
< $cfg['Servers'][$i]['bookmarktable'] = 'pma_bookmark';
< $cfg['Servers'][$i]['relation'] = 'pma_relation';
< $cfg['Servers'][$i]['table_info'] = 'pma_table_info';
< $cfg['Servers'][$i]['table_coords'] = 'pma_table_coords';
< $cfg['Servers'][$i]['pdf_pages'] = 'pma_pdf_pages';
< $cfg['Servers'][$i]['column_info'] = 'pma_column_info';
< $cfg['Servers'][$i]['history'] = 'pma_history';
< $cfg['Servers'][$i]['table_uiprefs'] = 'pma_table_uiprefs';
< $cfg['Servers'][$i]['tracking'] = 'pma_tracking';
< $cfg['Servers'][$i]['designer_coords'] = 'pma_designer_coords';
< $cfg['Servers'][$i]['userconfig'] = 'pma_userconfig';
< $cfg['Servers'][$i]['recent'] = 'pma_recent';
< $cfg['Servers'][$i]['table_uiprefs'] = 'pma_table_uiprefs';
---
> // $cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
> // $cfg['Servers'][$i]['bookmarktable'] = 'pma_bookmark';
> // $cfg['Servers'][$i]['relation'] = 'pma_relation';
> // $cfg['Servers'][$i]['table_info'] = 'pma_table_info';
> // $cfg['Servers'][$i]['table_coords'] = 'pma_table_coords';
> // $cfg['Servers'][$i]['pdf_pages'] = 'pma_pdf_pages';
> // $cfg['Servers'][$i]['column_info'] = 'pma_column_info';
> // $cfg['Servers'][$i]['history'] = 'pma_history';
> // $cfg['Servers'][$i]['table_uiprefs'] = 'pma_table_uiprefs';
> // $cfg['Servers'][$i]['tracking'] = 'pma_tracking';
> // $cfg['Servers'][$i]['designer_coords'] = 'pma_designer_coords';
> // $cfg['Servers'][$i]['userconfig'] = 'pma_userconfig';
> // $cfg['Servers'][$i]['recent'] = 'pma_recent';
> // $cfg['Servers'][$i]['table_uiprefs'] = 'pma_table_uiprefs';
63c63
< $cfg['Servers'][$i]['auth_swekey_config'] = '/etc/swekey-pma.conf';
---
> // $cfg['Servers'][$i]['auth_swekey_config'] = '/etc/swekey-pma.conf';

# mkdir config
# chmod o+rwx ./config
# mysql -uroot -p < /var/lib/phpMyAdmin/examples/create_tables.sql
# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.1.61 Source distribution

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> grant all on phpmyadmin.* to pma@localhost identified by "hogepass";
Query OK, 0 rows affected (0.01 sec)

mysql> exit;
Bye



・ベーシック認証設定
# vi virtualhost.conf

以下の設定を追加する。

    ServerName phpmyadmin.example.jp
    DocumentRoot /var/lib/phpMyAdmin
        
                AuthType Basic
                AuthName "phpmyadmin.example.jp"
                AuthUserFile /etc/httpd/conf/phpmyadmin.example.jp_auth_file
                Require valid-user
        


ベーシック認証ファイル準備
# htpasswd -c /etc/httpd/conf/phpmyadmin.example.jp_auth_file hogehoge

# /etc/init.d/mysqld restart
mysqld を停止中:                                           [  OK  ]
mysqld を起動中:                                           [  OK  ]


これで
http://phpmyadmin.example.jp
にアクセスする。
ベーシンク認証後にphpMyAdminのログイン画面が表示されれば成功

http://phpmyadmin.example.jp/setup
にて設定が可能らしいがまだ未検証、どうやら設定すると"/var/lib/phpMyAdmin/config/"に設定ファイルが出来るので、手動で"/var/lib/phpMyAdmin/config.inc.php"にコピー?などして反映させるらしい。

2012年1月25日水曜日

さくらのVPSでzabbix サーバーインストール

ちょっと前に不正アクセス疑惑(無実でした(^^ゞ)とサーバートラブルで、コマンドからのログ解析やらバックアップやらで3徹してしまったり、サーバも増えてきたので、ようやく監視サーバーを設置することに

ちょっと調べた結果zabbixに決定、こちらを参考にインストール!!

すでに、apache php mysqlはインストール済です。


まずはインストールするOSのディストリビューションを確認
cat /etc/issue

CentOS release 5.5 (Final)


#と言う事なので、zabbixをyumでインストールする為に以下を実行する。

[root@examsvr ~]# rpm -ivh http://www.zabbix.jp/binaries/relatedpkgs/rhel5/i386/zabbix-jp-release-5-5.noarch.rpm


#yumでどのバージョンのzabbixがインストールされるかを確認する。
[root@examsvr ~]# alternatives --display zabbix-jp-release
zabbix-jp-release - status is auto.
 link currently points to /usr/share/zabbix-jp-release/zabbix-jp-1.8.repo     <- 1.8が選ばれてるって言ってるっぽい
/usr/share/zabbix-jp-release/zabbix-jp-1.1.repo - priority 10
/usr/share/zabbix-jp-release/zabbix-jp-1.4.repo - priority 20
/usr/share/zabbix-jp-release/zabbix-jp-1.6.repo - priority 30
/usr/share/zabbix-jp-release/zabbix-jp-1.8.repo - priority 40     <- プライオリティーが一番大きい
Current `best' version is /usr/share/zabbix-jp-release/zabbix-jp-1.8.repo.

#見た感じ1.8がインストールされるっぽい


#念の為以下を実行して、1.8を指定することも出来る。
[root@examsvr ~]# alternatives --config zabbix-jp-release
   1           /usr/share/zabbix-jp-release/zabbix-jp-1.1.repo
   2           /usr/share/zabbix-jp-release/zabbix-jp-1.4.repo
   3           /usr/share/zabbix-jp-release/zabbix-jp-1.6.repo
*+ 4           /usr/share/zabbix-jp-release/zabbix-jp-1.8.repo     <- 1.8を選択する

#以上でzabbix1.8をyumでインストールする準備が出来たらしいので次に進む


[root@examsvr ~]# yum clean all

#一応確認
[root@examsvr ~]# yum search zabbix

[root@examsvr ~]# yum install zabbix zabbix-agent zabbix-server zabbix-server-mysql zabbix-web zabbix-web-mysql
#"Complete!"が出れば成功!!

[root@examsvr ~]# vi /etc/my.cnf

default-character-set=utf8     <- 追加
# skip-character-set-client-handshake     <- ホントはこれも追加するが、mysqlがエラーになるのでコメントアウト。

#上の行を"[mysqld_safe]"より前の行に追加する。

#mysqlを再起動
[root@examsvr ~]# /etc/init.d/mysqld restart

#DB作成
[root@examsvr ~]# mysqladmin -uroot -p create zabbix --default-character-set=utf8


#zabbix用mysqlユーザ作成
[root@examsvr ~]# mysql -uroot -p
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'hogehoge';
mysql> flush privileges;
mysql> quit


#zabbix用初期データ入力
[root@examsvr ~]# mysql -uroot -p zabbix < /usr/share/doc/zabbix-server-1.8.10/schema/mysql.sql
[root@examsvr ~]# mysql -uroot -p zabbix < /usr/share/doc/zabbix-server-1.8.10/data/data.sql
[root@examsvr ~]# mysql -uroot -p zabbix < /usr/share/doc/zabbix-server-1.8.10/data/images_mysql.sql

[root@examsvr ~]# cd /etc/zabbix/
[root@examsvr zabbix]# vi zabbix.conf.php

##"http://exam.com/zabbix"などではなく、"http://zabbix.exam.com"でアクセスするためにバーチャルホスト設定
[root@examsvr zabbix]# cd /etc/httpd/conf.d/
[root@examsvr conf.d]# vi zabbix.conf

# Alias /zabbix /usr/share/zabbix

#"Alias /zabbix /usr/share/zabbix"をコメントアウト


[root@examsvr conf.d]# vi virtualhost.conf

<VirtualHost *:80>
    ServerName zabbix.exam.com
    DocumentRoot /usr/share/zabbix
    <IfModule mod_ssl.c>
        SSLEngine off
    </IfModule>
        <Location />
                AuthType Basic
                AuthName "zabbix basic"
                AuthUserFile /etc/httpd/conf/svn_auth_file
                Require valid-user
        </Location>
</VirtualHost>

#上記を追加する。


#zabbixのコンフィつファイルをapacheで更新できるようにする。
[root@examsvr conf.d]# chown apache.apache /usr/share/zabbix/conf/zabbix.conf.php

#apache再起動。
[root@examsvr conf]# /etc/init.d/httpd restart


"http://zabbix.exam.com"にアクセスして見ると順調な様子!!
こちらを参考にながれで初期設定する。


#初期設定で、rootでmysqlにアクセスするように設定してしまったので設定変更。
[root@examsvr conf]# cd /etc/zabbix/
[root@examsvr zabbix]# vi zabbix.conf.php

$DB["USER"]                             = 'zabbix';
$DB["PASSWORD"]                 = 'hogehoge';


[root@examsvr zabbix]# vi zabbix_server.conf

DBUser=zabbix     <- データベースユーザ名を設定
DBPassword=zabbix     <- コメントアウトを外してデータベースパスワードを設定
DBSocket=/var/lib/mysql/mysql.sock     <- コメントアウトを外す

#これでサーバー起動
[root@examsvr zabbix]# service zabbix-server start


[root@examsvr zabbix]# vi zabbix_agentd.conf

Server=127.0.0.1     <- ZABBIXサーバのIPアドレスを設定
Hostname=ZABBIX Server     <- Webインターフェースのホスト設定で登録するホスト名と同じ値を設定
ListenIP=127.0.0.1     <- ListenするIPインターフェースを設定

#これでクライアントが起動するので、自分を監視できる。
[root@examsvr zabbix]# service zabbix-agent start



#自動起動設定
#まずは現状確認
[root@examsvr  ~]# chkconfig --list |grep zabbix
zabbix-agent    0:off   1:off   2:off   3:off   4:off   5:off   6:off
zabbix-server   0:off   1:off   2:off   3:off   4:off   5:off   6:off

#自動起動の設定
[root@examsvr  ~]# chkconfig --level 2345 zabbix-agent on
[root@examsvr  ~]# chkconfig --level 2345 zabbix-server on

#念のため確認
[root@examsvr  ~]# chkconfig --list |grep zabbix
zabbix-agent    0:off   1:off   2:on    3:on    4:on    5:on    6:off
zabbix-server   0:off   1:off   2:on    3:on    4:on    5:on    6:off



まずは、自分を監視しながらいじってみるかな。

2011年1月3日月曜日

apacheのサーバー情報を表示しない

  • レスポンスヘッダと"Not Fount"ページのサーバー情報を制限する。
※CentOSの場合
"/etc/httpd/conf/httpd.conf"ファイルの"ServerTokens **"を"ServerTokens Prod"に変更する。
#apache再起動
/etc/init.d/httpd restart
  • エラーページのサーバー情報を表示しない。
※CentOSの場合
"/etc/httpd/conf/httpd.conf"ファイルの"ServerSignature **"を"ServerSignature Off"に変更する。
#apache再起動
/etc/init.d/httpd restart

2011年1月2日日曜日

さくらのVPSでredmine

初期設定



ログインする



  • login:root


  • pass:*******


#必要に応じてrootパスワードを変更する
passwd

#作業ユーザー作成 ※以後作業ユーザー名は"tarou"として進める
useradd -m tarou
passwd tarou
#追加したユーザーでsshログインできることを確認後作業する
exit

追加したユーザーでのssh接続で作業する

#管理者ユーザに切り替える
su -

#rootのssh接続を無効にする
cd /etc/ssh
mkdir /etc/ssh/00Backup
cp /etc/ssh/sshd_config /etc/ssh/00Backup/sshd_config_`date +%Y%m%d%H%M`
vi /etc/ssh/sshd_config


"sshd_config"に"PermitRootLogin no"を追加する
#sshdを再起動
/etc/init.d/sshd restart
#rootでsshログイン出来ないことを確認する

#iptables(ファイヤーウォール)設定
vi /root/iptables-init.sh

"iptables-init.sh"に以下コードを保存しiptables-init.shスクリプトファイルを作成する
#!/bin/sh

iptables -F
iptables -X

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

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

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

# iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT

iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT

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


#スクリプト実行
sh /root/iptables-init.sh
#設定内容を表示する。
iptables -L

結果が以下の様な感じになっていればOK
Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere
DROP       all  --  10.0.0.0/8           anywhere
DROP       all  --  172.16.0.0/12        anywhere
DROP       all  --  192.168.0.0/16       anywhere
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ssh
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:http
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED 

Chain FORWARD (policy DROP)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere

#現在の設定を保存する。
iptables-save > /etc/sysconfig/iptables
#iptableを再起動する。
/etc/rc.d/init.d/iptables restart
#iptableの起動設定を表示する。
chkconfig --list |grep iptables

結果が以下の様に2/3/4/5がonならOK
iptables        0:off   1:off   2:on    3:on    4:on    5:on    6:off

違う場合は"# chkconfig --level 2345 iptables on"を実行する。

renmineインストール



cd ~
#yum管理のプログラムを更新する。
yum update
#開発系のツールをインストールする。
yum groupinstall -y "Development Tools" 
#その他のツールをインストールする。
yum install -y openssl-devel readline-devel zlib-devel

#apacheをインストールする。
yum install -y httpd httpd-devel

mysql5.1以上とphp5.3以上をインストールする為、yumのリポジトリ設定を追加する。

cd /etc/yum.repos.d
#remiリポジトリ設定ファイルをダウンロードする。
wget http://rpms.famillecollet.com/remi-enterprise.repo
#epelリポジトリ設定をインストールする。※こちらは、入れなくてもOK
rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm

#mysqlをインストール"mysql-devel"と指定すると"i386"の古いバージョンがインストールされてしまうので"mysql-devel.x86_64"と指定する。
yum install mysql-server mysql-devel.x86_64
#リポジトリremiを指定してmysqlをアップデートする。
yum --enablerepo=remi update mysql-server mysql-devel.x86_64
#バージョン確認5.1.54以上なら成功。

インストール済みのmysqlでエラーが出る場合は、以下をコメント外して実行し、完全にアニンストールする。
# yum remove mysql mysql-server mysql-devel
# rm -Rf /usr/share/mysql
# rm -Rf /var/lib/mysql

#不要なリポジトリを無効にしてインストールする場合の例。※他のリポジトリが原因でインストールが上手くいかない場合
#yum --disablerepo=* --enablerepo=remi install mysql mysql-server


バージョンは都度変更する
cd /root
wget http://rubyforge.org/frs/download.php/71096/ruby-enterprise-1.8.7-2010.02.tar.gz
tar xzvf ./ruby-enterprise-1.8.7-2010.02.tar.gz
./ruby-enterprise-1.8.7-2010.02/installer --no-dev-docs
#"readline-devel"が無いと言われたら"yum install readline-devel"でreadlineインストール後に再試行する。

#途中"[/opt/ruby-enterprise-1.8.7-2010.01] :"このような入力プロンプトが出たら"/usr/local"を入力する。


#sqliteやPostgreSQLがインストールされていないと、以下のような警告が出る、使用しない場合は無視してOK
* sqlite3-ruby
 * pg


gem install passenger
yum install -y curl-devel
passenger-install-apache2-module

apache設定



パフォーマンス(高速化・メモリ節約など)の為、ApacheのMPMを"prefork"(※デフォルト)から"worker"に変更する。※PHPでは"prefork MPM"を推奨しているらしい



cd /etc/sysconfig/
mkdir /etc/sysconfig/00Backup
cp /etc/sysconfig/httpd /etc/sysconfig/00Backup/httpd_`date +%Y%m%d%H%M`
vi /etc/sysconfig/httpd

#httpdファイルに"HTTPD=/usr/sbin/httpd.worker"を追加又は有効化する
#passenger用にapache設定ファイルを作成する
vi /etc/httpd/conf.d/passenger.conf

設定ファイル"passenger.conf"を以下の内容で保存する。
3-5行は"# passenger-install-apache2-module"で表示された内容に置き換える
# Passenger preferences.
# Passenger-install-apache2-module to use the content that appears during installation.
#
LoadModule passenger_module /usr/local/lib/ruby/gems/1.8/gems/passenger-3.0.2/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/1.8/gems/passenger-3.0.2
PassengerRuby /usr/local/bin/ruby

# Passenger will be added to remove the HTTP header setting.
#
Header always unset "X-Powered-By" 
Header always unset "X-Rack-Cache" 
Header always unset "X-Content-Digest" 
Header always unset "X-Runtime" 

# Passenger necessary to add the settings for tuning.
#
PassengerMaxPoolSize 20
PassengerMaxInstancesPerApp 4
PassengerPoolIdleTime 3600
PassengerUseGlobalQueue on
PassengerHighPerformance on
PassengerStatThrottleRate 10
RailsSpawnMethod smart
RailsAppSpawnerIdleTime 86400
RailsFrameworkSpawnerIdleTime 0

apacheの動作確認と自動起動設定



/etc/init.d/httpd start
/sbin/chkconfig httpd on

mysql設定



mysqlの文字コードをutf8に変更する



cd /etc
mkdir /etc/00Backup
cp /etc/my.cnf /etc/00Backup/my.cnf_`date +%Y%m%d%H%M`
vi /etc/my.cnf

設定ファイル"my.cnf"に"default-character-set=utf8"を3箇所追加して以下の様に変更する。
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1

# Disabling symbolic-links is recommended to prevent assorted security risks;
# to do so, uncomment this line:
# symbolic-links=0
default-character-set=utf8

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/Mysqld.pid
default-character-set=utf8

[mysql]
default-character-set=utf8


mysql起動と自動起動設定
/etc/init.d/mysqld start
/sbin/chkconfig mysqld on


rootパスワード変更と匿名ユーザ削除



mysql -uroot

mysqlプロンプトで以下を入力
mysql> use mysql;
mysql> update user set password=password('dbpasuwaado') where user = 'root';
mysql> delete from user where user = '';
mysql> flush privileges;
mysql> exit;

redmine用ユーザ作成



mysql -uroot -p

mysqlプロンプトで以下を入力
mysql> create database db_redmine default character set utf8;
mysql> grant all on db_redmine.* to user_redmine identified by 'dbpasuwaado';
mysql> flush privileges;
mysql> exit;

Redmine作業



Redmineダウンロードと設置



cd ~
wget http://rubyforge.org/frs/download.php/73457/redmine-1.0.4.tar.gz
tar zxvf redmine-1.0.4.tar.gz
mv ./redmine-1.0.4 /var/lib/redmine
cd /var/lib/redmine

#データベース設定ファイル記述
cd config/
mkdir /var/lib/redmine/config/00Backup
cp /var/lib/redmine/config/database.yml.example /var/lib/redmine/config/database.yml
vi /var/lib/redmine/config/database.yml
#"database.yml"に以下を記述する。

# MySQL (default setup).

production:
  adapter: mysql
  database: db_redmine
  host: localhost
  username: user_redmine
  password: dbpasuwaado
  encoding: utf8

development:
  adapter: mysql
  database: redmine_development
  host: localhost
  username: root
  password:
  encoding: utf8

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: mysql
  database: redmine_test
  host: localhost
  username: root
  password:
  encoding: utf8

test_pgsql:
  adapter: postgresql
  database: redmine_test
  host: localhost
  username: postgres
  password: "postgres" 

test_sqlite3:
  adapter: sqlite3
  database: db/test.db

メール設定ファイル記述



cp email.yml.example email.yml
vi email.yml
#"email.yml"に以下を記述する。

production:
  delivery_method: :smtp
  smtp_settings:
    tls: true
    address: smtp.gmail.com
    port: 587
    domain: pj.example.jp
    authentication: :plain
    user_name: pj@example.jp
    password: mailpasuwaado

development:
  delivery_method: :smtp
  smtp_settings:
    tls: true
    address: smtp.gmail.com
    port: 587
    domain: example.jp
    authentication: :plain
    user_name: pj+dev@example.jp
    password: mailpasuwaado

#gmailのsmtpサーバはtlsを使うが、ruby1.8はtls未対応なので以下の設定を行う。
cd /var/lib/redmine/
gem install tlsmail
cd config/
cp environment.rb 00Backup/environment.rb_201101022218
vi environment.rb
#以下の2行を"environment.rb"ファイルの最後に追加する。
##require "tlsmail" 
##Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)
/etc/init.d/httpd restart

初期データベース構築



cd /var/lib/redmine/
rake config/initializers/session_store.rb
rake db:migrate RAILS_ENV=production

"rack"のバージョンエラーが出るのでバージョンダウンして再試行
gem uninstall rack
gem install rack -v 1.0.1
rake db:migrate RAILS_ENV=production

Apache-Passenger-Redmine 連携設定



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



chown -R apache:apache /var/lib/redmine

apache用virtualhosts設定ファイル記述



vi /etc/httpd/conf.d/virtualhost.conf

"/etc/httpd/conf.d/virtualhost.conf"を以下の内容で作成する。


NameVirtualHost *:80
#バーチャルドメインを設定する場合は、最初の設定がデフォルト設定となりIP接続時などには、この設定が有効になる。

    ServerName example.jp
    DocumentRoot /etc/httpd



    ServerName pj.example.jp
    DocumentRoot /var/lib/redmine/public


サーバー再起動
/etc/init.d/httpd restart


PHPインストール



#phpのインストール
yum --enablerepo=remi install php php-mysql php-devel php-mcrypt php-mbstring php-zts

#phpのバージョン確認
php -v

phpMyAdminインストール



DNSレコードにphpmyadmin.example.jpの設定をする。


cd ~
wget http://downloads.sourceforge.net/project/phpmyadmin/phpMyAdmin/3.3.8.1/phpMyAdmin-3.3.8.1-all-languages.tar.gz?r=http%3A%2F%2Fwww.phpmyadmin.net%2Fhome_page%2Fdownloads.php&ts=1291797693&use_mirror=jaist
tar -zxvf phpMyAdmin-3.3.8.1-all-languages.tar.gz
mv ./phpMyAdmin-3.3.8.1-all-languages /var/lib/phpMyAdmin
cd /var/lib/phpMyAdmin/
cp /var/lib/phpMyAdmin/config.sample.inc.php /var/lib/phpMyAdmin/config.inc.php
vi /var/lib/phpMyAdmin/config.inc.php

"config.inc.php"のCOOKIE AUTHに適当なキーを入力する
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
 * phpMyAdmin sample configuration, you can use it as base for
 * manual configuration. For easier setup you can use setup/
 *
 * All directives are explained in Documentation.html and on phpMyAdmin
 * wiki .
 *
 * @version $Id$
 * @package phpMyAdmin
 */

/*
 * This is needed for cookie based authentication to encrypt password in
 * cookie
 */
$cfg['blowfish_secret'] = 'kb7imefu24d386kj3'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

/*
 * Servers configuration
 */
$i = 0;

/*
 * First server
 */
$i++;
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'cookie';
/* Server parameters */
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
/* Select mysqli if your server has it */
$cfg['Servers'][$i]['extension'] = 'mysql';
$cfg['Servers'][$i]['AllowNoPassword'] = false;

/* rajk - for blobstreaming */
$cfg['Servers'][$i]['bs_garbage_threshold'] = 50;
$cfg['Servers'][$i]['bs_repository_threshold'] = '32M';
$cfg['Servers'][$i]['bs_temp_blob_timeout'] = 600;
$cfg['Servers'][$i]['bs_temp_log_threshold'] = '32M';

/* User for advanced features */
// $cfg['Servers'][$i]['controluser'] = 'pma';
// $cfg['Servers'][$i]['controlpass'] = 'pmapass';
/* Advanced phpMyAdmin features */
$cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
$cfg['Servers'][$i]['bookmarktable'] = 'pma_bookmark';
$cfg['Servers'][$i]['relation'] = 'pma_relation';
$cfg['Servers'][$i]['table_info'] = 'pma_table_info';
$cfg['Servers'][$i]['table_coords'] = 'pma_table_coords';
$cfg['Servers'][$i]['pdf_pages'] = 'pma_pdf_pages';
$cfg['Servers'][$i]['column_info'] = 'pma_column_info';
$cfg['Servers'][$i]['history'] = 'pma_history';
$cfg['Servers'][$i]['tracking'] = 'pma_tracking';
$cfg['Servers'][$i]['designer_coords'] = 'pma_designer_coords';
/* Contrib / Swekey authentication */
// $cfg['Servers'][$i]['auth_swekey_config'] = '/etc/swekey-pma.conf';

/*
 * End of servers configuration
 */

/*
 * Directories for saving/loading files from server
 */
$cfg['UploadDir'] = '';
$cfg['SaveDir'] = '';

?>


ディレクトリのパーミッションを変更する。
cd /var/lib/phpMyAdmin/
chown -R root.apache /var/lib/phpMyAdmin


vi /etc/httpd/conf.d/virtualhost.conf

"virtualhost.conf"に以下を追記する。

    ServerName phpmyadmin.example.jp
    DocumentRoot /var/lib/phpMyAdmin



vi /etc/sysconfig/httpd
#httpdの"HTTPD=/usr/sbin/httpd.worker"をコメントアウトする

mysql -uroot -p < /var/lib/phpMyAdmin/scripts/create_tables.sql
/etc/init.d/httpd restart

redmineレプリケーション方法

mysqlのDBダンプ
#移行元のサーバーでダンプファイルを作成する。
/usr/bin/mysqldump -u user_redmine -ppaswaado redmine | gzip >  /root/redmine_AWS_`date +%Y%m%d%H%M`.gz
#ダンプファイルの解凍
#移行先のサーバーに移したダンプファイルを解凍する。
gzip -d /home/tarou/redmine_AWS_201101010919.gz

#空のDB"db_redmine"をあらかじめ用意する。
mysql -uroot -p
mysql> create database db_redmine default character set utf8;
#DBを復元する。
mysql -p -u user_redmine db_redmine < /home/tarou/redmine_AWS_201101010919

#バージョンが違う場合は、以下でデータベース構造を変更する。
cd /var/lib/redmine/
rake db:migrate RAILS_ENV="production" 
rake db:migrate:upgrade_plugin_migrations RAILS_ENV=production
rake db:migrate_plugins RAILS_ENV=production

#redmine1.0.4のチケットで"{{author}} が{{age}}前に追加"などと出る場合は、以下を実行する。
gem install i18n -v=0.4.2
gem uninstall i18n -v=0.5.0
/etc/init.d/httpd restart
#保存ファイルの移動
cp /home/tarou/files/* /var/lib/redmine/files/
cd /var/lib/redmine/files/
chown apache.apache /var/lib/redmine/files/*

2011年1月1日土曜日

さくらのVPSでredmine-CentOS基本設定

さくらのVPSのデフォルトOSはCentOSです、
無難なOSで使い慣れているOSなので、そのまま使用するのですが、最低限のセキュリティの設定を行う。

前回で使用準備完了して、コンソールコマンドが打てる状況です。

  • デフォルトだとSSHでroot(管理者権限)ログイン出来るが、悪い人がパスワード総当たり攻撃する時に、まず狙うユーザー名がrootなので、rootでログイン出来ない様にします。

#SSHでログインするユーザー"henohenomoheji"を作る。
useradd -m henohenomoheji
#作ったユーザーのバスワードを設定する。
passwd henohenomoheji


#設定ファイルのバックアップフォルダ作成
mkdir /etc/ssh/00Backup
#変更前の設定ファイルをコピー
cp /etc/ssh/sshd_config /etc/ssh/00Backup/sshd_config_`date +%Y%m%d%H%M`

#"/etc/ssh/sshd_config"ファイルを編集viの使い方はこちら
vi /etc/ssh/sshd_config
#"sshd_config"ファイルで"#PermitRootLogin yes"を探し、その下にでも"PermitRootLogin no"を挿入する。



#sshデーモンを再起動
/etc/init.d/sshd restart


#以上で次のログインからは、rootでログイン出来ないはずなので、実際にログインを試みて確認する。
  • ボットからの攻撃をさける為に、SSHのポート番号を変える。※今回の例では5022に変更する。
#変更前の設定ファイルをコピー
cp /etc/ssh/sshd_config /etc/ssh/00Backup/sshd_config_`date +%Y%m%d%H%M`
#"/etc/ssh/sshd_config"ファイルを編集
vi /etc/ssh/sshd_config
#"sshd_config"ファイルで"#Port 22"を探し、その下にでも"Port 5022"を挿入する。


#sshデーモンを再起動
/etc/init.d/sshd restart


#以上で設定完了※ポート番号が変わるので新しいポート番号で接続する。

  • 必要なポート以外を閉じる
#iptablesの設定スクリプトを作る。
vi ~/iptables-init.sh
#以下の内容で"~/iptables-init.sh"を保存する。

#!/bin/sh

iptables -F
iptables -X

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

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

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

# iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT

iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT

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

#スクリプト実行
sh /root/iptables-init.sh
#設定結果表示
iptables -L
#結果が以下の内容なら成功

Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere
DROP       all  --  10.0.0.0/8           anywhere
DROP       all  --  172.16.0.0/12        anywhere
DROP       all  --  192.168.0.0/16       anywhere
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ssh
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:http
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED 

Chain FORWARD (policy DROP)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere

#設定結果を保存
iptables-save > /etc/sysconfig/iptables
#iptablesを再起動
/etc/rc.d/init.d/iptables restart
#iptablesの起動設定を確認
chkconfig --list |grep iptables
#結果が以下の様に2/3/4/5がonならOK
#iptables        0:off   1:off   2:on    3:on    4:on    5:on    6:off
#違っていたら以下を実行
# chkconfig --level 2345 iptables on