📄 1860.html
字号:
#chown root:root /chroot/mysql/dev/null<br>
#chmod 666 /chroot/mysql/dev/null<br>
<br>
6.拷贝mysql的数据库文件到chroot下<br>
<br>
<br>
#cp -R /usr/local/mysql/var/ /chroot/mysql/usr/local/mysql/var<br>
#chown -R mysql:mysql /chroot/mysql/usr/local/mysql/var<br>
<br>
7.安装chrootuid程序<br>
<br>
下载chrootuid,然后RPM安装即可。<br>
<br>
<br>
http://rpm.pbone.net/index.php3/stat/4/idpl/355932/com/<br>
chrootuid-1.3-alt2.i586.rpm.html<br>
<br>
8.测试Chroot环境下的MySQL配置<br>
<br>
<br>
#chrootuid /chroot/mysql mysql /usr/local/mysql/libexec/mysqld &<br>
<br>
如果失败请注意chroot目录下面的权限问题。<br>
<br>
9.测试连接chroot下的MySQL<br>
<br>
<br>
#/usr/local/mysql/bin/mysql --socket=/chroot/mysql/tmp/mysql.sock<br>
..............<br>
mysql>show databases;<br>
mysql>create database wgh;<br>
mysql>quit;<br>
#ls -al /chroot/mysql/var/<br>
...............<br>
<br>
配置服务器<br>
<br>
为了更加安全地使用MySQL,需要对MySQL的数据库进行安全配置;并且由于Chroot的原因,配置文件也会有所不同。<br>
<br>
1.关闭远程连接<br>
<br>
首先,应该关闭3306端口,这是MySQL的默认监听端口。由于此处MySQL只服务于本地脚本,所以不需要远程连接。尽管MySQL内建的安全机制很严格,但监听一个TCP端口仍然是危险的行为,因为如果MySQL程序本身有问题,那么未授权的访问完全可以绕过MySQL的内建安全机制。关闭网络监听的方法很简单,在/chroot/mysql/etc/my.cnf文件中的[mysqld]部分,去掉#skip-networking前面的“#”即可。<br>
<br>
关闭了网络,本地程序如何连接MySQL数据库呢?本地程序可以通过mysql.sock来连接,速度比网络连接更快。后文将提到关于mysql.sock的具体情况。<br>
<br>
MySQL的备份通常使用SSH来执行!<br>
<br>
2.禁止MySQL导入本地文件<br>
<br>
下面,将禁止MySQL中用“LOAD DATA LOCAL INFILE”命令。这个命令会利用MySQL把本地文件读到数据库中,然后用户就可以非法获取敏感信息了。网络上流传的一些攻击方法中就有用它的,它也是很多新发现的SQL Injection攻击利用的手段!<br>
<br>
为了禁止上述命令,在/chroot/mysql/etc/my.cnf文件的[mysqld]部分加入:<br>
<br>
<br>
set-variable=local-infile=0<br>
<br>
为了管理方便,一般在系统中的MySQL管理命令如mysql,mysqladmin,mysqldump等,使用的都是系统的 /etc/my.cnf文件。如果要连接,它会寻找/tmp/mysql.sock文件来试图连接MySQL服务器,但是这里要连接的是chroot下的 MySQL服务器,解决办法有两个:一个是在管理命令后面加入--socket=/chroot/mysql/tmp/mysql.sock。例如:<br>
<br>
<br>
#/usr/local/mysql/bin/mysql -root -p --socket=/chroot/mysql/tmp/mysql.sock<br>
<br>
第二个就是在/etc/my.cnf的[client]部分加入socket=/chroot/mysql/tmp/mysql.sock。显然,第二个方法方便多了。<br>
<br>
3.修改MySQL的root用户ID和密码<br>
<br>
<br>
#chrootuid /chroot/mysql mysql /usr/local/mysql/libexec/mysqld &<br>
#/usr/local/mysql/bin/mysql -uroot<br>
...............<br>
mysql>SET PASSWORD FOR root@localhost=PASSWORD('new_password');<br>
<br>
尽量养成在mysql下输入密码的习惯,因为Shell下面输入的时候可能会被其它人看见。<br>
<br>
<br>
mysql>use mysql;<br>
mysql>update user set user="wghgreat" where user="root";<br>
mysql>select Host,User,Password,Select_priv,Grant_priv from user;<br>
mysql>delete from user where user='';<br>
mysql>delete from user where password='';<br>
mysql>delete from user where host='%';<br>
mysql>drop database test;<br>
mysql>flush privileges;<br>
mysql>quit;<br>
<br>
修改为一个不容易猜的ID<br>
<br>
4.删除历史命令记录<br>
<br>
这些历史文件包括~/.bash_history、~/.mysql_history等。如果打开它们,你会大吃一惊,怎么居然有一些明文的密码在这里?!<br>
<br>
<br>
#cat /dev/null > ~/.bash_history<br>
#cat /dev/null > ~/.mysql_history<br>
<br>
PHP和MySQL通信<br>
<br>
默认情况下,PHP会通过/tmp/mysql.sock来和MySQL通信,但这里的一个大问题是MySQL生成的根本不是它,而是/chroot/mysql/tmp/mysql.sock。解决的办法就是做一个连接:<br>
<br>
<br>
#ln /chroot/mysql/tmp/mysql.sock /tmp/mysql.sock <br>
<br>
注意:由于hard links不能在文件系统的分区之间做,所以该处的连接必须位于同一分区内部。<br>
<br>
自启动配置<br>
<br>
自启动配置前先提示一点:即用于PHP的数据库需要用一个新建的帐号,其上有数据库权限设置,比如FILE、GRANT、ACTER、SHOW DATABASE、RELOAD、SHUTDOWN、PROCESS、SUPER等。<br>
<br>
自启动脚本示例:<br>
<br>
<br>
#!/bin/sh<br>
CHROOT_MYSQL=/chroot/mysql <br>
SOCKET=/tmp/mysql.sock<br>
MYSQLD=/usr/local/mysql/libexec/mysqld<br>
PIDFILE=/usr/local/mysql/var/`hostname`.pid<br>
CHROOTUID=/usr/bin/chrootuid<br>
echo -n " mysql"<br>
case "$1" in<br>
start)<br>
rm -rf ${SOCKET}<br>
nohup ${CHROOTUID} ${CHROOT_MYSQL} mysql ${MYSQLD} >/dev/null 2>&1 &<br>
sleep 5 && ln ${CHROOT_MYSQL}/${SOCKET} ${SOCKET}<br>
;;<br>
stop)<br>
kill `cat ${CHROOT_MYSQL}/${PIDFILE}`<br>
rm -rf ${CHROOT_MYSQL}/${SOCKET}<br>
;;<br>
*)<br>
echo ""<br>
echo "Usage: `basename $0` {start|stop}" >&2<br>
exit 64<br>
;;<br>
esac<br>
exit 0<br>
<br>
文件位于/etc/rc.d/init.d下,名为mysqld,注意要可执行。<br>
<br>
<br>
#chmod +x /etc/rc.d/init.d/mysqld<br>
#ln -s /etc/rc.d/init.d/mysql /etc/rc3.d/S90mysql<br>
#ln -s /etc/rc.d/init.d/mysql /etc/rc0.d/K20mysql<br>
<br>
结论:尽管我们不能做到100%的安全,但是这些措施可以保护我们的系统更加安全!<br>
<br>
参考资料:<br>
<br>
<br>
Artur Maj 《Securing MySQL》<br>
Xuzhikun 《MySQL数据库安全配置》<br>
晏子 译 《MySQL中文参考手册》<br>
<br>
</FONT><br>
</TD>
</TR>
<TR>
<TD colSpan=2><FONT
class=middlefont></FONT><BR>
<FONT
class=normalfont>全文结束</FONT> </TD>
</TR>
<TR>
<TD background="images/dot.gif" tppabs="http://www.linuxhero.com/docs/images/dot.gif" colSpan=2
height=10></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></DIV></TD>
<TD vAlign=top width="20%"
background="images/line.gif" tppabs="http://www.linuxhero.com/docs/images/line.gif" rowSpan=2>
<DIV align=center>
<table class=tableoutline cellspacing=1 cellpadding=4
width="100%" align=center border=0>
<tr class=firstalt>
<td noWrap background="images/bgline.gif" tppabs="http://www.linuxhero.com/docs/images/bgline.gif" colspan=2 height=21>
<font class=normalfont><b>所有分类</b></font></td>
</tr>
<tr class=secondalt> <td noWrap width=27%> <font class=normalfont>1:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type1.html" tppabs="http://www.linuxhero.com/docs/type1.html">非技术类</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>2:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type2.html" tppabs="http://www.linuxhero.com/docs/type2.html">基础知识</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>3:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type3.html" tppabs="http://www.linuxhero.com/docs/type3.html">指令大全</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>4:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type4.html" tppabs="http://www.linuxhero.com/docs/type4.html">shell</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>5:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type5.html" tppabs="http://www.linuxhero.com/docs/type5.html">安装启动</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>6:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type6.html" tppabs="http://www.linuxhero.com/docs/type6.html">xwindow</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>7:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type7.html" tppabs="http://www.linuxhero.com/docs/type7.html">kde</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>8:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type8.html" tppabs="http://www.linuxhero.com/docs/type8.html">gnome</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>9:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type9.html" tppabs="http://www.linuxhero.com/docs/type9.html">输入法类</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>10:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type10.html" tppabs="http://www.linuxhero.com/docs/type10.html">美化汉化</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>11:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type11.html" tppabs="http://www.linuxhero.com/docs/type11.html">网络配置</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>12:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type12.html" tppabs="http://www.linuxhero.com/docs/type12.html">存储备份</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>13:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type13.html" tppabs="http://www.linuxhero.com/docs/type13.html">杂项工具</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>14:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type14.html" tppabs="http://www.linuxhero.com/docs/type14.html">编程技术</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>15:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type15.html" tppabs="http://www.linuxhero.com/docs/type15.html">网络安全</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>16:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type16.html" tppabs="http://www.linuxhero.com/docs/type16.html">内核技术</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>17:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type17.html" tppabs="http://www.linuxhero.com/docs/type17.html">速度优化</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>18:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type18.html" tppabs="http://www.linuxhero.com/docs/type18.html">apache</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>19:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type19.html" tppabs="http://www.linuxhero.com/docs/type19.html">email</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>20:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type20.html" tppabs="http://www.linuxhero.com/docs/type20.html">ftp服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>21:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type21.html" tppabs="http://www.linuxhero.com/docs/type21.html">cvs服务</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>22:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type22.html" tppabs="http://www.linuxhero.com/docs/type22.html">代理服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>23:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type23.html" tppabs="http://www.linuxhero.com/docs/type23.html">samba</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>24:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type24.html" tppabs="http://www.linuxhero.com/docs/type24.html">域名服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>25:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type25.html" tppabs="http://www.linuxhero.com/docs/type25.html">网络过滤</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>26:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type26.html" tppabs="http://www.linuxhero.com/docs/type26.html">其他服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>27:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type27.html" tppabs="http://www.linuxhero.com/docs/type27.html">nfs</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>28:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type28.html" tppabs="http://www.linuxhero.com/docs/type28.html">oracle</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>29:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type29.html" tppabs="http://www.linuxhero.com/docs/type29.html">dhcp</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>30:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type30.html" tppabs="http://www.linuxhero.com/docs/type30.html">mysql</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>31:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type31.html" tppabs="http://www.linuxhero.com/docs/type31.html">php</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>32:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type32.html" tppabs="http://www.linuxhero.com/docs/type32.html">ldap</a></font></td> </tr> </table></td></tr> </table>
</DIV></TD></TR>
<TR vAlign=top>
<TD width="80%">
<DIV align=center><BR>
</DIV>
</TD></TR></TBODY></TABLE></TD></TR>
</TABLE></TD></TR>
</TABLE>
<TABLE cellSpacing=0 cellPadding=4 width="100%" bgColor=#eeeeee
border=0><TBODY>
<TR>
<TD width="50%">
<P><FONT class=middlefont>版权所有 © 2004 <A
href="mailto:bjchenxu@sina.com">linux知识宝库</A><BR>
违者必究. </FONT></P>
</TD>
<TD width="50%">
<DIV align=right><FONT class=middlefont>Powered by: <A
href="mailto:bjchenxu@sina.com">Linux知识宝库</A> Version 0.9.0 </FONT></DIV>
</TD></TR></TBODY></TABLE>
<CENTER></CENTER></TD></TR>
</TABLE></CENTER></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -