{"id":7,"date":"2005-03-04T23:46:45","date_gmt":"2005-03-04T22:46:45","guid":{"rendered":"http:\/\/blog.blackdown.de\/2005\/03\/08\/chrooting-mysql-on-debian\/"},"modified":"2016-10-29T03:51:03","modified_gmt":"2016-10-29T01:51:03","slug":"chrooting-mysql-on-debian","status":"publish","type":"post","link":"https:\/\/blackdown.de\/articles\/chrooting-mysql-on-debian\/","title":{"rendered":"Chrooting MySQL on Debian"},"content":{"rendered":"
It’s quite easy to chroot bind9<\/a> and apache<\/a> on Debian<\/a>. (See this page<\/a> for bind9 and libapache2-mod-chroot<\/a> or libapache2-mod-security<\/a> for apache.)<\/p>\n But I’ve found no guide for chrooting MySQL<\/a>, so here’s my short recipe:<\/p>\n Don’t change the to the March 13th, 2005:<\/strong> I’ve updated the script for newer Debian packages, see Updated MySQL Chroot Script<\/a> for more information.<\/em><\/p>\n July 30th, 2006:<\/strong> These modifications still work fine on the current stable Debian release (3.1, “sarge”). The mysql packages in the testing (“etch”) and unstable (“sid”) distributions of Debian need a few additional changes, I’ll post an updated guide in a few days.<\/em><\/p>\n December 30th, 2006:<\/strong> I’ve made an updated guide<\/a> on how to chroot more recent MySQL packages on Debian and Ubuntu<\/em><\/p>\n","protected":false},"excerpt":{"rendered":" It’s quite easy to chroot bind9 and apache on Debian. (See this page for bind9 and libapache2-mod-chroot or libapache2-mod-security for apache.) But I’ve found no guide for chrooting MySQL, so here’s my short recipe: Prepare the chroot directory. It’s recommended to use an extra partition\/filesystem for it. I will use \/srv\/mysql (which is an LVM2\n
\/srv\/mysql<\/code> (which is an LVM2<\/a> partition with an ext3 filesystem on my system) for the rest of the text.<\/li>\n
\/etc\/init.d\/mysql stop<\/pre>\n<\/li>\n
mkdir -p \/srv\/mysql\/var\/lib\r\ncp -a \/var\/lib\/mysql \/srv\/mysql\/var\/lib<\/pre>\n<\/li>\n
\/etc\/default\/mysql-chroot<\/code><\/li>\n
\/etc\/init.d\/mysql<\/code>:\n
\n
mysql-chroot<\/a><\/code> script somewhere at the top:\n
…\r\ntest -x \/usr\/sbin\/mysqld || exit 0\r\n\r\n. \/etc\/default\/mysql-chroot<\/strong>\r\n\r\nSELF=$(cd $(dirname $0); pwd -P)\/$(basename $0)\r\n…<\/pre>\n<\/li>\n
setup_chroot<\/code> right in the start section:\n
…\r\nif mysqld_status check_alive nowarn; then\r\n echo "...already running."\r\nelse\r\n setup_chroot<\/strong>\r\n \/usr\/bin\/mysqld_safe > \/dev\/null 2>&1 &\r\n…<\/pre>\n<\/li>\n
\/var\/run\/mysqld\/mysqld.pid<\/code> disappears after each start. We have to create it each time, otherwise the
stop<\/code> command won’t work properly:\n
…\r\nif mysqld_status check_alive warn; then\r\n echo "."\r\n ln -sf $CHROOT_DIR\/var\/run\/mysqld\/mysqld.pid \\\r\n \/var\/run\/mysqld<\/strong>\r\n # Now start mysqlcheck or whatever the admin wants.\r\n \/etc\/mysql\/debian-start\r\n…<\/pre>\n<\/li>\n<\/ul>\n<\/li>\n
\/etc\/mysql\/debian.cnf<\/code>, change the
socket<\/code> line to:\n
socket = \/srv\/mysql\/var\/run\/mysqld\/mysqld.sock<\/pre>\n<\/li>\n
\/etc\/mysql\/my.cnf<\/code>:\n
\n
socket<\/code> line in the
[client]<\/code> section to:\n
socket = \/srv\/mysql\/var\/run\/mysqld\/mysqld.sock<\/pre>\n
socket<\/code> lines in the other sections!<\/p>\n<\/li>\n
chroot = \/srv\/mysql<\/pre>\n
[mysqld]<\/code> section.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n
\/srv\/mysql<\/code> to the log files listed in
\/etc\/logrotate.d\/mysql-server<\/code><\/li>\n
\/etc\/init.d\/mysql start<\/pre>\n<\/li>\n
\/var\/log\/syslog<\/code> for errors ;-)<\/li>\n<\/ul>\n
[→ Read the rest of this entry<\/a>]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[6,3,8],"tags":[],"yoast_head":"\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n\t\n