2008年06月06日

OpenSimサーバ構築記録その2(MySQL移行編)


● まえがき

OpenSimのデータベースは、内蔵されているSQLiteがデフォルトなんですが、
グリッドモードで動かす為にも、データベースをMySQLに変更する必要があります。
英語のサイトと格闘しながらも、意外と苦労せず動いてしまいました~。 ^^

また、OpenSimは、今日現在最新の、0.5.7-releaseで動作確認しました。
環境ファイルOpenSim.iniファイルを確認すると、ODE(Open Dynamics Engine)物理や、LSL
関連のパラメタが、前回のVer0.5.6からずいぶん増えているので、今後が楽しみです。 ^^



● 手順書を確認

教えて君にならないように、説明書はちゃんと読みます。

 【OpenSim Database support】
 http://opensimulator.org/wiki/OpenSim_Database_support

 【MySQL configuration】
 http://opensimulator.org/wiki/Mysql-config

 【Mysql-config example】
 http://opensimulator.org/wiki/Mysql-config_example



● Mysqlサーバ Ver5.0 のインストール

(1) ubuntuインストール時には指定しなかったので、パッケージ指定で、MySQLをインストールします。

root@sv:~# apt-get install mysql-server-5.0



(2) MySQLサーバの、起動用シェルスクリプトの確認

MySQL起動用シェル本体は、/etc/init.d/ 配下に、自動的に作成されます。

root@sv:~# ls /etc/init.d/mysql*
/etc/init.d/mysql* /etc/init.d/mysql-ndb* /etc/init.d/mysql-ndb-mgm*

起動用シェル本体のエイリアス(ショートカット)が、ランレベル2起動用のディレクトリ/etc/rc2.d/
配下に、自動的に作成されます。

root@sv:~# ls /etc/rc2.d/*mysql*
/etc/rc2.d/S17mysql-ndb-mgm@ /etc/rc2.d/S18mysql-ndb@ /etc/rc2.d/S19mysql@

ubuntu(Debian/Gnu Linux系OS)は、通常、GUIモード、テキストモードにかかわらず、
ランレベル2なので、OS起動時に、/etc/rc2.d/配下のシェルスクリプトが実行されます。
(ちなみに、RedHat系Fedora、CentOS等は、テキストモードがランレベル3、GUIモードが
ランレベル5、ですね。)



● MySQLサーバ Ver5.0 の起動確認

(1) MySQLのインストールに問題なければ、自動的に起動しています。

root@sv:~# ps ax | grep -i mysql
5056 ?  S   0:00 /bin/sh /usr/bin/mysqld_safe
5098 ?  Sl  0:02 /usr/sbin/mysqld



● MySQLサーバ Ver5.0 の管理者(root)権限設定

MySQLインストール直後のユーザ権限は、
 ・アノニマスユーザが有効になっている。
 ・rootで、パスワード無しでログインできる。
と、問題だらけです。

MySQLにログインして、SQL文を発行します。(パスワード無しでログインできる。。。><)

root@sv:~# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.0.51a-3ubuntu5 (Ubuntu)


mysql> select host,user,password from mysql.user;





(1) 全てのRootユーザにパスワードと権限を設定し、アノニマスユーザを削除します。

mysql> grant all on *.* to root@localhost identified by '********';
mysql> grant all on *.* to root@sv identified by '********';
mysql> grant all on *.* to root@127.0.0.1 identified by '********';

mysql> delete from mysql.user where user='';

mysql> flush privileges;



(2) 設定の確認

mysql> select host,user,password from mysql.user;



【補足】
 画面のパスワードは、ハッシュで暗号化されたものが表示されています。



(3) これで、パスワード無しでMysqlにログインできません。

root@sv:~# mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)



● データベースの作成

(1) 手順書にしたがって、SQLのcreateコマンドで、データベース(データベース名:opensim)を
  作成します。

mysql> create database opensim;
mysql> show databases;



【補足】
データベースで日本語データを扱う場合は、文字コードを指定する事が多いです。
mysql> create database データベース名 default character set utf8;



