Selasa, 28 Juli 2009

Apache ssl php mysql

From openSUSE

Apache with OpenSSL, MySQL, PHP on OpenSuSE 11.0

The goal of this guide is to setup a minimal OpenSUSE 11.0 system and take advantage of the tools that come shipped with it.

This may also serve as a primer for a myriad of web enabled applications available out there that make use of Apache, MySQL, and PHP. Parts of this document could be used as independent guides for installing and/or configuring each core service.

The document is just a rough guide not a sacred text. Do not blindly execute commands here without understanding them. Also, please keep in mind that your journey doesn’t end here. Observe best practices in tuning and securing your machine after performing the steps discussed in this document.

All steps were done using root via terminal interface. This may work using sudo with administrative privileges and even on a full GUI workstation environment. All packages will be installed and configured using the default shell of OpenSuSE; Bourne Again shell (bash).

Contents



Pre-requisites and additional assumptions

  • Successfully installed, configured, updated base installation of OpenSuSe 11.0
  • Most of the procedures here are OpenSuSE-centric (e.g. Yast and Zypper)
  • Basic knowledge of Unix and Unix-like environment
  • Basic knowledge of computer networks
  • Will make use of a dummy SSL certificate
  • Actual commands are preceded by the host name and its present working directory e.g.:
    linux-iifk:~ # 
  • To facilitate comparison (confusion), an actual screen output will be shown whenever a command is executed.
  • System information
Linux 2.6.25.18-0.2-pae #1 SMP 2008-10-21 16:30:26 +0200 i686 athlon i386
Linux version 2.6.25.18-0.2-pae (geeko@buildhost)
(gcc version 4.3.1 20080507 (prerelease) [gcc-4_3-branch revision 135036]
(SUSE Linux) ) #1 SMP 2008-10-21 16:30:26 +0200

MySQL

Install the MySQL database:

    linux-iifk:~ # yast2 -i mysql

Let’s configure our MySQL service to start automatically on boot-up:

    linux-iifk:~ # chkconfig --add mysql
 mysql                     0:off  1:off  2:on   3:on   4:off  5:on   6:off

Verify if run levels 3 and 5 are toggled “on” as shown above.

Start the Mysql Service:

    linux-iifk:~ # rcmysql start
Creating MySQL privilege database...
Installing MySQL system tables...
OK
Filling help tables...
OK
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h linux-iifk.site password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
Updating MySQL privilege database...
Looking for 'mysql' in: /usr/bin/mysql
Looking for 'mysqlcheck' in: /usr/bin/mysqlcheck
Running 'mysqlcheck'...
mysql.columns_priv OK
mysql.db OK
mysql.func OK
mysql.help_category OK
mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.host OK
mysql.proc OK
mysql.procs_priv OK
mysql.tables_priv OK
mysql.time_zone OK
mysql.time_zone_leap_second OK
mysql.time_zone_name OK
mysql.time_zone_transition OK
mysql.time_zone_transition_type OK
mysql.user OK
Running 'mysql_fix_privilege_tables'...
OK
Starting service MySQL done

Let’s use netstat to check if the MySQL process is running:

    linux-iifk:~ # netstat -lpt | grep "mysql"
tcp        0      0 *:mysql                 *:*                     LISTEN   2962/mysqld

As shown earlier, you can install and configure your MySQL Database manually or using a script. For this example we’re going to use mysql_secure_installation script. Also, please think of a strong password that contains at least 10 mixed case alpha-numeric characters for your MySQL root password.

    linux-iifk:~ # /usr/bin/mysql_secure_installation

A message like this will appear:

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):

Since this is a fresh installation just press enter.

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.

At this point, press enter to confirm the suggested answer (written on caps) for each question. Read them carefully as this may not be applicable for you. For this installation, the suggested answers were all accepted.

Set root password? [Y/n]
New password: (type your password, should be more than 10 characters)
Re-enter new password: (re-type your 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]


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.

... 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!

For this setup mysql root is not allowed to login remotely. Let’s verify our database installation and root account using a localhost login.

    linux-iifk:~ # mysql -u root -p
Enter password:

A successful login will yield this output:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.0.51a SUSE MySQL RPM

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>

To return to your shell, either type \q or exit and press enter. MySQL monitor will bid you farewell with a message “Bye”. :)

     mysql> \q

PHP

Installing PHP is simple:

    linux-iifk:~ # yast2 -i php5

