免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1132 | 回复: 0
打印 上一主题 下一主题

Chrooting MySQL on Debian [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-04-14 13:23 |只看该作者 |倒序浏览
I’ve posted a recipe for chrooting MySQL on Debian sarge a while ago. These instructions no longer work out of the box for newer MySQL packages from Debian and Ubuntu. The main problem is that the startup script added a few extra checks and script invocations that don’t understand the chroot environment. So here’s an updated plan:
    * Prepare the chroot directory. It’s recommended to use an extra partition/filesystem for it. I will use /srv/mysql (which is an LVM2 partition with an ext3 filesystem on my system) for the rest of the text.
    * Stop MySQL:
      /etc/init.d/mysql stop
    * Copy the databases to new location:
      mkdir -p /srv/mysql/var/lib
      cp -a /var/lib/mysql /srv/mysql/var/lib
    * Copy this script to /etc/default/mysql-chroot
    * Edit /etc/init.d/mysql:
          o Source the mysql-chroot script somewhere at the top:
            …
            test -x /usr/sbin/mysqld || exit 0
            . /etc/default/mysql-chroot
            SELF=$(cd $(dirname $0); pwd -P)/$(basename $0)
            …
          o Fix the disk space check:
            …
            # check for diskspace shortage
            datadir=`mysqld_get_param datadir`
            if LC_ALL=C BLOCKSIZE= df --portability $CHROOT_DIR$datadir/. | tail -n 1 | awk '{ exit ($4>4096) }'; then
              log_failure_msg "$0: ERROR: The partition with $datadir is too full!"
            …
          o Run setup_chroot right in the start section:
            …
            if mysqld_status check_alive nowarn; then
              echo "...already running."
            else
              setup_chroot
              /usr/bin/mysqld_safe > /dev/null 2>&1 &
            …
          o Somehow /var/run/mysqld/mysqld.pid disappears after each start. We have to create it each time, otherwise the stop command won’t work properly:
            …
            if mysqld_status check_alive warn; then
              log_end_msg 0
              ln -sf $CHROOT_DIR/var/run/mysqld/mysqld.pid
                             /var/run/mysqld
              # Now start mysqlcheck or whatever the admin wants.
              output=$(/etc/mysql/debian-start)
            …
    * In /etc/mysql/debian.cnf, change the two socket lines to:
      socket = /srv/mysql/var/run/mysqld/mysqld.sock
    * In /etc/mysql/my.cnf:
          o Change the socket line in the [client] section to:
            socket = /srv/mysql/var/run/mysqld/mysqld.sock
            Don’t change the socket lines in the other sections!
          o Add
            chroot = /srv/mysql
            to the [mysqld] section.
    * Prepend /srv/mysql to the log files listed in /etc/logrotate.d/mysql-server
    * Make /usr/bin/mysql_upgrade_shell use the chrooted socket. Note: Currently these changes must be made each time mysql gets upgraded because upgrades override this file!
      …
      −−password=*) password=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
      −−socket=*) socket=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
      −−ldata=*|−−data=*|−−datadir=*) DATADIR=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
      …
      fi
      $bindir/mysql_fix_privilege_tables −−silent −−user=$user −−password=$password −−socket=$socket $args
      exit 0
      …
      check_args="−−check-upgrade −−all-databases −−auto-repair −vuser=$user −−password=$password −−socket=$socket"
      …
      $bindir/mysql_fix_privilege_tables −−silent −−user=$user −−password=$password −−socket=$socket $args
      …
    * Start MySQL:
      /etc/init.d/mysql start
    * Check /var/log/syslog for errors ;-)
http://blog.blackdown.de/2006/12/30/chrooting-recent-mysql-versions-on-debian-and-ubuntu/
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/6418/showart_277811.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP