Jump to content

How To Install an Metin2 Server on FreeBSD 9 64-bit


Rumor

Recommended Posts

M2 Download Center

This is the hidden content, please
( Internal )

This guide will walk you through each step of installing the necessary daemons for a Metin2 server on FreeBSD. Asking for help setting up Metin2 on the official FreeBSD forums is not permitted, I suggest if you have issues to ask in this forum only. You may not need to install cURL, it depends on whether or not you'll host your website on the same server and use things that require cURL (such as automatic paypal transactions). 
 
It's recommended to host your website on a separate web server and not share the IP with anyone then run it through CloudFlare. A guide will be posted soon in these forums on how to run your website through CloudFlare while preventing CloudFlare IP resolvers from functioning. However, if you do run your website on another server I would recommend hosting it in the same datacenter because you'll need to use Remote MYSQL to access your database.
 

- For sake of simplicity I'll be using "ee editor" for this guide. Most new people don't like vi anyway. If you're already familiar with vi, feel free to use that to edit text inside files instead.

- To transfer files to and from your server, use WinSCP.

- To enter commands into your server, use PuTTy. Please note that when the system asks you for a password in PuTTy you won't see it as you type it on the screen, be precise!

- Pressing the TAB key in PuTTy will auto-complete as much as possible in the directory you're in.


Downloads
Libs: https://mega.co.nz/#!rExCyBba!dho0EjPjjHLzARsaQ3XU2yY38mpRBrf0YpilLo3aC4c

 

1. Updating Ports
 

portsnap fetch extract
portsnap update

 
 
2. Installing Python 2.7
 

cd /usr/ports/lang/python27
make -DBATCH install clean

pro tip: Use the "-DBATCH" flag for a default installation of the port. Skip all those annoying prompts during installation.


3. Standard C++ Libraries

 

 

 

 

 

 

 

 

 

 

 

 

 

fetch ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/amd64/9.1-RELEASE/lib32.txz
tar Jxpvf lib32.txz -C /
rm lib32.txz

Unrar "Libs.rar" and put the files in the "/usr/lib32" directory.


4. Compat7x

Because Metin2 was originally meant to be run on FreeBSD 7, we need this so that it's compatible with FreeBSD 9.
 


 

cd /usr/ports/misc/compat7x && make -DBATCH install clean
pkg_add -r compat7x-amd64

5. Install & Configure MySQL 5.6 server

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

cd /usr/ports/databases/mysql56-server
make BUILD_OPTIMIZED=yes BUILD_STATIC=yes
make WITH_XCHARSET=all install clean

 
Now we make it start on each startup of the system.

ee /etc/rc.conf

Add a new line:

mysql_enable="YES"

Press ESC then save and close the file.
 

service mysql-server start
/usr/local/bin/mysqladmin -uroot password 'enterpassword'

pro tip: "enterpassword" should be the password you choose, don't use "enterpassword" as your password. A long string of lower case and capital letters and numbers is the safest bet. Don't use words that can be found in a dictionary. Don't use passwords which are the same as other passwords of yours.

You may not need to do this, but when I got an OVH server it messed up the installation of mysql (on 9.2). If you get an error about the mysql user account with the step above, just do this:
 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

pwd_mkdb -p /etc/master.passwd
chown -R mysql /var/db/mysql && chgrp -R mysql /var/db/mysql

Then repeat the step.
6. Adding your server files and Metin2 Database

Extract your game.tar.gz containing all the Metin2 server files somewhere in your server. This is all you have to do to extract a .tar.gz file:



 

tar -zxvf filename.tar.gz

You should have your metin2 database inside of a tarball (.tar.gz file). For structure, it doesn't really matter as long as once you extract your tarball on your server it follows this file hierarchy:
Maeixtd.png

Now you should change the group and ownership of some files for your database:
 

service mysql-server stop
chown -R mysql /var/db/mysql && chgrp -R mysql /var/db/mysql
service mysql-server start