Install additional modules for PHP (MySQL for this installation):

    linux-iifk:~ # yast2 -i php5-mysql

Note: If you need to add other PHP5 modules see additional notes section.


Apache

In this step, Apache 2.2 Server MPM Prefork will be installed.

    linux-iifk:~ # yast2 -i apache2

Install PHP module for Apache:

    linux-iifk:~ # yast2 -i apache2-mod_php5

As with most Linux distributions, package layout varies. Also, check your config file if the APACHE_MODULES line contains php5:

    linux-iifk:~ # less /etc/sysconfig/apache2

Your output should have a line similar to this:

APACHE_MODULES="actions alias auth_basic authn_file authz_host authz_groupfile authz_default authz_user authn_dbm autoindex cgi dir env expires include log_config mime negotiation setenvif ssl suexec userdir php5"

Let’s configure Apache to automatically start at boot time:

    linux-iifk:~ # chkconfig --add apache2
 apache2                   0:off  1:off  2:off  3:on   4:off  5:on   6:off

Verify if run levels 3 and 5 are toggled “on” as shown above.

Starting your httpd server Apache:

    linux-iifk:~ # rcapache2 start
Starting httpd2 (prefork)                                             done

To check what version of Apache is installed and important files/directories are located for this box:

    linux-iifk:~ # httpd2 -V
Server version: Apache/2.2.8 (Linux/SUSE)
Server built: Sep 25 2008 11:59:55
Server's Module Magic Number: 20051115:11
Server loaded: APR 1.2.12, APR-Util 1.2.12
Compiled using: APR 1.2.12, APR-Util 1.2.12
Architecture: 32-bit
Server MPM: Prefork
threaded: no
forked: yes (variable process count)
Server compiled with....
-D APACHE_MPM_DIR="server/mpm/prefork"
-D APR_HAS_SENDFILE
-D APR_HAS_MMAP
-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
-D APR_USE_SYSVSEM_SERIALIZE
-D APR_USE_PTHREAD_SERIALIZE
-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
-D APR_HAS_OTHER_CHILD
-D AP_HAVE_RELIABLE_PIPED_LOGS
-D DYNAMIC_MODULE_LIMIT=128
-D HTTPD_ROOT="/srv/www"
-D SUEXEC_BIN="/usr/sbin/suexec2"
-D DEFAULT_PIDLOG="/var/run/httpd2.pid"
-D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
-D DEFAULT_LOCKFILE="/var/run/accept.lock"
-D DEFAULT_ERRORLOG="/var/log/apache2/error_log"
-D AP_TYPES_CONFIG_FILE="/etc/apache2/mime.types"
-D SERVER_CONFIG_FILE="/etc/apache2/httpd.conf"

As shown earlier, not only the module of php5 is enabled but ssl as well; “ssl_module (shared)”. The next step would be enabling ssl module with Apache with a bash script called a2enflag.

    linux-iifk:~ # a2enflag SSL

The command above modifies your /etc/sysconfig/apache2 file from:

APACHE_SERVER_FLAGS=""

to

APACHE_SERVER_FLAGS=" SSL"

Alternatively, you can use your favorite text editor and type the " SSL" at the APACHE_SERVER_FLAGS line.

Let’s restart Apache:

    linux-iifk:~ # rcapache2 restart
 Syntax OK
Shutting down httpd2 (waiting for all children to terminate) done
Starting httpd2 (prefork) done

Check if the machine listens for http and https traffic

    linux-iifk:~ # netstat -lpt | grep "http"
 tcp        0      0 *:www-http              *:*                     LISTEN   3212/httpd2-prefork
tcp 0 0 *:https *:* LISTEN 3212/httpd2-prefork


Configure firewall (Netfilter)

The configuration of Netfilter has been done by most via command line using Iptables. For this installation, the Yast utility will be used for configuring the packet filtering instead of creating a custom iptables script.

    linux-iifk:~ # yast2

The blue Yast2 Control Center console appears on your screen. (to navigate just use arrow keys and tab button)

Press arrow down to select Security and Users:

Enlarge

Press tab to select Firewall at the right pane and press enter.

Press arrow down to highlight Allowed Services and press enter. Kindly check if the entry Apache 2 is present on Service to Allow portion.

Enlarge

Press tab (7 times) until you reach Advanced then press enter.

Press tab (2 times) until you you reach the TCP Ports and type 80 443.

Enlarge

