2012
10
10
16:33

phpmyadmin导入mysql数据库sql文件最大限制2M

php配置文件php.ini中默认设置允许上传的最大文件数据为2M,因此通过phpmyadmin Web界面管理mysql数据库时,能够导入mysql数据库的最大sql文件或gzip文件大小也是2M (2048K)。如果要导入大于2M的sql数据库文件,有以下几种解决方法。

 

最直接的解决办法当然就是修改php.ini配置文件的设置,即修改默认的 upload_max_filesize = 2M, memory_limit = 128M; post_max_size = 8M 。 比如我想上传一个27M的sql数据库文件,则可以修改为 upload_max_filesize = 32M, post_max_size = 32M,post_max_size 和 memory_limit 的值至少要大于等于upload_max_filesize的设置值。增加了php.ini中的最大上传设置数据之后,重启Apache数据库,再打开phpmyadmin 就可以上传大的sql数据库文件等等。

 

另外一种方法适用于没有权限修改网站服务器php.ini文件设置的用户,可以使用phpmyadmin提供的$cfg[‘UploadDir’]方法,$cfg[‘UploadDir’]方法允许我们通过scp、ftp等文件传输方式上传数据库文件到网站服务器,然后phpmyadmin从服务器的临时目录中导入数据库文件。该上传的文件名后缀必须为.sql或者.sql.bz2 或.sql.gz 。具体步骤如下:

 

在phpMyAdmin的根目录下找到config.inc.php文件(config.sample.inc.php),打开找到$cfg[‘UploadDir’] 和$cfg[‘SaveDir’],注释为“Directories for saving/loading files from server ”,即通过$cfg[‘UploadDir’] 和$cfg[‘SaveDir’]可以导入服务器上的SQL文件到数据库,以及将从数据库导出的SQL文件保存到服务器上的目录中。

 

修改这个参数为$cfg[‘UploadDir’] = ‘ImportSQLFile’; 和 $cfg[‘SaveDir’] = ‘ExportSQLFile’;

 

再在phpMyAdmin中建立两个文件夹,ImportSQLFile和ExportSQLFile。也就是将需要导入的sql文件复制到ImportSQLFile文件夹中,上传到服务器上。选择需要导入的数据库名,选择导入(Import),就会发现在文件导入(File to import)的地方多出来一个导入服务器上的SQL文件(web server upload directory)。通过这种方法可以突破php.ini的上传文件限制。导出/备份mysql数据的时候也可以直接保存在服务器上,保存到$cfg[‘SaveDir’] = ‘ExportSQLFile’; 中指定的文件夹中。

 

另外,如果网站服务器和国外美国主机dreamhost一样支持Shell方式(SSH,SFTP,命令行)传输文件,那么通过shell方式导入Mysql数据库很大的sql文件都不成问题,直接在Mysql中使用命令:source filename.sql。

 

如果还是不能上传大于2M的数据库数据文件,可以检查一下你的phpmyadmin 版本是不是最新的,据说phpmyadmin低于 2.7.0版本会出现类似memory内存、http错误和timeout超时等各种问题,因此最好安装phpmyadmin升级到最新版本。

2012
10
08
12:44

error: 'Access denied for user 'debian-sys-maint'@'localhost' (using password: YES)

debian-sys-maint的密码是安装mysql时随时生成的

停止或重启服务都靠它

如果你修改了它的密码或覆盖掉密码,就会出现错误

error: ‘Access denied for user ‘debian-sys-maint’@’localhost’ (using password: YES)’

查看/etc/mysql/debian.cnf查看内容,可以看到有这个mysql连接用户:[client]

host = localhost

user = debian-sys-maint

password = G1I2JcALeXXvyC50

socket = /var/run/mysqld/mysqld.sock

[mysql_upgrade]

user = debian-sys-maint

password = G1I2JcALeXXvyC50

socket = /var/run/mysqld/mysqld.sock

basedir = /usr

直接用mysql登录,为debian-sys-maint用户改密:

mysql>SET PASSWORD FOR ‘debian-sys-maint’@’localhost’ = PASSWORD(‘这里就是上面看到的密码’);

mysql> flush privileges;

这样就OK了

如果删除了改用户,那只有添加了

mysql> GRANT ALL PRIVILEGES ON *.* TO ‘debian-sys-maint’@’localhost’ IDENTIFIED BY ‘这里就是上面看到的密码” WITH GRANT OPTION;

mysql> flush privileges;

2012
09
27
11:41

Linux vps修改时间改成北京时间

1.先登陆你的ssh,命令:date 看下时间是不是北京时间,如果不是我们把他改成北京时间。

2.命令:

rm -rf /etc/localtime

ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

 

3.再用date命令看下,你的vps的时间改变了吗?大部分Linux vps的母鸡是允许每个vps修改时间的!

如果此时你的vps时间已经改成北京时间就不用看下面了,如果此时你的vps时间还没有修改好。再试下命令:

ntpdate stdtime.sinica.edu.tw

使用ntpdate stdtime.sinica.edu.tw 时候如果提示这个命令,先安装 ntpdate就可以了。

 

centos 系统的vps用命令:

yum -y install ntpdate ntp

Ubuntu系统的:

sudo apt-get install -y ntpdate ntp

2012
09
19
16:18