Setup an account for you to login to the database via Navicat and an account for your game cores to interact with your database using. For this example I'll use the username "rumor" for my account and "metin2" for the game core's account. Every password in this example will be "password" but please DO NOT use this as your password! If you have a static IP address and wish to restrict access to the database only to your IP, change the "%" sign to your IP. The "%" sign indicates that any IP address is allowed to connect to the database using the specified credentials.

mysql -p

Now enter the password you set with mysqladmin earlier... and you will see this prompt:

mysql>

This is where we set the actual permissions for the accounts up.

GRANT ALL PRIVILEGES ON *.* TO 'rumor'@'%'
IDENTIFIED BY 'password' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'metin2'@'localhost'
IDENTIFIED BY 'password' WITH GRANT OPTION;
quit

pro tip: remember (or write down) this information because you will need it later.

Setup your CONFIG files under each channel folder and the "auth" folder. All of these are found inside the Metin2 server files.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

PLAYER_SQL: localhost metin2 password player
COMMON_SQL: localhost metin2 password common
LOG_SQL: localhost metin2 password log

The conf.txt file looks a little bit different and it's found in the "db" folder of your Metin2 server files.

SQL_ACCOUNT = "localhost account metin2 password 0"
SQL_PLAYER = "localhost player metin2 password 0"
SQL_COMMON = "localhost common metin2 password 0"
SQL_HOTBACKUP = "localhost hotbackup metin2 password 0"

 
~~~~ STOP HERE IF YOU'RE RUNNING YOUR WEB SERVER SOMEWHERE ELSE ~~~~

 
7. Setting up web server for website and/or patcher
 
 
Install nginx:

cd /usr/ports/www/nginx
make install clean

 
Make sure these are selected with space bar:

[X] HTTP_MODULE               Enable HTTP module
[X] HTTP_ADDITION_MODULE      Enable http_addition module
[X] HTTP_CACHE_MODULE         Enable http_cache module  
[X] HTTP_GEOIP_MODULE         Enable http_geoip module
[X] HTTP_GZIP_STATIC_MODULE   Enable http_gzip_static module
[X] HTTP_IMAGE_FILTER_MODULE  Enable http_image_filter module 
[x] HTTP_PERL_MODULE          Enable http_perl module 
[X] HTTP_REALIP_MODULE        Enable http_realip module
[X] HTTP_REWRITE_MODULE       Enable http_rewrite module  
[X] HTTP_STATUS_MODULE        Enable http_stub_status module

Press "Enter" when ready to continue.
 
Install libtool

cd /usr/ports/devel/libtool
make install clean

 
Install php5

cd /usr/ports/lang/php5
make config

Make sure the following is selected with space bar then press "Enter":

[X] FPM        Build FPM version (experimental)

Leave everything else default.
 
then do this:

make install clean

 
~~~~
If you need cURL support then do this, if not then skip this step:

cd /usr/ports/lang/php5-extensions
make config

Make sure that the "CURL Support" is selected then press "Enter".
 
Then do the installation and clean the directory:

make -DBATCH install clean

~~~~
 
Time to configure your php.ini file...

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini

Edit /usr/local/etc/php.ini in WinSCP using Notepad++. Firstly, set your "date.timezone" to the appropriate one. Choose from this list: http://php.net/manual/en/timezones.php
 
Next, if you have something that needs to run large MYSQL queries you may run into some issues. Some website packages also can cause these problems. The issue is with memory usage. For security reasons there are limitations set on how much memory php is allowed to use. I suggest only modifying this IF you have problems loading memory-intensive pages. Just try to raise it a bit until it works, don't raise it to an excessively high number. I had to set mine to "512M" to make my queries work in my patcher. It can be set by just inputting numbers and they will be recognized as bytes, or you could use K, M, or G. 

memory_limit = 512M

 
Installation of php-mysql5:

cd /usr/ports/databases/php5-mysql 
make -DBATCH install clean

 
If you've gotten this far, congratulations.. you're almost done!
 