Press tab (4 times) until you reach OK and press enter.

Press tab (3 times) until you reach Next.

A configuration summary indicating your changes to your system. Kindly check if:

+ TCP Ports: 443, 80 is shown on Open Services, Ports and Protocol

Enlarge

Press enter or F10 to confirm changes and go back to the main menu of Yast2 Control Center.

Press tab twice again and press enter to quit (F9).

To verify if your system allows http (80) and https (443) traffic to pass through your box:

    linux-iifk:~ # iptables -L | less

Check for lines similar to this:

 ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:https
 ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:http

Enabling Secure Socket Layer for Apache

Generate a dummy SSL keys for this server using a bash script gensslcert. Please take note that this command will place a file /srv/www/htdocs named CA.crt

    linux-iifk:~ # gensslcert
comment         mod_ssl server certificate
name
C XY
ST unknown
L unknown
U web server
O SuSE Linux Web Server
CN linux-iifk.site
email webmaster@linux-iifk.site
srvdays 730
CAdays 2190

creating CA key ...
710687 semi-random bytes loaded
Generating RSA private key, 2048 bit long modulus
..................+++
...........+++
e is 65537 (0x10001)

creating CA request/certificate ...
`/etc/apache2/ssl.crt/ca.crt' -> `/srv/www/htdocs/CA.crt'

creating server key ...
710687 semi-random bytes loaded
Generating RSA private key, 1024 bit long modulus
.................++++++
...++++++
e is 65537 (0x10001)

creating server request ...
creating server certificate ...
Signature ok
subject=/C=XY/ST=unknown/L=unknown/O=SuSE Linux Web Server/OU=web server/CN=linux-iifk.site/emailAddress=webmaster@linux-iifk.site
Getting CA Private Key

Verify: matching certificate & key modulus

Verify: matching certificate signature
/etc/apache2/ssl.crt/server.crt: OK

Proceed to Apache’s virtual hosts directory:

    linux-iifk:~ # cd /etc/apache2/vhosts.d/

Copy the vhost-ssl.template file to that that of your machine name. In this example it’s linux-iifk:

    linux-iifk:/etc/apache2/vhosts.d # cp vhost-ssl.template linux-iifk.conf

Restart Apache service again

    linux-iifk:~ # rcapache2 restart
Syntax OK
Shutting down httpd2 (waiting for all children to terminate) done
Starting httpd2 (prefork) done


Test the server for http connections

Let’s create a test.php file to test our installation

    linux-iifk:~ # echo "" >> /srv/www/htdocs/test.php

Open your favorite browser to check your server if it accepts http connection:

    http://ip.address.ofyour.box/test.php 

The output on your browser will be similar to this:

Enlarge

Please scroll down the output and look for for the MySQL section.

PHP Version 5.2.6

System Linux linux-iifk 2.6.25.18-0.2-pae #1 SMP 2008-10-21 16:30:26 +0200 i686
Build Date Aug 20 2008 18:19:14

--snip --

mysql
MySQL Support enabled
Active Persistent Links 0
Active Links 0
Client API version 5.0.51a
MYSQL_MODULE_TYPE external
MYSQL_SOCKET /var/lib/mysql/mysql.sock
MYSQL_INCLUDE -I/usr/include/mysql
MYSQL_LIBS -L/usr/lib -lmysqlclient


Test server for https connections

    https://ip.address.ofyour.box/test.php 

Since we have just made a dummy certificate, it should not come as a surprise if you receive warnings when you access the test page.

Enlarge

Below are messages encountered for several browsers and their suggested actions:

a) Firefox: The certificate is not trusted because the issuer certificate is unknown. (Error code: sec_error_unknown_issuer)

-- Click “Add an exception”, “Get Certificate”, “Confirm Security Exception”

b) Opera: The server’s certificate chain is incomplete and the signer(s) are not registered. Accept?

-- Click “Approve”

c) Lynx: SSL error: unable to get local issuer certificate - Continue ? (y)

-- Just press enter until you get the same output as http connection

The output should be the same as the one you saw using http connection.

Enlarge

Worth noting is the inclusion of the hardened php project :)

This server is protected with the Suhosin Patch 0.9.6.2 http://www.hardened-php.net/