(2) テーブルは?

データベース内のテーブルはどうするんだ~?、というわけで、README.txtを読むと、
テーブルは、OpenSim起動時に自動的に作成されますよ。
と、書いてありました。 とりあえず、信じよう。

 【/usr/local/opensim/0.5.7/share/sql/mysql_README.txt】
 This directory used to contain sql files for mysql that needed to be manually sourced in order to
 set up the database tables required by OpenSim. This is no longer necessary - OpenSim now
 sets up these tables automatically.

 All you need to do is create the database that OpenSim is to use and set the configuration in
 bin/mysql_connection.ini (using bin/mysql_connection.ini.example as a reference).



● MySQL接続用環境ファイルの作成

(1) 環境ファイルのひな型が用意されているので、コピーして、viエディタで修正します。

root@sv:/usr/local/opensim/0.5.7/bin# cp mysql_connection.ini.example mysql_connection.ini
root@sv:/usr/local/opensim/0.5.7/bin# vi mysql_connection.ini

 【mysql_connection.ini】
 hostname=localhost
 database=opensim
 username=root
 password=******** <- パスワードを合わせる
 pooling=false
 port=3306



● OpenSim環境ファイルの修正

(1) OpenSim.iniは、インストール直後は、SQLiteの設定になってます。
  SQLiteの設定部分を無効(コメント化)にして、MySQLの設定部分を有効にします。

 【OpenSim.ini】
 ; asset_plugin = "OpenSim.Data.SQLite.dll"  (無効にする)
 asset_plugin = "OpenSim.Data.MySQL.dll" ; for mysql  (有効にする)
 ; inventory_plugin = "OpenSim.Data.SQLite.dll"  (無効にする)
 inventory_plugin = "OpenSim.Data.MySQL.dll"  (有効にする)
 ; userDatabase_plugin = "OpenSim.Data.SQLite.dll"  (無効にする)
 userDatabase_plugin = "OpenSim.Data.MySQL.dll"  (有効にする)



● さぁ、OpenSimの実行~。。。。。起動しませんでした。_| ̄|○

root@sv:/usr/local/opensim/0.5.7/bin# mono OpenSim.exe

14:26:20 - [ASSET SERVER]: Starting asset storage system
14:26:20 - [SQLAssetServer]: AssetStorage: Attempting to load OpenSim.Data.MySQL.dll
[APPLICATION]:
APPLICATION EXCEPTION DETECTED: System.UnhandledExceptionEventArgs
Exception: System.Exception: Error initialising MySql Database:
System.Exception: Connection error while using connection string
[Server=localhost;Port=3306;Database=opensim;User ID=root;Password=********;Pooling=false;]
---> System.NotSupportedException: CodePage 1252 not supported
 at System.
Text.Encoding.GetEncoding (Int32 codePage) [0x00000]
 at MySql.Data.MySqlClient.Driver..ctor (MySql.Data.MySqlClient.MySqlConnectionStringBuilder settings) [0x00000]
 at MySql.Data.MySqlClient.NativeDriver..ctor (MySql.Data.MySqlClient.MySqlConnectionStringBuilder settings) [0x00000]
 at MySql.Data.MySqlClient.Driver.Create (MySql.Data.MySqlClient.MySqlConnectionStringBuilder settings) [0x00000]
 at MySql.Data.MySqlClient.MySqlConnection.Open () [0x00000] --- End of inner exception stack trace ---



● エラーメッセージを見て、思い出す。

「---> System.NotSupportedException: CodePage 1252 not supported」
このエラーメッセージ、確かどこかで見かけたなぁ、と手順書を見直すと、

 【OpenSim Build Instructions】
 http://opensimulator.org/wiki/OpenSim_Build_Instructions

のページに、

 Ubuntu 8.04
 If you get an exception "System.NotSupportedException: CodePage 1252 not supported"
 running OpenSim with MySql, install also libmono-i18n2.0-cil.

OpenSim+Mysqlで、このエラーが出た場合は、libmono-i18n2.0-cil をインストールしなさい、
と、書いてあります。 ちゃんと読んどいて、よかったです。 ^^



