2011年12月16日金曜日

サーバへの接続方法

1.ファイルのアップロード/ダウンロード

Windowsで使用できるGUIのSFTPツールであるFilezillaをインストール
Download



2.DBへの接続(MySQL Workbench)

Windowsで使用できるGUIのMySQLフロントエンドツールであるMySQL Workbenchをインストール
Download

Server Administration -> New Server Instanceから接続設定作成






2011年12月15日木曜日

PHP-MySQL連携

1.php-mysqlモジュールをインストール
$ su
# yum install php-mysql
# service httpd stop
# service httpd start
# service mysqld stop
# service mysqld start 

2.以下のファイルを作成し,/var/www/html以下に配置
 index.php
<HTML>
<HEAD> 
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<TITLE>SA2011 sample</TITLE>
<STYLE TYPE="text/css"> 
<!-- 
 .table1 {
  width: 600px;
  border-collapse: collapse;
  border: 1px #111111 solid;
 }
 .table1 TD { 
  border: 1px #111111 solid;
 } 
-->
</STYLE>
</HEAD>
<BODY>

<H1>SA2011 SAMPLE PAGE</H1>

<br />

<a href='status.php?name="sato"&pass="******"'>XML SAMPLE</a>

<?php
 $db_user  = "root";
 $db_password = "******";
 $db_name = "sample";
 $db_table_name = "users";
 $db_host  = "localhost";

 $db = mysql_connect($db_host,$db_user,$db_password);
 mysql_select_db($db_name,$db);


 $strsql = "SET CHARACTER SET UTF8";
 mysql_query($strsql,$db);


 $str_sql = "select * from ".$db_table_name;
 $rs = mysql_query($str_sql,$db);
 $num = mysql_num_fields($rs);

 print("<table CLASS='table1'><tr><th colspan=7>Registered User List</th></tr>");
 print("<tr>");
 for ($i=0;$i<$num;$i++){
  print("<td><b>".mysql_field_name($rs,$i)."</b></td>");
 }
 print("</tr>");
 while($row=mysql_fetch_array($rs)){
  print("<tr>");
  for($j=0;$j<$num;$j++){
   print("<td>".$row[$j]."</td>");
  }
  print("</tr>");
 }

 print("</table>");

 mysql_free_result($rs);
 mysql_close($db);
?>

</BODY>
</HTML>

status.php
<?php
 $db_user  = "root";
 $db_password = "******";
 $db_name = "sample";
 $db_table_name = "users";
 $db_host  = "localhost";

 //create xml
 header('Content-type: text/xml; charset=utf-8');
 echo '<?xml version="1.0"?><sample>';

 $user_name = null;
 $user_pass = null;

 if(isset($_GET['name'])) {
  $user_name = $_GET['name'];
  $user_pass = $_GET['pass'];

  $con = mysql_connect($db_host,$db_user,$db_password) or die("error!");
  mysql_select_db($db_name,$con) or die("DB is not exist");
  $strsql = "SET CHARACTER SET UTF8";
  mysql_query($strsql,$con);
  $strsql = "SELECT money, item, kana, studentId FROM ".$db_table_name." WHERE name = $user_name AND pass = $user_pass;";
  $res = mysql_query($strsql,$con);

  while ($item = mysql_fetch_array($res)) {
   print "<user_status><money>".$item[0]."</money><item>".$item[1]."</item><kana>".$item[2]."</kana><studentId>".$item[3]."</studentId></user_status>";
  }

  mysql_close($con);
 }

 echo '</sample>'; 
?>

2011年12月9日金曜日

各チーム毎のFLASH設置サーバIPアドレス割り当て

FLASH設置サーバIPアドレス
IPアドレス利用者名
10.2.5.3佐藤
10.2.5.131team神崎
10.2.5.132team秋山
10.2.5.133teamふなや
10.2.5.134team中山
10.2.5.135solo間宮
10.2.5.136予備