Additional notes

  • Remove test.php on the www directory after you have tested the system.
  • Always restart Apache if you have loaded/removed modules by issuing:
    linux-iifk:~ # rcapache2 restart
  • This is also true for changes in PHP
  • Should you need other modules for PHP like gd just replace php5-mysql in the install command. The command should be:
    linux-iifk:~ # yast2 -i php5-gd
  • The config file for PHP is /etc/php5/apache2/php.ini
  • Log files for Apache are located at /var/log/apache2
  • Default data directory for Apache is located at /srv/www/htdocs

You can check which shared modules are present by displaying all the Apache 2 modules by:

    linux-iifk:~ # httpd2 -M
Loaded Modules:
core_module (static)
mpm_prefork_module (static)
http_module (static)
so_module (static)
actions_module (shared)
alias_module (shared)
auth_basic_module (shared)
authn_file_module (shared)
authz_host_module (shared)
authz_groupfile_module (shared)
authz_default_module (shared)
authz_user_module (shared)
authn_dbm_module (shared)
autoindex_module (shared)
cgi_module (shared)
dir_module (shared)
env_module (shared)
expires_module (shared)
include_module (shared)
log_config_module (shared)
mime_module (shared)
negotiation_module (shared)
setenvif_module (shared)
ssl_module (shared)
suexec_module (shared)
userdir_module (shared)
php5_module (shared)
Syntax OK
  • The config file for MySQL is in /etc/my.cnf
  • Log and data files are stored for mysql are stored at /var/lib/mysql
  • Acessing the MySQL server remotely should have tcp port 3306 open on your firewall
  • The command “zypper install” can be used instead of "yast2 -i"
  • Please do not forget to lock down your system.
  • Many,many,many thanks to OpenSuSE, Apache, PHP, Hardened PHP, MySQL, OpenSSL, Opera, Mozilla, Lynx, Vi, KDE, GNU and all Linux folks.

Further reading

For Yast 2 in text mode: http://www.novell.com/documentation/sled10/sled_deployment_sp1/index.html?page=/documentation/sled10/sled_deployment_sp1/data/cha_yast2.html

For tips/guide using zypper: http://en.opensuse.org/Zypper/Usage

For guides on how to configure/use Apache Version 2.2: http://httpd.apache.org/docs/2.2/

For guides on how to configure MySQL: http://dev.mysql.com/doc/refman/5.0/en/

For info about PHP: http://www.php.net/manual/en/

For info about packet filtering on GNU/Linux: http://www.netfilter.org/

For info about OpenSSL: http://httpd.apache.org/docs/2.2/ssl/ http://www.openssl.org/

Backup dan Restore di MySQL

Email Cetak PDF

I. Pendahuluan

Backup dan recovery merupakan suatu proses penyalinan dan perbaikan data untuk menghindari terjadinya kerusakan data. Hal ini mutlak diperlukan dalam administrasi database, dimana file backup ini nantinya akan menjadi master data yang sewaktu-waktu dibutuhkan. Proses backup pada MySQL dapat dilakukan secara online yaitu ketika server masih hidup atau secara offline yaitu ketika server masih aktif berjalan.

II. Merencanakan dan Mempersiapkan backup

Sebelum membackup database MySQL, ada beberapa yang harus diperhatikan agar proses backup lancar, diantaranya:
a. Menentukan seberapa sering backup
Backup merupakan program rutin seorang administrator database. Maka itu, dia harus melihat kapan waktu yang tepat untuk proses backup. Jika database itu sangat besar dan sering berubah secara konstan setiap hari, maka sebaiknya di rencanakan agar proses backup terjadi setiap hari sehingga data tersebut dapat tersimpan dengan baik. Namun, jika database itu tidak sering berubah setiap hari, maka tidak perlu dilakukan backup setiap hari, mungkin seminggu atau dua minggu sekali proses backup baru dilakukan. Namun hal di atas tergantung dari administrator itu sendiri.

b. Menamakan file backup
Seharusnya kita menamakan file backup secara teratur dan selalu memasukkan tanggal dimana backup terakhir dibuat. Misalnya database kita bernama latihan dan dibackup pada tanggal 18 januari 2009, maka seharusnya diberikan nama file backup tersebut dengan nama latihan.18012009.bkp. Namun, hal ini juga tergantung dari administrator sendiri. Namun, yang harus diperhatikan bahwa penamaan file backup tersebut juga sangat penting apalagi jika kita sering melakukan backup secara regular.

c Menyimpan File Backup
Kita seharusnya membuat kopi dari file backup kita dan menyimpan file tersebut ke computer lain atau penyimpan data yang lain seperti CD atau DVD.

