Preseljenje WordPressa na Squeeze
Povod članku je tema koja je trenutno aktualna, a to je nadogradnja Carnet Debiana sa distribucije Lenny na Squeeze. Na serveru ustanove "vrtim" jedan konferencijski site na WordPressu, pa me zanimalo kako će se dogradnja odraziti na rad Apache web servera, baze MYSQL i programskog alata PHP.
Poslušao sam savjet kolege koji mi je predložio da podignem testni server na kojem ću ispitati uspješnost prebacivanja mysql baze na višu verziju, ne dirajući produkcijski server.
Za potrebe testiranja instalirao sam "čist" Debian Carnet Squeeze testni server uz pomoć uputa u članku Želje Boroša.
Prekopirao sam cijeli public_html sa WordPress instalacijom na novi server u kreirani korisnički direktorij /home/korisnik/public_html pazeći na dozvole za pristup datotekama.
Zatim sam napravio backup mysql baza:
# mysqldump --all-databases >/var/backups/mysqldump.sql.carnet-upgrade
Zanimale su me razlike između verzija paketa Debian Lenny i Debian Squeeze. Usporedbom trenutnog servera i testnog dolazimo do slijedećeg stanja:
dpkg -l | grep mysql
ii libdbd-mysql-perl 4.007-1+lenny1 A Perl5 database interface to the MySQL data
ii libmysqlclient15off 5.0.51a-24+lenny5 MySQL database client library
ii mysql-client-5.0 5.0.51a-24+lenny5 MySQL database client binaries
ii mysql-cn 2:5.0.51-2lenny1 MySQL database server
ii mysql-common 5.0.51a-24+lenny5 MySQL database common files
ii mysql-server-5.0 5.0.51a-24+lenny5 MySQL database server binaries
ii php5-mysql 5.2.6.dfsg.1-1+lenny16 MySQL module for php5
dpkg -l | grep mysql
ii libdbd-mysql-perl 4.016-1 Perl5 database interface to the MySQL database
ii libmysqlclient16 5.1.61-0+squeeze1 MySQL database client library
ii mysql-client-5.1 5.1.61-0+squeeze1 MySQL database client binaries
ii mysql-cn 2:5.1.49-1 MySQL database server
ii mysql-common 5.1.61-0+squeeze1 MySQL database common files, e.g. /etc/mysql/my.cnf
ii mysql-server-5.1 5.1.61-0+squeeze1 MySQL database server binaries and system database setup
ii mysql-server-core-5.1 5.1.61-0+squeeze1 MySQL database server binaries
ii php5-mysql 5.3.3-7+squeeze8 MySQL module for php5
Znači imamo različite verzije mysql servera i mysql modula za php5. Prema sugestijama preseljenje baze iz niže u višu verziju trebalo bi funkcionirati. Prenesemo mysqldump.sql.carnet-upgrade na testni server i pokrenemo naredbu.
# mysql -u root -p < mysqldump.sql.carnet-upgrade
Restore baze prolazi bez vidljivih problema međutim pri pokušaju pokretanja mysqld servisa javljaju se višestruke greške. Evo izvoda iz logova.
/etc/mysql/debian-start[8043]: /usr/bin/mysqlcheck: Got error: 1045: Access denied for user 'debian-sys-maint'@'localhost' (using password: YES) when trying to connect
Ova se greška javlja kad preselimo MYSQL instalaciju sa jednog Debian servera na drugi i promijene se korisnički podaci. Debian kreira korisnika "debian-sys-maint" sa slučajnom lozinkom. Taj podatak možemo potražiti u /etc/mysql/debian.cnf
# cat /etc/mysql/debian.cnf | grep password
password = fU6o26UB114UCVg0
Zamijenimo lozinku u bazi s novom koju smo izlistali u prethodnoj naredbi:
# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 97
Server version: 5.1.61-0+squeeze1 (Debian)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY 'fU6o26UB114UCVg0' WITH GRANT OPTION;
Nakon resetiranja lozinke mysql bi se trebao pokrenuti. No u logovima ima još grešaka koje se javljaju kod pokretanja:
Mar 21 10:48:52 stroj mysqld: 120321 10:48:52 [Note] /usr/sbin/mysqld: Shutdown complete
Mar 21 10:48:52 stroj mysqld:
Mar 21 10:48:52 stroj mysqld_safe: mysqld from pid file /var/run/mysqld/mysqld.pid ended
Mar 21 10:48:57 stroj mysqld_safe: Starting mysqld daemon with databases from /var/lib/mysql
Mar 21 10:48:57 stroj mysqld: 120321 10:48:57 [Note] Plugin 'FEDERATED' is disabled.
Mar 21 10:48:57 stroj mysqld: 120321 10:48:57 InnoDB: Initializing buffer pool, size = 8.0M
Mar 21 10:48:57 stroj mysqld: 120321 10:48:57 InnoDB: Completed initialization of buffer pool
Mar 21 10:48:57 stroj mysqld: 120321 10:48:57 InnoDB: Started; log sequence number 0 44233
Mar 21 10:48:57 stroj mysqld: 120321 10:48:57 [ERROR] Column count of mysql.db is wrong. Expected 22, found 20. The table is probably corrupted
Mar 21 10:48:57 stroj mysqld: 120321 10:48:57 [ERROR] mysql.user has no `Event_priv` column at position 29
Mar 21 10:48:57 stroj mysqld: 120321 10:48:57 [ERROR] Event Scheduler: An error occurred when initializing system tables. Disabling the Event Scheduler.
Mar 21 10:48:57 stroj mysqld: 120321 10:48:57 [Note] /usr/sbin/mysqld: ready for connections.
Mar 21 10:48:57 stroj mysqld: Version: '5.1.61-0+squeeze1' socket: '/var/run/mysqld/mysqld.sock' port: 3306 (Debian)
Mar 21 10:48:58 stroj /etc/mysql/debian-start[3434]: Upgrading MySQL tables if necessary.
Mar 21 10:48:58 stroj /etc/mysql/debian-start[3437]: /usr/bin/mysql_upgrade: the '--basedir' option is always ignored
Mar 21 10:48:58 stroj /etc/mysql/debian-start[3437]: Looking for 'mysql' as: /usr/bin/mysql
Mar 21 10:48:58 stroj /etc/mysql/debian-start[3437]: Looking for 'mysqlcheck' as: /usr/bin/mysqlcheck
Mar 21 10:48:58 stroj /etc/mysql/debian-start[3437]: This installation of MySQL is already upgraded to 5.1.61, use --force if you still need to run mysql_upgrade
Mar 21 10:48:58 stroj /etc/mysql/debian-start[3444]: Checking for insecure root accounts.
Mar 21 10:48:58 stroj /etc/mysql/debian-start[3448]: Triggering myisam-recover for all MyISAM tables
Mar 21 10:48:58 stroj mysqld: 120321 10:48:58 [ERROR] Column count of mysql.proc is wrong. Expected 20, found 16. The table is probably corrupted
Pogledajmo što se događa nakon što pokrenemo mysql.
# /etc/init.d/mysql start
Starting MySQL database server: mysqld.
Checking for corrupt, not cleanly closed and upgrade needing tables..
ERROR 1577 (HY000) at line 1: Cannot proceed because system tables used by Event Scheduler were found damaged at server start
ERROR 1547 (HY000) at line 1: Column count of mysql.proc is wrong. Expected 20, found 16. The table is probably corrupted
Tražeći informacije o ovom problemu nailazim na izveštaje o bugovima "Upgrading from 5.0 to 5.1, mysql crashes during mysql_upgrade". Preporučaju se standardne provjere koje mogu izvršiti na slijedeći način.
# mysql_upgrade -u root -p
Enter password:
Looking for 'mysql' as: mysql
Looking for 'mysqlcheck' as: mysqlcheck
This installation of MySQL is already upgraded to 5.1.61, use --force if you still need to run mysql_upgrade
root@stroj:~# mysql_upgrade --force -u root -p
Enter password:
Looking for 'mysql' as: mysql
Looking for 'mysqlcheck' as: mysqlcheck
Running 'mysqlcheck' with connection arguments: '--port=3306' '--socket=/var/run/mysqld/mysqld.sock'
Running 'mysqlcheck' with connection arguments: '--port=3306' '--socket=/var/run/mysqld/mysqld.sock'
foundry.wp_foundrycommentmeta OK
foundry.wp_foundrycomments OK
foundry.wp_foundryflag_album OK
foundry.wp_foundryflag_comments OK
foundry.wp_foundryflag_gallery OK
foundry.wp_foundryflag_pictures OK
foundry.wp_foundrylinks OK
foundry.wp_foundryngg_album OK
foundry.wp_foundryngg_gallery OK
foundry.wp_foundryngg_pictures OK
foundry.wp_foundryoptions OK
foundry.wp_foundrypostmeta OK
foundry.wp_foundryposts OK
foundry.wp_foundryterm_relationships OK
foundry.wp_foundryterm_taxonomy OK
foundry.wp_foundryterms OK
foundry.wp_foundryusermeta OK
foundry.wp_foundryusers OK
mysql.columns_priv OK
mysql.db OK
mysql.event OK
mysql.func OK
mysql.general_log
Error : You can't use locks with log tables.
status : OK
mysql.help_category OK
mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.host OK
mysql.ndb_binlog_index OK
mysql.plugin OK
mysql.proc OK
mysql.procs_priv OK
mysql.servers OK
mysql.slow_log
Error : You can't use locks with log tables.
status : 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
phpmyadmin.pma_bookmark OK
phpmyadmin.pma_column_info OK
phpmyadmin.pma_designer_coords OK
phpmyadmin.pma_history OK
phpmyadmin.pma_pdf_pages OK
phpmyadmin.pma_relation OK
phpmyadmin.pma_table_coords OK
phpmyadmin.pma_table_info OK
phpmyadmin.pma_tracking OK
Running 'mysql_fix_privilege_tables'...
OK
Nakon toga napravimo provjeru dogradnje:
# mysqlcheck -u root -p --check-upgrade --all-databases --auto-repair
Enter password:
foundry.wp_foundrycommentmeta OK
foundry.wp_foundrycomments OK
foundry.wp_foundryflag_album OK
foundry.wp_foundryflag_comments OK
foundry.wp_foundryflag_gallery OK
foundry.wp_foundryflag_pictures OK
foundry.wp_foundrylinks OK
foundry.wp_foundryngg_album OK
foundry.wp_foundryngg_gallery OK
foundry.wp_foundryngg_pictures OK
foundry.wp_foundryoptions OK
foundry.wp_foundrypostmeta OK
foundry.wp_foundryposts OK
foundry.wp_foundryterm_relationships OK
foundry.wp_foundryterm_taxonomy OK
foundry.wp_foundryterms OK
foundry.wp_foundryusermeta OK
foundry.wp_foundryusers OK
mysql.columns_priv OK
mysql.db OK
mysql.event OK
mysql.func OK
mysql.general_log
Error : You can't use locks with log tables.
status : OK
mysql.help_category OK
mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.host OK
mysql.plugin OK
mysql.proc OK
mysql.procs_priv OK
mysql.servers OK
mysql.slow_log
Error : You can't use locks with log tables.
status : 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
phpmyadmin.pma_bookmark OK
phpmyadmin.pma_column_info OK
phpmyadmin.pma_designer_coords OK
phpmyadmin.pma_history OK
phpmyadmin.pma_relation OK
phpmyadmin.pma_table_coords OK
phpmyadmin.pma_table_info OK
phpmyadmin.pma_tracking OK
# mysqlcheck -u root -p --all-databases --check-upgrade --fix-db-names --fix-table-names
Enter password:
root@stroj:/var/log#
Nakon provjera poruke o oštećenim tablicama trebale bi se izgubiti. Prema uputama za WordPress treba promijeniti i URL stranice koju smo preselili na drugu adresu. Za to je jako koristan paket phpmysql.
# apt-get install phpmyadmin
Da bi mogli pristupiti bazi kroz phpmyadmin treba dati prava phpmyadmin korisniku nad bazom.
# mysql -u root -p
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON foundry.* TO 'phpmyadmin'@'localhost' IDENTIFIED BY 'lozinka';
Promijenimo pod wp_imebazeoptions URL kao na slikama.
Ukoliko nakon ovih promjena imate problem sa otvaranjem stranice provjerite dozvole nad php datotekama što je opisano u drugom članku.
Primjetio sam u /var/log/apache2/error.log nakon što stranica proradi slijedeću grešku.
[Fri Mar 23 09:42:37 2012] [error] PHP Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 4864 bytes) in /home/foundry/public_html/wp-content/plugins/wp-pagenavi/wp-pagenavi.php on line 31
Za taj problem je potrebno prepraviti jedan redak u /etc/php5/apache2/php.ini, jer je nova instalacija donijela maksimalni memory_limit= 16M
Radi se količini memorije koja je data skriptama na korištenje. Limit je postavljen da loše napisane skripte ne bi "pojele" svu raspoloživu memoriju na serveru.
Provjeravamo tu vrijednost na svom produkcijskom serveru.
# less php.ini | grep memory_limit
memory_limit = 64M
Ovu vrijednost prenesemo na testni server.
Nakon toga poruke o greškama se više ne javljaju. Nadamo se da će ove upute nekome pomoći.
- Logirajte se za dodavanje komentara
- Inačica za ispis
- PDF version
Komentari
Primjenjeno na preseljenju sa Squeeze na Wheezy
Uputa funkcionira i za slučaj prebacivanja WP stranice sa Squeeze servera na Wheezy.
Testno isprobano.
S tim da je najbolje prenijeti sa izvornog na ciljani serveri password retke iz konfiguracijske datoteke:
U protivnom imat ćete problema sa startanjem mysql-a.Prenesite password sa izvornog na
ciljani server.