※WEBサーバ,DBサーバ設定済みです.
※DBには初期データ投入済みです.http://10.2.5.***にアクセスして,内容を確認してください.
※ファイルの設置には,SFTPツール(Filezilla等)を利用します.
※DBへの値投入/変更には,MySQL Workbenchを利用します.

2011年12月8日木曜日

DBサーバ構築


1.MySQLサーバのインストール

#yum install mysql-server



2.MySQLサーバを,サーバ起動時に自動的に起動するように設定

#chkconfig mysqld on


3.MySQLサーバの起動
(自動起動設定が反映された次回起動以降であれば,このようなコマンドは不要ですが,今回は自動起動はなされていないため,手動にてMySQLサーバを起動)

#service mysqld start



4.MySQLサーバの初期設定
セキュリティーを確保するために,何カ所かの設定変更が必要です.
従来は個別に設定を施していましたが,それらを纏めて設定する便利な対話式のツールがあるので,今回はそちらを利用します.
(もちろん個別に設定を行ってもかまいません)

#mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL SERVERS IN PRODUCTION USE! &nbsp;PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current password for the root user. &nbsp;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):

*1 初期状態ではrootにパスワードは設定されていない為,何も入力せずenter

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] Y

*2 rootのパスワードを設定するために,Yを入力後enter

New password:********

*3 設定したいパスワードを入力後enter

Re-enter new password:********

*4 再度設定したいパスワードを入力しenter

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. &nbsp;This is intended only for testing, and to make the installation go a bit smoother. &nbsp;You should remove them before moving into a production environment. 
Remove anonymous users? [Y/n] Y

*5 初期状態で登録されている匿名ユーザーを削除する為にYを入力しenter

... Success!
Normally, root should only be allowed to connect from 'localhost'. &nbsp;This ensures that someone cannot guess at the root password from the network. 
Disallow root login remotely? [Y/n] n

*6 初期状態で設定されている外部からのrootアカウントでのログイン設定.今回はrootでのログインを許可する方針の為nを選択しenter

... skipping.
By default, MySQL comes with a database named 'test' that anyone can access. &nbsp;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] Y

*7 初期状態で用意されているtestテーブルを削除する為にYを入力しenter

- 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] Y

*8 設定ファイルを再読込するために,Yを入力しenter

... Success!
Cleaning up...
All done! &nbsp;If you've completed all of the above steps, your MySQL installation should now be secure.
Thanks for using MySQL!

5.コマンドラインからMySQLサーバに接続

#mysql -u root -p


6.MySQL Workbenchから接続

Windowsで使用できるGUIツールであるMySQL Workbenchをインストール
Download

Server Administration -> New Server Instanceから接続設定作成






2011年12月1日木曜日

初期設定~WEBサーバ構築


1.OS及びKernelのVersion確認
#cat /etc/issue
#uname -a

2.メモリ使用量の確認
#free -m

3.ディスク使用量の確認
#df -H

4.稼働しているプロセスの確認
#ps aux

5.インストールされているアプリケーションの確認
#rpm -aq

6.installされているアプリケーションの数を表示
#rpm -aq | wc -l

7.自動起動設定されているアプリケーションの確認
#chkconfig

8.不要なサービスの自動起動設定解除
#chkconfig (サービス名) off

例)chkconfig ip6tables off

9.yum準備
#yum install yum-fastestmirror
#yum install yum-utils

10.NTPインストール
#yum install ntp
#chkconfig ntpd on
#chkconfig | grep ntp
#service ntpd start

11.PHPインストール
#yum install php
#vi /etc/php.ini
memory_limit = 16M ; Maximum amount of memory a script may consume

12.Webサーバ(httpd)インストール
#yum install httpd
#chkconfig httpd on
#service httpd start

13.Firewall設定
iptablesのルール初期化
# /sbin/iptables -F

現在のルール確認
#iptables -L

fire wallにルール追加
#vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80    -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306  -j ACCEPT

service iptables restart

13.動作確認
ブラウザから以下のアドレスにアクセスし,テスト画面が表示されることを確認
http://10.2.5.***