● libmono-i18n2.0-cil のパッケージを検索して、インストール

(1) apt-cacheコマンドで、パッケージlibmono-i18n2.0-cilの検索

root@sv:~# apt-cache search libmono-i18n
libmono-i18n1.0-cil - Mono I18N libraries (1.0)
libmono-i18n2.0-cil - Mono I18N libraries (2.0)

よかった、ちゃんとありました。^^



(2) パッケージlibmono-i18n2.0-cilのインストール

root@sv:~# apt-get install libmono-i18n2.0-cil
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
以下のパッケージが新たにインストールされます:
 libmono-i18n2.0-cil




● OpenSimの起動

(1) これで、OpenSimが問題なく動きました。
  起動ログのMySQL接続部分です。コネクションが確立しています。

root@sv:/usr/local/opensim/0.5.7/bin# mono OpenSim.exe

14:38:20 - [ASSET SERVER]: Starting asset storage system
14:38:20 - [SQLAssetServer]: AssetStorage: Attempting to load OpenSim.Data.MySQL.dll
14:38:20 - [MYSQL]: Connection established
14:38:20 - [ASSETS DB]: Creating new database tables
14:38:20 - [AssetStorage]: Added MySQL Asset storage engine 1.0.0.0

14:38:21 - [AGENT INVENTORY]: Inventory storage: Attempting to load OpenSim.Data.MySQL.dll
14:38:21 - [MYSQL]: Connection established



(2) OpenSimデータベース内に、テーブルが自動的に作成されています。
  READMEに書かれているとおり、テーブルをわざわざ作る必要はありませんでしたね。

mysql> use opensim;
mysql> show tables;



【補足】
 「avatarappearance」は、Ver0.56では、外部データベースでしたが、
 Ver0.57からopensimデータベース内のテーブルに移行したようです。
 Ver0.56のOpenSim.iniファイルに存在したavatarappearanceの定義も、
 Ver0.57では無くなっています。



(3) ユーザテーブルを、確認します。
  一番最初に作った、OpenSimの管理者アカウントも、MySQLに引き継がれてます。
  なかなか親切だ。 ^^

mysql> select username,lastname,passwordHash from opensim.users;





● 一般ユーザ(自分)の作成

(1) OpenSimのコンソールから、ユーザアカウント(私ぱすてるさん)を作成します。

Region# : create user
First name [Default]:
Pastel
Last name [User]:
Flow
Password:
********



(2) MySQLにログインして、確認してみます。
  ちゃんと、ユーザアカウントができてました。

mysql> select username,lastname,passwordHash from opensim.users;





● ついにお友達ができました~、、って、ひとり二役ですけど。。。><





● ちょっと疑問

ところで、OpenSimをアップデートしたら、今あるMySQL内のデータベース(ユーザアカウントとか、
インベントリ)は引き継げるんだろうか?
OpenSimを最初にコンパイル、起動する時は、SQLiteだし。。。
アップデートのたびに、DB移行作業が発生するのはゴメンです。
要調査ですね~。



● 予定は未定

データベースをMySQLに移行した事で、Apache Web ServerとPerlやPHP、Rubyで、いろいろな、
Web-DB連携アプリが組めるようになりました。
さすがにテーブルを書き換えるような処理は危険だけど、インベントリを検索したり、一覧表示する
様なアプリを組んでみよう。
それから、やっぱり本命は、グリッドモードの仕組みや、移行方法を覚えないとね。
当分、英語と格闘です。。。><



● 補足

