查看Linux版本:cat /etc/redhat-release
关机:shutdown -h now halt
重启:shutdown -r now reboot
删除文件:rm -f xxx
删除文件夹及其中文件:rm -rf xxx
创建多级目录:mkdir -p
复制:cp -r Ctrl + Insert
粘贴:Shift + Insert
查找:find / -name 'xxx'
重命名:mv xxx xxx
查看进程:ps aux|grep 'xxx'
列出进程使用的文件(筛选带log的):lsof -p 15326|grep 'log'
查看装了那些包:rpm -qa|grep mysql
打印匹配行的前后5行:grep -5 'parttern' inputfile
打印匹配行的前后5行:grep -C 5 'parttern' inputfile
打印匹配行的后5行:grep -A 5 'parttern' inputfile
打印匹配行的前5行:grep -B 5 'parttern' inputfile
从服务器上下载文件:scp username@servername:/path/filename /var/www/local_dir(本地目录)
上传本地文件到服务器:scp /path/filename username@servername:/path
从服务器下载整个目录:scp -r username@servername:/var/www/remote_dir/(远程目录) /var/www/local_dir(本地目录)
上传目录到服务器:scp -r local_dir username@servername:remote_dir
查看mysql慢日志中ip地址为192.168.0.10发送过来的SQL语句的后面三行:tail -50 /usr/local/mysql/data/sql-slow.log |grep -3 '192.168.0.10'
匹配php错误日志中某一个字段:tail -100 /data/logs/php/php_error_5.3.log | grep "Memcache::get()";
查看某一个文件第5行和第10行:sed -n '5,10p' filename 这样你就可以只查看文件的第5行到第10行。
卸载:yum remove
查看当前路径:pwd
查找文件路径:whereis
添加可执行权限:chmod +x
切换用户:su xxx
修改密码:passwd
使环境变量立即生效:source /etc/profile
关闭防火墙:
1) 重启后生效
开启: chkconfig iptables on
关闭: chkconfig iptables off
2) 即时生效,重启后失效
开启: service iptables start
关闭: service iptables stop
Nginx相关:
cd /usr/local/nginx/sbin/
开启nginx ./nginx
关闭nginx ./nginx -s quit
重新加载配置文件 ./nginx -s reload
redis相关:
开启redis ./redis-server redis.conf
关闭redis ./redis-cli -p 7001 shutdown
跨域配置
if ($http_origin ~* '.*(xxx.com|xxx-corp.com)') {
set $cors "true";
}
if ($cors = "true") {
add_header 'Access-Control-Allow-Origin' "$http_origin" ;
add_header 'Access-Control-Allow-Credentials' 'true' ;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' ;
add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With' ;
}
zookeeper相关:
开启zookeeper ./zkServer.sh start
关闭zookeeper ./zkServer.sh stop
查看状态 ./zkServer.sh status
tomcat相关:
查看日志 tail -f tomcat/logs/catalina.out
mysql相关:
安装yum源包:yum localhostinstall mysql-community-release.noarch.rpm
安装MySQL服务:yum install mysql-server
启动:service mysqld start
设置root用户密码:/usr/bin/mysqladmin -u root password '123456'
连接:mysql -uroot -p123456
远程连接授权:GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;