服务器管理常用知识和命令

mysql服务器:

service httpd start

service httpd stop

修改/etc/my.conf中的mysql数据文件所在目录:

datadir=/assets/mysql

重启mysql服务器后生效

注意在上面修改datadir重启服务过程中可能出现权限问题:因为mysqld是以mysql这个用户来运行的,而datadir可能并不属于mysql用户,解决方案:

InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
InnoDB: File name ./ibdata1
InnoDB: File operation call: 'open'.
InnoDB: Cannot continue operation.
071027 07:43:13 mysqld ended

chown -R mysql.mysql /assets/mysql

 

数据盘挂载和扩容:

https://help.aliyun.com/document_detail/25452.html?spm=5176.doc25445.6.173.XKkyJu

检查linux下占用cpu高的进程详细信息:

1. top -c 查出对应的命令以及pid,

2. cd /prox/pid

3. ls -l,显示的cwd以及exe就可以看出具体是哪条命令启动了这个占用CPU巨大的任务!

redis安全相关

参考于:https://help.aliyun.com/knowledge_detail/5988808.html?spm=5176.2020520130.105.2.h59EGf&&msctype=pmsg&mscmsgid=119316051500075948&

1、指定redis服务使用的网卡 (需要重启redis才能生效)
在 redis.conf 文件中找到 “# bind 127.0.0.1” ,把前面的#号去掉,然后保存。注:修改后只有本机才能访问Redis。
 
2、设置访问密码 (需要重启redis才能生效)
在 redis.conf 中找到“requirepass”字段,在后面填上你需要的密码,Redis客户端也需要使用此密码来访问Redis服务。
 
3、修改Redis服务运行账号 (需要重启redis才能生效)
请以较低权限账号运行Redis服务,且禁用该账号的登录权限。另外可以限制攻击者往敏感写入文件,但是Redis数据还是能被黑客访问到,或者被黑客恶意删除。

4、设置防火墙策略

如果正常业务中Redis服务需要被其他服务器来访问,可以设置iptables策略仅允许指定的IP来访问Redis服务。

让laravel可以执行sudo命令git pull && php artisan cache:clear自动部署

chmod u+w /etc/sudoers ;
echo "apache ALL=NOPASSWD:/usr/local/git/bin/git pull" >> /etc/sudoers
echo "apache ALL=NOPASSWD:/usr/local/zend/bin/php artisan cache:clear" >> /etc/sudoers
再注释掉Defaults requiretty这行,否则会要求有tty才能运行!(TODO: 写shell实现自动化)
chmod u-w /etc/sudoers

rpm -qa |grep mysql  // 查找mysql是否已经安装

centos将文件清空:

true > logfile

七牛cdn上传及刷新

qshell qupload xx.json  :上传文件到存储空间

七牛后台刷新操作: 更i新CDN Cache

上述两个操作同步进行方能完成cache更新

或者qupload+ ?v = xx来强制更新无需后台刷新,因为v=xx+1后七牛会自动去源更新内容

mysql约束问题调试方法:

http://www.mihaimatei.com/mysql-foreign-key-constraint-fails/

You are here because of:

Cannot resolve table name close to (id)

Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails

What to check when you have MySQL foreign key related errors

  • Table should be of same engine (InnoDB)
  • Table fields should be of same type
    • Pay attention to INT size and UNSIGNED
  • Values inserted/updated in the main table are also present in the foreign table
  • You are inserting/updating all required fields

How to debug

Execute the following SQL query:

1
SHOW ENGINE INNODB STATUS

and look for:

1
2
3
------------------------
LATEST FOREIGN KEY ERROR
------------------------

If you see:

“Cannot resolve table name close to: (id)”,

or

“Trying to add to index `fieldname` tuple: … But the parent table `dbname`.`tablename` or its .ibd file does not currently exist!”

then one of your tables is MyISAM. Convert it to InnoDB.

具体解决办法:

mysqldump dbname > all.sql 
showed that the table referenced by my foreign key was a MyISAM table, not a InnoDB table. 

To fix it, in all.sql I: 
- globally substituted "InnoDB" for "MyISAM"; 
- added "SET FOREIGN_KEY_CHECKS=0;" at the top 
- added "SET FOREIGN_KEY_CHECKS=1;" at the bottom 
Then I recreated the database with: 
mysql dbname < all.sql 

I still don't have any .idb file (mentioned in the "SHOW INNODB STATUS" error message), but its fixed.

 mysql中的字符集:

1.关于字符集

所为字符集,就是用来定义字符在数据库中的编码的集合。常见的字符集有:utf8(支持中文)和AccIS(不支持中文)

2.关于排序规则

数据库中的排序规则用来定义字符在进行排序和比较的时候的一种规则。常见的如下: 
(1) utf8_general_ci 不区分大小写,utf8_general_cs 区分大小写 
(2) utf8_bin 规定每个字符串用二进制编码存储,区分大小写,可以直接存储二进制的内容

说明:所为排序规则,就是指字符比较时是否区分大小写,以及是按照字符编码进行比较还是直接用二进制数据比较。

这里只是简单记录下自己整理的东西,如果对你有用,麻烦点个赞咯。

posted @ 2016-05-15 15:43  世有因果知因求果  阅读(309)  评论(0编辑  收藏  举报