You need to create a folder for your website like this:

mkdir /usr/local/www/nginx/domain.com

Set the owner and permissions:

chown www:www /usr/local/www/nginx/domain.com
chmod 755 /usr/local/www/nginx/domain.com

 
Customize this file to your needs and upload it to /usr/local/etc/nginx:
 

Spoiler

user  www;
worker_processes  2;
 
 
events {
    worker_connections  1024;
    multi_accept on;
}
 
worker_rlimit_nofile    20000;
 
http {
    include       mime.types;
    default_type  application/octet-stream;
 
   #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
   #                  '$status $body_bytes_sent "$http_referer" '
   #                  '"$http_user_agent" "$http_x_forwarded_for"';
 
   #access_log  logs/access.log  main;
    sendfile    on;
    keepalive_timeout  10;
    client_max_body_size 64M;
    server_tokens off;
    client_body_buffer_size 128k;
    keepalive_requests 10000;
    reset_timedout_connection on;
    send_timeout 5;
    open_file_cache max=20000 inactive=20s;
    open_file_cache_valid 30s;
    open_file_cache_min_uses 2;
    open_file_cache_errors on;
    directio  50m;
 
        server {
                listen 80;
                server_name www.patch.mysite.com;
                rewrite ^(.*)$ $scheme://patch.mysite.com$1;
        }
 
        server {
                types {
                        application/octet-stream lz;
                        text/plain xml;
                        text/css css;
                }
 
                listen       80;
                server_name  patch.mysite.com;
                root /usr/local/www/nginx/patch.mysite.com;
                rewrite  ^/$  /index.php  permanent;
                index  index.php;
             
                location ~*  .(jpg|jpeg|png|gif|ico|css|js)$ {
                        expires 7d;
                }
               
      location ~ .php$ {
         try_files $uri =404;
         fastcgi_split_path_info ^(.+.php)(/.+)$;
         fastcgi_index index.php;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
         fastcgi_pass 127.0.0.1:9000;
         include fastcgi_params;
      }
 
                location ~ /. {
                        deny all;
                }
 
        }
}
 
 


 
If you're using cloudflare, uncomment the lines 38-57 by removing the "#". The reason for this is to ensure you get the real user IP in your logs rather than cloudflare's IP. 
 