通常、データベースが稼動しているサーバに、グローバルIPアドレスを割り当てて、インターネットに
公開することは決してしません。 
セキュリティ対策を十分した上で、自己責任で。 (^^ゞ




【資料2.1】
データベース「opensim」内、テーブルカラム情報 (OpenSim Ver0.57)

・テーブル名:agents




・テーブル名:assets




・テーブル名:avatarappearance




・テーブル名:inventoryfolders




・テーブル名:inventoryitems




・テーブル名:userfrends




・テーブル名:users






【資料2.2】
OpenSim.iniファイル V0.5.6 -> V0.5.7差分

● V0.5.6から削除

34: ; Avatar appearance persistence
35: appearance_persist = false
36: appearance_database = "MySQL"
37: appearance_connection_string = "Data Source=localhost;Database=avatar_appearance;User ID=root;Password=xxxx;pooling=false;"


● V0.5.7から追加

71: ;permissionmodules = "DefaultPermissionsModule"
104: ; asset_plugin = "OpenSim.Data.NHibernate.dll" ; for nhibernate

115: ; inventory_plugin = "OpenSim.Data.NHibernate.dll" ; for nhibernate
116: ; Inventory Source NHibernate Example (DIALECT;DRIVER;CONNECTSTRING)
117: ; inventory_source = "SQLiteDialect;SqliteClientDriver;URI=file:Inventory.db,version=3"

123: ; userDatabase_plugin = "OpenSim.Data.NHibernate.dll" ; for nhibernate
124: ; User Source NHibernate Example (DIALECT;DRIVER;CONNECTSTRING)
125: ; user_source = "SQLiteDialect;SqliteClientDriver;URI=file:User.db,version=3"

156: [ODEPhysicsSettings]
157:
158: ;# World Settings
159:
160: ;Gravity. Feel like falling up? change world_gravityz to 9.8 instead of -9.8. m/s
161: world_gravityx = 0
162: world_gravityy = 0
163: world_gravityz = -9.8
164:
165: ; World Step size. (warning these are dangerous. Changing these will probably cause your scene to explode dramatically)
166: ; reference: fps = (0.09375/ODE_STEPSIZE) * 1000;
167: world_stepsize = 0.020
168: world_internal_steps_without_collisions = 10
169:
170: ;World Space settings. Affects memory consumption vs Collider CPU time for avatar and physical prim
171: world_hashspace_size_low = -4
172: world_hashSpace_size_high = 128
173:
174: ;Dynamic space settings Affects memory consumption vs Collider CPU time for static prim
175: meters_in_small_space = 29.9
176: small_hashspace_size_low = -4
177: small_hashspace_size_high = 66
178:
179: ; # Contact properties. (the stuff that happens when things come in contact with each other)
180:
181: ; surface layer around geometries other geometries can sink into before generating a contact
182: world_contact_surface_layer = 0.001
183:
184: ; Non Moving Terrain Contact (avatar isn't moving)
185: nm_terraincontact_friction = 255.0
186: nm_terraincontact_bounce = 0.1
187: nm_terraincontact_erp = 0.1025
188:
189: ; Moving Terrain Contact (avatar is moving)
190:
191: m_terraincontact_friction = 75.0
192: m_terraincontact_bounce = 0.05
193: m_terrainContact_erp = 0.05025
194:
195: ; Moving Avatar to object Contact
196:
197: m_avatarobjectcontact_friction = 75.0
198: m_avatarobjectcontact_bounce = 0.1
199:
200: ; Object to Object Contact and Non-Moving Avatar to object
201:
202: objectcontact_friction = 250.0
203: objectcontact_bounce = 0.2
204:
205: ; # Avatar Control
206:
207: ; PID Controller Settings. These affect the math that causes the avatar to reach the
208:
209: av_pid_derivative_linux = 3200.0
210: av_pid_proportional_linux = 1400.0
211:
212: av_pid_derivative_win = 2200.0
213: av_pid_proportional_win = 900.0;
214:
215:
216: ;girth of the avatar. Adds radius to the height also
217: av_capsule_radius = 0.37
218:
219: ; Max force permissible to use to keep the avatar standing up straight
220: av_capsule_standup_tensor_win = 550000
221: av_capsule_standup_tensor_linux = 2000000
222:
223: ; used to calculate mass of avatar.
224: ; float AVvolume = (float) (Math.PI*Math.Pow(CAPSULE_RADIUS, 2)*CAPSULE_LENGTH);
225: ; av_density * AVvolume;
226:
227: av_density = 80
228:
229: ; use this value to cut 52% of the height the sim gives us
230: av_height_fudge_factor = 0.52
231:
232: ; Movement. Smaller is faster.
233:
234: ; speed of movement with Always Run off
235: av_movement_divisor_walk = 1.3
236:
237: ; speed of movement with Always Run on
238: av_movement_divisor_run = 0.8
239:
240: ; # Object options
241: ; used in the mass calculation.
242: geometry_default_density = 10.000006836
243:
244: ; amount of ODE steps where object is non moving for ODE to automatically put it to sleep
245: body_frames_auto_disable = 20
246:
247: ; used to control llMove2Target
248: body_pid_derivative = 35
249: body_pid_gain = 25
250:
251: ; amount of time a geom/body will try to cross a region border before it gets disabled
252: geom_crossing_faiures_before_outofbounds = 5
253:
254: ; start throttling the object updates if object comes in contact with 3 or more other objects
255: geom_contactpoints_start_throttling = 3
256:
257: ; send 1 update for every x updates below when throttled
258: geom_updates_before_throttled_update = 15
259:
260: ; Used for llSetStatus. How rigid the object rotation is held on the axis specified
261: body_motor_joint_maxforce_tensor_linux = 2
262: body_motor_joint_maxforce_tensor_win = 5
263:
264: ; # Sculpted Prim settings
265:
266: ; Do we want to mesh sculpted prim to collide like they look?
267: mesh_sculpted_prim = true
268:
269: ; number^2 non-physical level of detail of the sculpt texture. 32x32 - 1024 verticies
270: mesh_lod = 32
271:
272: ; number^2 physical level of detail of the sculpt texture. 16x16 - 256 verticies
273: mesh_physical_lod = 16

279: [RestPlugins]
280: enabled = false
281: password = unknown
282: prefix = /admin
283:
284: [RestRegionPlugin]
285: enabled = false

451: ; Maximum number of llListen events we allow per script
452: ; Set this to 0 to have no limit imposed.
453: max_listens_per_script = 64


blender v2.46 Blender Foundation



同じカテゴリー(OpenSim)の記事
 再掲:OpenSim構築手順 (Linux版&OSGrid) (2009-04-18 19:33)
 OpenSimサーバ構築記録10/OSX版MySQLで動かす (2008-12-07 18:25)
 OpenSimサーバ構築記録9(MacOSXコンパイル編) (2008-11-30 16:10)
 OpenSimサーバ構築記録8 (手作りファイアウォール編) (2008-09-07 11:14)
 OpenSimサーバ構築記録その7(暗号化しなくちゃ編) (2008-08-03 11:52)
 OpenSimサーバ構築記録その6(ブレンダーで土地作り編) (2008-07-19 00:07)

Posted by ぱすてる at 22:13│Comments(2)OpenSim
この記事へのコメント
すでに、米国の一部の企業では、イントラバースやエクストラバースの導入が2007年より始まっています。
日本では、2008年末から、2009年にかけて、イントラバースやエクストラバースの導入が一般企業において始まってくるでしょう。

具体的にどのようなプラットフォームを使うようになるかは、注視するところです。

IBMとグーグルの動きが楽しみです。

OpenNebulaのOpenSimで相互接続実験はいかがでしょうか?
Posted by netkasai at 2008年06月07日 09:01
(^^) netkasaiさん。 まいどです。
こんな文字だらけの無味乾燥な記事にコメントしてくれて、ありがとうです。

>IBMとグーグルの動きが楽しみです。
近い将来、Googleが仮想空間サービスに参入してくるので楽しみですね。
品質の悪いSLよりも、期待大です。
今のうちにOpenSimや外部連携、Googleサービスの知識を身につけておこう。
OpenNebulaも調べ中です。 何か新しい情報がありましたらぜひ紹介してください。^^/
しかし、やってみたい事が多すぎ。。。><
Posted by ぱすてるぱすてる at 2008年06月08日 21:16
上の画像に書かれている文字を入力して下さい
 
<ご注意>
書き込まれた内容は公開され、ブログの持ち主だけが削除できます。