linux
重装linux
查看linux版本
lsb_release -a
更换源
在系统设置里面找到软件源,随便更换一个国内的源
ctrl + alt + t之后sudo apt-get update
这时候应该会提醒安装更新,安装新立得
在软件中心搜索新立得,安装chrome
在火狐里面打开google,搜索chrome,安装zsh
sudo chsh -s $(which zsh)tmux切屏
tmux在ssh的时候会显现出功力,因为某些费时操作会阻塞主ssh shell,用tmux解决这个问题 视频 http://happycasts.net/episodes/41
第一见事情,改配置,更改为如下配置
###常用指令
主要分为两种,一种是在tmux外,一种是tmux内
概念 session | window | pane 一个session可以有多个window,一个window有可以被切为多个pane
tmux外
进入tmux后
修改 ~/.tmux.conf如果发现配置没有生效,说明还有tmux进程开着
将tmux有关进程kill后重启tmux就可以了
~/.tmux.conf
ssh登录服务器
http://blog.csdn.net/hugeheadhuge/article/details/6719405
在Ubuntu客户端通过ssh登录服务器。假设服务器的IP地址是192.168.0.103,登录的用户名是hyx。
接下来会提示输入密码,然后就能成功登录到服务器上了。
ssh [-l login_name] [-p port] [user@]hostname
在linux下一般用scp这个命令来通过ssh传输文件。
http://www.cnblogs.com/jiangyao/archive/2011/01/26/1945570.html
1、从服务器上下载文件
例如scp root@192.168.0.101:/var/www/test.txt 把192.168.0.101上的/var/www/test.txt 的文件下载到/var/www/local_dir(本地目录)
2、上传本地文件到服务器
例如scp /var/www/test.php root@192.168.0.101:/var/www/ 把本机/var/www/目录下的test.php文件上传到192.168.0.101这台服务器上的/var/www/目录中
3、从服务器下载整个目录
例如:scp -r root@192.168.0.101:/var/www/test /var/www/
4、上传目录到服务器
例如:scp -r test root@192.168.0.101:/var/www/ 把当前目录下的test目录上传到服务器的/var/www/ 目录
编辑/etc/profile后导致命令找不到的解决方法
原因:在设置环境变量时,编辑profile文件没有写正确,导致在命令行下ls等命令不能够识别。
解决方案:
然后vi修改profile文件
vi配置文件
随便找了一个
~/.vimrc
centos 安装文件
用yum安装
iptables 防火墙启动80端口
以下仅仅是记录,需要参考/etc/sysconfig/iptables修改
编辑vi /etc/sysconfig/iptables文件,如:
重启iptalbes服务:
java安装
###下载
首先下载最新的jdk 6 目前是45版本,下载地址不太好找,在oracle官网的download-->java se -->Previous Releases找到下载地址,现在oracle下载必须注册了。 http://www.oracle.com/technetwork/java/javase/downloads/index.html?ssSourceSiteId=ocomen
###移动到服务器 下载完成后首先将本地的文件上传到服务器上 scp命令,有关scp命令的问题见上一个issure。
###解压 上传到服务器之后例如在/opt/files文件夹,首先给jdk-6u45-linux-x64.bin加上执行权限 chmod +x jdk-6u45-linux-x64.bin,然后./jdk-6u45-linux-x64.bin他就会解压到当前目录,如果想移动到别的目录,使用mv命令即可。
修改环境变量 vi 编辑/etc/profile文件,在最下面写上这几行代码,注意你真实的路径,然后重新登录服务器,java javac命令都能找到,安装成功,如果出现什么命令找不到的话,请见上一个issure的解决方案。
###安装结束
tomcat安装
下载 apache-tomcat-6.0.37.zip 将文件scp到服务器/opt/files
unzip 命令解压即可,如果没有unzip命令,yum 安装 http://www.cnblogs.com/lucyjiayou/archive/2011/12/25/2301046.html
unzip apache-tomcat-6.0.37.zip -d ../tomcats/
weblogic 安装
参考文章 https://blogs.oracle.com/brunoborges/entry/how_to_install_weblogic_12c
nginx 安装
包含nginx_upstream_check_module 健康度检查模块
参考文章 http://my.oschina.net/wuzhaohui/blog/121822
首先下载nginx_upstream_check_module 和nginx1.4.3 将文件scp到服务器的/opt/files下
unzip到当前目录
安装依赖
打补丁
添加用户和组,注意和后面./configure里面的--user和--group一致
./configure配置文件
vi /etc/init.d/nginx
加上x权限
将nginx增加到启动列表中
让nginx随机启动
将nginx加入环境变量
nginx常用命令
python安装
参考 http://www.cnblogs.com/yuechaotian/archive/2013/06/03/3115482.html
官网下载Python-2.7.5.tgz scp到服务器/opt/files/
解压文件 tar xvf Python-2.7.5.tar.bz2 设定安装目录 ./configure --prefix=/opt/python 安装 make && make install
mysql安装
查看mysql 服务是否启动
启动mysql
停止mysql服务
/etc/my.cnf 配置
在client修改socket
在mysqld下面分别加上datadir和修改socket
service start
The server quit without updating PID file (/mydb/mysql/aft.develop.pid)的问题
删除掉/mydb/mysql/mysql-bin.index
http://blog.rekfan.com/articles/186.html
###允许远程访问 注释掉#bind-address = 127.0.0.1
###解决utf-8的问题
show variables like 'character%';
http://stackoverflow.com/questions/3513773/change-mysql-default-character-set-to-utf8-in-my-cnf
在mysql5.5之后 不能在mysqld中使用 default-character-set=utf8,否则会启动异常的
vi /etc/my.cnf
密码重置
###/etc/my.cnf
###数据库导出导入
工具增强
编辑器vim
vim 直接安装janus,节省安装插件时间
https://github.com/carlhuda/janus
常用 ctrl + p / + n gf (例如有个井号注释地址 # /home/duoduo/file.js,在# 后的路径按gf,会打开这个文件)
grep
grep增强ack
安装ack
http://brooky.cc/2012/09/28/ack-for-%E5%B7%A5%E7%A8%8B%E5%B8%AB%E7%94%A8%E7%9A%84-grep/
http://beyondgrep.com/
ps:janus里面已经安装,使用方法:Ack
搜索近期命令
shell 复制和粘贴
shell增强
安装zsh,并且配置zshrc(废弃, 建议oh-my-zsh)
#source /opt/python_env/heroku/bin/activate
shell 操作命令 生成gif
chrome安装SwitchySharp
问题,在新机器上没翻墙前是登陆不了chrome的,也就拿不到书签和扩展,没有扩展就没法翻墙, 鸡生蛋蛋生鸡的问题。好在goagent自带电池,在goagent local 下有SwitchySharp.crx
第一步是装SwitchySharp
如果最近google没被墙,自然可以商店里面直接安装;
windows用户直接在chrome中打开extensions(扩展程序), 把SwitchySharp.crx拖进去即可安装;
linux用户比较蛋疼,总之ubuntu是很蛋疼的,不能托到chrome里面去,需要将SwitchySharp.crx 重命名为SwitchySharp.zip,解压,然后在chrome extensions里面点开开发这模式,Load unpacked extension 将解压的文件夹加过来即可安装。
解决goagent翻墙后上twitter等无效
浏览器快捷键
tree
桌面通知
查找
find
find 地址 -name 文件名 find ./ -name settings.py 时间 -atime n n天前访问的文件 大小 -size n 正则 -regex
vim command P
打开vim 点击ctrl + p
压缩解压
.tar.gz 和 .tgz 解压:tar zxvf FileName.tar.gz 压缩:tar zcvf FileName.tar.gz DirName // 压缩参数加上 p可以保持权限,解压后cp -p可以保持权限不变
mysql暂时关闭外键
SET foreign_key_checks = 0;
mysql修改密码 mysql创建用户
用户相关
添加用户
添加用户组
显示各个组
添加root权限
修改密码
查看用户信息
文件下载
wget 支持断点下载的工具
查找之前命令
在shell里面会输入很多命令,有的时候你想找几百次之前的某条名利,按下ctrl + r搜索
安装ttf字体
fontpalace下载喜欢的字体,程序员一般选consolas
查看端口
linux 更新locale
sed
-n 不打印 -n p打印 d删除 w重定向 s替换 e执行命令 &表示匹配的正则 i添加行,行前 a添加行,行后
awk
awk处理列,只记录简单的分割操作,复杂的话还是用python脚本
磁盘命令
因为虚拟机给配的磁盘很小,经常因为磁盘的原因起不了服务(超大的log文件,测试时可以删)
yes输入y
tail实时打印
cd - 回到刚才的目录
查看进程树
bash输入命令时删除最后一个词
查看文件行数
获取外网IP
使用sz rz传输文件
mac需要配置,方法可以百度 mac rzbe
https://github.com/mmastrac/iterm2-zmodem
curl获得网页header信息
查看服务器连接
to get a list of the number of connections you have per ip run,
netstat -nat | awk {'print $5'} | cut -d ':' -f1 | sort | uniq -c | sort -n
查看TIME_WAIT
netstat -an | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
常用的三个状态是:ESTABLISHED 表示正在通信,TIME_WAIT 表示主动关闭,CLOSE_WAIT 表示被动关闭。
linux机器之间不输入密码直接ssh
例如 机器A想ssh到B,并且不输入密码
对于B机器需要:
vim /etc/ssh/sshd_config, 将下面几行的注释去掉
将A机器的公钥 ~/.ssh/id_rsa.pub里面的东西粘贴到B的 ~/.ssh/authorized_keys里
B机器重启ssh服务 service ssh restart
mac方法: http://www.zhihu.com/question/30640159
xshell中文乱码
在Xshell中[file]-> [open] -> 在打开的session中选择连接的那个,点击properties ->[Terminal],在右边translation中选择UTF-8,再重新连接服务器即可。 原文
录制shell
http://showterm.io/
处理json
https://stedolan.github.io/jq/manual/#Basicfilters
jq '.data[0].mention_me'
jq '.data | length'
unix /etc/passwd 解释
wiki jsmith❌1001:1000:Joe Smith,Room 1007,(234)555-8910,(234)555-0044,email:/home/jsmith:/bin/sh
User name: the string a user would type in when logging into the operating system: the logname. Must be unique across users listed in the file.
Information used to validate a user's password; in most modern uses, this field is usually set to "x" (or "", or some other indicator) with the actual password information being stored in a separate shadow password file. On Linux systems, setting this field to an asterisk ("") is a common way to disable direct logins to an account while still preserving its name, while another possible value is "NP" which indicates to use an NIS server to obtain the password.[2] Without password shadowing in effect, this field would typically contain a cryptographic hash of the user's password (in combination with a salt).
user identifier number, used by the operating system for internal purposes. It need not be unique.
group identifier number, which identifies the primary group of the user; all files that are created by this user may initially be accessible to this group.
Gecos field, commentary that describes the person or account. Typically, this is a set of comma-separated values including the user's full name and contact details.
Path to the user's home directory.
Program that is started every time the user logs into the system. For an interactive user, this is usually one of the system's command line interpreters (shells).
所以最后一个东西是用户登录后执行的玩意儿,一般为各种 shell 例如/bin/bsh、/bin/zsh 但是还有 /usr/sbin/nologin、/bin/false 这些东西 这个回答 解释了一堆,简单说就是 nologin 会打一个信息,false 则啥事儿不干
sql pro 多跳板机链接
ssh -L 9906:0.0.0.0:9906 ubuntu@跳板机1 ssh -L 9906:生产mysql服务器ip:3306 ubuntu@跳板机2
然后mysql 客户端把 mysql 链接配置配好即可 mysql -h127.0.0.1 -P 9906 -uhermes -p 注意 shell 要开着, 可以 -g -f -N 后台执行或者双 tmux 解决
zsh 出现 Ignore insecure directories and continue [y] or abort compinit [n]?
https://github.com/zsh-users/zsh-completions/issues/433
内网穿透
将本地 8000 端口映射到外网,需要一个云服务器
本机执行
服务器nginx
访问服务器 nginx 对应 ip 即可, 如果有域名则可以顺便加个dns.
另外,如果服务器出现 Warning: remote port forwarding failed for listen port xxx
可以考虑两种方案:
ssh 添加 config文件管理不同的ssh key
.ssh中可以添加 config 文件使用不同的id_rsa
ssh免密登录
本地使用ssh-keygen生成公钥之后
cat ~/.ssh/id_rsa.pub | ssh user@host "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
Last updated
Was this helpful?