关于apache2伪静态问题

刚把博客搬了一个新家,之前是用一键安装包配置的VPS,虽然配置完了能很正好的运行,但是有很多想地方想修改却不知道从何处下手。这次搬家,全是手动配置的APACHE2环境,其实手运配置还是蛮简单的,只要自己细心点,但是配置完成后发现怎么也无法实现伪静态,开始以为是伪静态规则出了问题,但经过很多次试验,感觉发现不是伪静态规则的问题,看了看PHPINFO信息,原来里面没有mod_rewrite模块,这下犯愁了,因为APACHE2安装是用默认安装的,难道默认安装apache2没有安装mod_rewrite模块?试着用google和百度查看一些如何重新加入mod_rewrite模块的方法,网上有大多数是垃圾文章,还好没试,不然试了又要重新配置VPS。看了一些资料,原来默认安装的apache2是有安装mod_rewrite模块,只是没有启动而已

a2enmod rewrite 启动

然后系统会提示你重新加载apache2 ,最后再用phpinfo查看,就已经有mod_rewrite模块了

2012
09
14
15:54

Optimize Apache and MySQL for a 256MB VPS

sudo nano /etc/mysql/my.cnf

 

Add the following line into the section [mysqld]:

skip-innodb

 

Next locate the line skip-external-locking and add skip-locking below that line.

 

Now find the section labeled “Fine Tuning”. Change/add the settings in that section to match those below:

 

key_buffer = 16K

max_allowed_packet = 1M

thread_stack = 64K

thread_cache_size = 4

sort_buffer = 64K

net_buffer_length = 2K

 

Save the file (ctrl+x) and restart MySQL: sudo /etc/init.d/mysql restart

If you run MySQLtuner again you will see that the “memory” warning is gone, ignore the aother warnings for the moment (you need to run the script after a few days again to get exact test results)

 

Optimize Apache in prefork mode

If you followed the Ubuntu tutorial we’ve mentioned in the first paragraph, your Apache setup should run in prefork mode. The default settings are much to high, open the file sudo nano /etc/apache2/apache2.conf andchange the following settings:

 

 

Timeout 45

KeepAlive On

MaxKeepAliveRequests 200

KeepAliveTimeout 3

 

StartServers 5

MinSpareServers 5

MaxSpareServers 10

MaxClients 30

MaxRequestsPerChild 2000

 

That’s all, restart Apache using sudo /etc/init.d/apache2 restart. If you know more tweaks, please share.

2012
09
11
17:29

购买VPS后简单测试

一、CPU信息及性能查看

cat /proc/cpuinfo

二、硬盘IO性能测试

root@h:~# dd if=/dev/zero of=test bs=64k count=4k oflag=dsync && rm test

4096+0 records in

4096+0 records out

268435456 bytes (268 MB) copied, 6.19022 s, 43.4 MB/s

root@h:~# dd if=/dev/zero of=test bs=64k count=16k conv=fdatasync && rm test

16384+0 records in

16384+0 records out

1073741824 bytes (1.1 GB) copied, 6.32504 s, 170 MB/s

测试结果,如果超过10M,对正常建站就无影响。超过50M,就是非常给力状态。

2012
09
10
15:59

ssh只允许指定的用户登陆

方法1:在/etc/pam.d/sshd文件第一行加入

auth required pam_listfile.so item=user sense=allow file=/etc/sshusers

onerr=fail

然后在/etc下建立sshusers文件,编辑这个文件,加入你允许使用ssh服务的用户名,不用重新启动sshd服务。

 

方法2:pam规则也可以写成deny的

auth required pam_listfile.so item=user sense=deny file=/etc/sshusers

onerr=succeed

 

方法3:在sshd_config中设置AllowUsers,格式如

AllowUsers a,b,c

重启sshd服务,则只有a/b/c3个用户可以登陆

2012
09
10
15:57

linux 限制root用户SSH登录

1、修改SSHD服务的配置文件/etc/ssh/sshd_config

将#PermitRootLogin yes 改为PermitRootLogin no

2、重启sshd服务使配置生效

/etc/rc.d/init.d/sshd restart

 

为了增强linux的安全性,应该限制只有wheel组的用户可以使用su命令切换到root和其他用户:

 

1、修改su命令的认证配置文件/etc/pam.d/su

 

去掉以下两行前的#号注释

#auth sufficient pam_wheel.so trust use_uid (去年注释后ROOT组成员使用su切换到root不需要密码)

#auth required pam_wheel.so use_uid  (去年注释后只允许ROOT组成员使用su切换到root)

2、创建一个普通用户,然后将这个用户加入到wheel组即可!以后就只有这个普通用户和root可以使用su命令了

usermod -G 组 用户

 

su命令使用简介:

 

su 直接切换到root用户,但保持原用户的环境变量;

su – 切换到root用户,并使用root用户的环境变量;

 

su -l test 切换到test用户,并使用test的环境变量;

2012
09
10
15:16

nginx 禁止ip访问及未绑定的域名跳转

ngixn 禁止ip访问和未绑定ip的访问

 

server {

listen 80 default;

server_name _;

return 500;

}

 

 

 

nginx 将未绑定的域名跳转

 

server {

listen 80 default;

rewrite ^(.*) http://www.kogoogle.com permanent;

}