III. Macam-Macam Backup

a. Backup Satu Database
Untuk membackup seluruh database maka format yang digunakan adalah:
# mysqldump -u [username] -p[password] [nama_database] > [nama-file].sql
Misal kita ingin membackup MySQL dengan passwordnya 123456 dari database latihan dan jika sudah dibackup maka namanya adalah latihan, maka perintah diatas menjadi:
# mysqldump -u root -p123456 latihan > latihan.sql

b. Backup Tabel Database
Untuk membackup satu atau lebih tabel yang ada di dalam suatu database maka formatnya adalah sebagai berikut:
# mysqldump -u [username] -p[password] [nama_database] [table1] [table2] ... > [nama-file].sql
Misal kita ingin membackup tabel tes1 dan tes2 yang berada di dalam database latihan dan jika kedua tabel itu sudah dibackup maka namanya adalah duatabel, maka perintah diatas menjadi:
# mysqldump -u root -p123456 latihan tes1 tes2 > duatabel.sql

c. Backup Dua Atau Lebih Database
Jika kita ingin membackup dua atau lebih database menjadi satu maka formatnya adalah sebagai berikut:
# mysqldump -u [username] -p[password] --database [database1] [database2] ... > [namafile].sql
Misal kita ingin menggabungkan database latihan dan database teman digabung menjadi satu dengan nama gabung, maka format diatas menjadi:
# mysqldump -u root -p123456 --database latihan teman > gabung.sql
d. Backup Seluruh Database
Jika kita ingin membackup seluruh database yang berada di Mysql, maka formatnya adalah sebagai berikut:
# mysqldump -u [username] -p[password] --all-databases > [namafile].sql
Misal kita ingin membackup seluruh database yang berada di root dengan nama gabungan, maka format di atas menjadi:
# mysqldump -u root -p123456 --all-databases > gabungan.sql

e. Backup Struktur Data
Jika kita hanya ingin membackup struktur database saja tanpa mengikutsertakan data-datanya maka formatnya sebagai berikut:
# mysqldump -u [username] -p[password] --no-data [database] > [namafile].sql
jika databasesnya lebih dari 1 maka formatnya sebagai berikut:
# mysqldump -u [username] -p[password] --no-data --databases [database1] [database2] > [namafile].sql

f. Backup Kompress Database
Jika kita ingin hasil mengkompres backup database, maka formatnya sebagai berikut:
# mysqldump -u [username] -p[password] [database] | bzip2 -c  > [namafile].sql.bz2
atau
# mysqldump -u [username] -p[password] [database] | gzip -c  > [namafile].sql.gz
Misal kita ingin membackup database latihan dan dikompress menggunakan bzip2 atau gzip dengan nama latihan, maka format di atas menjadi:
# mysqldump -u root -p123456 latihan | bzip2 -c  > latihan.sql.bz2
atau
# mysqldump -u root -p123456 latihan | gzip > latihan.sql.gzip

Jika kita ingin melakukan variasi backup seperti backup seluruh database, backup beberapa tabel saja atau yang lainnya maka hanya diubah sebelum tanda | dengan pola mengikuti format sebelumnya. Misalnya kita ingin membackup seluruh database mysql dan hasilnya berupa kompresan dengan gabungan maka perintahnya:
# mysqldump -u root -p123456 --all-databases | gzip > gabungan.sql.gzip
atau
# mysqldump -u root -p123456 --all-databases | bzip2 -c > gabungan.sql.bz2
Dan perlu diketahui bahwa hasil file kompresan bz2 mempunyai ukuran yang lebih kecil dibandingkan dengan gzip.

g. Skrip Untuk Backup
Kita juga bisa mengunakan skrip bash untuk mempermudah proses backup pada MySQL. Di bawah ini adalah salah satu contoh skrip untuk backup seluruh database:
#!/bin/sh 
mysqldump --all-databases | gzip > /var/backup/backup-`date -I`.sql.gz   
Jika ingin automasi backup, maka gunakan crontab yang caranya bisa dilihat disini.

IV. Macam-Macam Restore

a. Restore Database
Untuk merestore database maka formatnya sebagai berikut:
# mysql -u [username] -p[password]  [database] < [file_backup].sql
misal kita punya file latihan.sql ingin direstore ke database testing maka format diatas menjadi:
# mysql -u root -p123456 testing <>

b. Restore Database Hasil Kompres
Jika file backupnya berupa kompresan, maka untuk kompresan gzip formatnya seperti berikut:
# gunzip < [file_backup] | mysql -u [username] -p[password] [database]
misalnya kita ingin merestore file gabungan.sql.gzip ke database monitoring, maka format diatas berubah menjadi:
# gunzip <>
Begitu juga dengan kompresan bz2, formatnya seperti berikut:
# bunzip2 < [file_backup] | mysql -u [username] -p[password] [database]
misalnya seperti contoh diatas, maka formatnya berubah menjadi:
# bunzip2 <>

c. Backup dan Restore di Server yang lain
Bagaimana caranya agar kita ingin agar file hasil backup database yang lama dipindahkan ke database yang baru yang berbeda server atau ip? Misalnya kita mau membackup database monitoring yang ada di server 192.168.1.3 dan hasil backup akan langsung direstore ke server 192.168.1.2 di database monitoring_baru. Bisa saja kita menggunakan cara konvensional yaitu kita backup dulu database monitoring lalu file backup tersebut kita ftp ke server yang baru lalu kemudian di ekstrak di server baru tersebut. Tapi cara ini kurang efektif. Ada cara yang lebih efektif yaitu kita menggunakan format sebagai berikut:
# mysqldump -u [username] -p[password] [database] | mysql -u [username] -p[password] --host=[alamat_ip] -C [database]
Namun, cara ini mempunyai syarat yaitu adanya grant untuk memberikan hak izin akses bagi user agar dapat mengakses database. Untuk mengetahui lebih jauh tentang grant, silahkan lihat ke sini pada bagian mengakses server mysql di server lain. Di sini diandaikan kita membuat user susan untuk meminta hak akses dari IP 192.168.1.3 di server 192.168.1.2 dan kita membuat database baru yang bernama monitoring_baru.
> create database monitoring_baru; 
> grant all on testing.* to

susan@192.16This e-mail address is being protected from spambots, you need JavaScript enabled to view it .1.3 identified by 'password';
> flush privilleges; 
Jika kita sudah mendapat hak akses atau grant, maka untuk kasus format di atas menjadi:
# mysqldump -u root -p123456 monitoring | mysql -u susan -ppassword --host=192.168.1.2 -C monitoring_baru
Untuk mengeceknya gunakan perintah berikut:
>use monitoring_baru; 
> show tables;
Jika tidak ada error, maka file hasil backup database monitoring akan berada di database monitoring_baru

Referensi

www.devshed.com
http://mrothouse.wordpress.com/

Kamis, 27 Desember 2007

Setting registry...

Apabila menggunakan kedua cara sebelumnya masih juga belum berhasil kita bisa menggunakan cara dengan merubah atau memodify file registry. Perlu diketahui bahwa sebenarnya proses ini cukup riskan karena apabila terjadi kesalahan dapat menyebabkan komputer kita sedikit bermasalah. Tapi jangan khawatir karena kita akan melakukannya dengan hati-hati dan khusus untuk permasalahan hidden file saja.

Mula-mula kita masuk ke menu registry dengan mengetikkan perintah regedit pada menu run (start -> run : ketik regedit)

Setelah masuk ke menu regedit kita langsung menuju ke path : HKEY_CUURENT_USER -> software -> Microsoft -> windows -> currentversion -> explorer > advanced

1. Windows 98

Setelah masuk ke folder advanced cari file bernama Hidden kemudian klik kanan pilih modify dan ubah angka 0 pada value data menjadi 1. Maka semua file yang terhidden akan muncul di windows explorer. Penjelasan dari perubahan angka ini adalah bahwa angka 0 adalah nilai default yang dibawa oleh windows untuk menyatakan bahwa fungsi hidden file aktif sedangkan apabila kita rubah ke angka 1 maka berarti fungsi hidden tidak kita aktifkan/ disable.
Perubahan tersebut nanti dapat dilihat pada view -> folder Option -> tab view -> Hidden files, dimana perubahan angka di atas sebenarnya adalah kita melakukan perubahan pada 3 pilihan Do not show hidden files atau Do not show hidden or system files atau Show All files. Defaultnya adalah disetting ke angka 0 (Do not show hidden or system files). Lebih jelasnya adalah;
0 -> Do not show hidden or system files
1 -> Show All files
2 -> Do not show hidden files


Penjelasan dari setting untuk attribut tersebut dapat kita lihat di HKEY_LOCAl_MACHINE -> software -> Microsoft -> windows -> currentversion -> explorer -> advanced -> folder -> Hidden


2. Windows 2000,XP

Setelah masuk ke folder advanced cari file bernama Hidden kemudian klik kanan pilih modify dan ubah angka 2 pada value data menjadi 1. Kemudian cari juga file ShowSuperHidden dan ubah angka 0 pada value data menjadi 1. Maka semua file yang terhidden akan muncul di windows explorer. Penjelasan dari perubahan angka ini adalah bahwa angka 2 adalah nilai default yang dibawa oleh windows untuk menyatakan bahwa fungsi hidden file aktif sedangkan apabila kita rubah ke angka 1 maka berarti fungsi hidden tidak kita aktifkan/ disable.
Perubahan tersebut nanti dapat dilihat pada tool->folder Option->tab view->Hidden files and folders, dimana perubahan angka di atas sebenarnya adalah kita melakukan perubahan pada 2 pilihan Do not show hidden files and folders atau Show hidden files and folders.
Sedangkan perubahan angka 0 ke 1 pada file ShowSuperHidden adalah bahwa kita bermaksud untuk mendisable status hidden file system dan perubahan ini dapat dilihat pada tool->folder Option->tab view->Hide protected operating system files (Recommended). Defaultnya adalah option tersebut dipilih dan perubahan angka pada file ShowSuperHidden akan membuat option tersebut tidak dipilih/ Unchecked.

Penjelasan dari setting untuk attribut tersebut dapat kita lihat di HKEY_LOCAl_MACHINE -> software -> Microsoft -> windows -> currentversion -> explorer -> advanced -> folder
- Hidden
- SuperHidden

Hidden File...

1. Hidden file Windows XP,2000,NT

Ternyata hidden file atau file tersembunyi bisa membuat orang lumayan pusing apalagi klo orang yang
awam komputer. Sebenarnya fungsi dari hidden file adalah untuk proteksi file sistem supaya aman.
Tapi ada beberapa kasus yang akibatnya membuat file terhidden padahal file tersebut sebenarnya adalah
bukan file sistem tapi file data. Salah satu kasus yang sering terdengar adalah file terhidden karena
disebabkan oleh virus misal jenis virus W32.** atau .scr.

Ada cara yang gampang untuk menangani kasus seperti di atas salah satunya dengan memanfaatkan fungsi
attrib. Fungsi ini dijalankan dari DOS promt atau dengan perintah cmd pada start->run.
misal file yang ingin dimunculkan ada di drive D maka masuk dulu ke drive atau folder yang diinginkan lalu
ketik;
attrib /?
Nanti akan muncul intruksi yang dapat dipakai atau dijalankan untuk perintah ini. Untuk lebih jelasnya
ketik saja attrib -s -h *.* /s /d. Maka setelah itu file-file yang terhidden akan muncul di
window explorer.

Nah untuk mengembalikan ke status semula tinggal ulangi perintah tadi dan ganti tanda - sebelum huruf s
dan h dengan tanda +. Maka file akan terhidden kembali seperti posisi semula.

Fungsi di atas cukup efektif digunakan pada windows 2000,XP. sedangkan untuk windows 98 kurang akurat
hasilnya.

2. Hidden file windows 98

Pada windows 98 fungsi attrib di atas bisa juga digunakan walaupun kadang tidak berhasil. Untuk windows
98 fungsinya adalah attrib -s -h *.* /s. Tanda *.* maksudnya adalah semua jenis/ tipe file dan klo ingin
tertentu saja misal file document (*.doc) dapat digunakan untuk mengganti *.*

Sebenarnya proses menampilkan hidden file dapat juga dilakukan pada menu folder option. Dengan
memilih option show hidden files and folders maka file yang terhidden akan muncul pada windows
explorer.
Tapi untuk option show hidden files and folders masih tidak memunculkan semua file yang terhidden
khususnya file sistem yang memang penting dan default dari OSnya.
Untuk bisa memunculkan file sistem atau file lain yang mungkin belum bisa muncul dengan option show
hidden files and folders dapat digunakan option berikutnya yaitu uncheck pilihan Hide protected
operating system files (Recommended). Dengan menggunakan kedua option di atas dipastikan semua
file akan dapat dimunculkan.....selamat mencoba!!!

3. Setting registry bila kedua langkah di atas masih gagal

Bersambung..................