If you want to allow directory listing.. ie: [url=http://domain.com/files]http://domain.com/files to present a visitor with a list of files they can access/download then uncomment lines 63 and 73.
 
You MUST change the domain name to your own!
 
Now you need to enable startup of php-fpm and nginx whenever your server is booted:

ee /etc/rc.conf

Add these lines:

php_fpm_enable="YES"
nginx_enable="YES"

Start your services:

service php-fpm start
service nginx start

Upload your website files to /usr/local/www/nginx/domain.com

Edited by Metin2 Dev
Core X - External 2 Internal
  • Metin2 Dev 112
  • kekw 1
  • Eyes 6
  • Facepalm 1
  • Dislove 1
  • Angry 2
  • Sad 2
  • Smile Tear 1
  • Think 2
  • Confused 3
  • Scream 3
  • Lmao 1
  • Good 74
  • Love 15
  • Love 160
Link to comment
Share on other sites

  • 2 weeks later...
  • 4 weeks later...

@iRemix, no "pkg_add" isn't rly secure, cause it won't compile the mysql files, so if the host uses modified kernels it could be, that the mysql bin doesn't work anymore with this kind of install!

@Rumor, please don't give the external mysql users grant option... that's evil and not rly safe! You additionaly shouldn't give the M2 User grant option, cause, FOR WHAT HE SHOULD NEED IT?! Hacking database, if u useing a modified game/db core with evil backdoor functions?

 

And for the Web-server ... I personally am of the opinion, FreeBSD isn't an OS for webhosting... I often had problems cause of missing pkg's or s.th. else... 

 

Kind regards

  • Love 2
Link to comment
Share on other sites

  • 3 weeks later...

 

One question, why this?

1
2
3
cd /usr/ports/databases/mysql56-server
make BUILD_OPTIMIZED=yes BUILD_STATIC=yes
make WITH_XCHARSET=all install clean
 
 
 

besides this?  What is the difference?

 

1
2
cd /usr/ports/databases/mysql56-server
make install clean
 
 
 
 
 

 

 

I carried this with me since verison 8 because it was having issues installation mysql50-server. This seemed to be the only solution to the problem, and I always do it now and never have any issues. Maybe it will work for people now in version 9 but in 8 I had to do this or the database had problems.

  • Love 1
Link to comment
Share on other sites

@iRemix, no "pkg_add" isn't rly secure, cause it won't compile the mysql files, so if the host uses modified kernels it could be, that the mysql bin doesn't work anymore with this kind of install!

[...]

That would only be an issue if you had changed APIs. Since just building an own kernel with special options/built-in drivers doesn't do that, there's no reason not to use the binary packages unless you need to change config. options (less dependencies, extra features, ...)

[...]This way the software will be optimized for your particular setup.

Only if you added extra optimization flags (eg. -Ofast etc.) to your /etc/make.conf (which isn't recommended since you can break ports that are incompatible with the settings you added)
  • Love 2
Link to comment
Share on other sites

 

 

One question, why this?

1
2
3
cd /usr/ports/databases/mysql56-server
make BUILD_OPTIMIZED=yes BUILD_STATIC=yes
make WITH_XCHARSET=all install clean
 
 
 

besides this?  What is the difference?

 

1
2
cd /usr/ports/databases/mysql56-server
make install clean
 
 
 
 
 

 

 

I carried this with me since verison 8 because it was having issues installation mysql50-server. This seemed to be the only solution to the problem, and I always do it now and never have any issues. Maybe it will work for people now in version 9 but in 8 I had to do this or the database had problems.

 

What kind of problems you had?

  • Love 1
Link to comment
Share on other sites

  • 1 month later...
  • 2 weeks later...

>SOLVED<*

 

 

 

Hi Rumor, i got a problem, but in first place, thanks fo do that tutorial :D

the issue i become is this one:

root@ns3306138:~ # pwd_mkdb -p /etc/master.passwd
root@ns3306138:~ # chown -R mysql /var/db/mysql && chgrp -R mysql /var/db/mysql
root@ns3306138:~ # service mysql-server start
Starting mysql.
root@ns3306138:~ # /usr/local/bin/mysqladmin -uroot password 'passpasspass'
/usr/local/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!

maybe you or someother knows soemthing about it? im using freebsd 9.2, should i downgrade it to 9.0? 

i have tryed with mysql 5.1 and 5.5, same issue :/

thanks for reading! :)

PS: after this error message, i make:

 

root@ns3306138:~ # service mysql-server status
mysql is not running.
 

in rc.conf i got: 

 

sshd_enable="YES"
ntpdate_enable="YES"
ntpdate_hosts="IP.IP.IP.IP.IP"
fsck_y_enable="YES"
background_fsck="NO"
named_enable="YES"
firewall_enable="YES"
firewall_script="/etc/ipfw.rules"
 
# Set dumpdev to "AUTO" to enable crash dumps, "NO" to disable
dumpdev="NO"
 
ifconfig_em0="inet IP.IP.IP.IP.IP netmask 255.255.255.0 broadcast IP.IP.IP..255"
defaultrouter="IP.IP.IP.IP.IP"
 
# Fail2Ban
fail2ban_enable="YES"
 
 
# MySQL
mysql_enable="YES"




*after reading the error log of the mysql, i noticed that i puted into /var/db/mysql my old mysql files before that new installation, little fail ^^U

 

Thanks again for your work, making this tutorial with that kind of commands, what we [with "we" i mean us, the hobbie metin2 developers(can i call myself a developer... i think no xD)] doesn´t know the great part of them. :)

 
  • Metin2 Dev 1
  • Love 1
Link to comment
Share on other sites

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.