记录自己无事可做的时候可以做的事
1.打字、练五笔
2.背诵名家名篇
3.看若干H网站
4.修改更新blog:全面拒绝无认知式的转载,确保每篇博文精练
–反思
我曾经整块时间都干了什么
1、聊qq
2、逛淘宝、b2c、团购
3、下片子
4、下歌
5、各种SNS
记录自己无事可做的时候可以做的事
1.打字、练五笔
2.背诵名家名篇
3.看若干H网站
4.修改更新blog:全面拒绝无认知式的转载,确保每篇博文精练
–反思
我曾经整块时间都干了什么
1、聊qq
2、逛淘宝、b2c、团购
3、下片子
4、下歌
5、各种SNS
1.安装PPTP VPN
apt-get update apt-get upgrade apt-get install pptpd
2.配置PPTP VPN
使用你喜欢的编辑器,编辑/etc/pptpd.conf 。修改localip,remoteip的ip地址段,例如修改为:
localip 10.10.10.1 remoteip 10.10.10.100-200
编辑/etc/ppp/pptpd-options,修改ms-dns 的dns地址,例如可以修改为:
ms-dns 211.65.64.65 ms-dns 8.8.8.8
编辑/etc/ppp/chap-secrets,设置用户名密码,格式如下:
user1 pptpd password1 * user2 pptpd password2 10.10.10.102
格式一为不限定分配ip地址,格式二为限定分配ip地址。
编辑/etc/sysctl.conf,修改#net.ipv4.ip_forward=1为net.ipv4.ip_forward=1。执行如下命令(打开转发):
sysctl -p
3.iptables防火墙设置(iptables转发规则)
iptables -A INPUT -p gre -j ACCEPT iptables -A OUTPUT -p gre -j ACCEPT iptables -A INPUT -p tcp --sport 1723 -j ACCEPT iptables -A OUTPUT -p tcp --dport 1723 -j ACCEPT iptables -t nat -A POSTROUTING -s 10.10.10.0/24 -o eth0 -j MASQUERADE
Debian默认防火墙是全通的,因此前四行可以选择不执行。建议将第五行加入到/etc/rc.local。如果不加,有可能会出现连上VPN,但是上不了网的情况
像vps,ifconfig后要通过venet0来走
iptables -t nat -A POSTROUTING -s 10.10.10.0/24 -o venet0 -j MASQUERADE
没有ppp设备,需要执行如下命令:
mknod /dev/ppp c 108 0
4.启动PPTP 服务
执行如下命令,启动PPTP服务:
/etc/init.d/pptpd restart
pptp搭建的vpn代理上网很慢
解决:
在pptp所在的linux服务的iptables的*filter表中加入 -I FORWARD -p tcp --syn -i ppp+ -j TCPMSS --set-mss 1356 来源:http://hi.baidu.com/624686/blog/item/5f3e32c428e4e0a38226acb1.html 方法2: 在/etc/ppp/ip-up最后添加一行 /sbin/ifconfig $1 mtu 1356 重启pptpd /etc/init.d/pptpd restart
限制pptp vpn用户单个连接的简单方法
实现方法很简单。只要在/etc/ppp文件夹下面建立一个名为auth-up的文件。在里面写入如下内容即可: #!/bin/sh # get the username/ppp line number from the parameters REALDEVICE=$1 USER=$2 # create the directory to keep pid files per user mkdir -p /var/run/pptpd-users # if there is a session already for this user, terminate the old one if [ -f /var/run/pptpd-users/$USER ]; then kill -HUP `cat /var/run/pptpd-users/$USER` fi # copy the pid file of current user to /var/run/pptpd-users cp "/var/run/$REALDEVICE.pid" /var/run/pptpd-users/$USER 来源:http://vastars.info/linux/pptp-vpn.html
——below add at 2011-05-17——
方便查看在线用户
#vim ~/.bashrc
最后一行加入
alias online='last | grep still | grep ppp |sort -k 2,2'
#source ~/.bashrc
正好有一台测试机
试试nginx升级
原来版本是nginx0.8.54
下载最新版的nginx
#wget http://nginx.org/download/nginx-0.9.5.tar.gz
解压缩
#tar vxzf nginx-0.9.5.tar.gz
新版本编译
root@debian:~/nginx-0.9.5# cd nginx-0.9.5/
root@debian:~/nginx-0.9.5# ./configure
root@debian:~/nginx-0.9.5# make
make -f objs/Makefile
make[1]: Entering directory `/root/nginx-0.9.5′
gcc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Wunused-function -Wunused-variable -Wunused-value -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \……………………中间省略………………………………………….
make[1]: Leaving directory `/root/nginx-0.9.5′
make -f objs/Makefile manpage
make[1]: Entering directory `/root/nginx-0.9.5′
sed -e “s|%%PREFIX%%|/usr/local/nginx|” \
-e “s|%%PID_PATH%%|/usr/local/nginx/logs/nginx.pid|” \
-e “s|%%CONF_PATH%%|/usr/local/nginx/conf/nginx.conf|” \
-e “s|%%ERROR_LOG_PATH%%|/usr/local/nginx/logs/error.log|” \
< man/nginx.8 > objs/nginx.8
make[1]: Leaving directory `/root/nginx-0.9.5′
编译完成
开始升级
root@debian:~/nginx-0.9.5# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old
关键 拷贝objs下的nginx
root@debian:~/nginx-0.9.5# cp objs/nginx /usr/local/nginx/sbin/
关键 升级
root@debian:~/nginx-0.9.5# make upgrade /usr/local/nginx/sbin/nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful kill -USR2 `cat /usr/local/nginx/logs/nginx.pid` sleep 1 test -f /usr/local/nginx/logs/nginx.pid.oldbin kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`
查看版本
root@debian:~/nginx-0.9.5# /usr/local/nginx/sbin/nginx -v nginx: nginx version: nginx/0.9.5
确实是无缝升级的,中间没有停顿
———————————nginx自动更新脚本 update 2011-06-01————————————–
root@debian:~# vim nginxupdate.sh
#!/bin/bash
#for nginx updating
version=`curl http://nginx.org/en/download.html | sed 's/.tar.gz.*$//g' | sed 's/^.*download\/nginx-//g'`
wget http://nginx.org/download/nginx-${version}.tar.gz
tar vxzf nginx-${version}.tar.gz
cd nginx-${version}/
./configure
make
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old
cp objs/nginx /usr/local/nginx/sbin/
make upgrade
cd ..
rm -rf nginx-${version}
rm -f nginx-${version}.tar.gz
在cron里加入,每个礼拜更新一次
0 0 * * 0 bash /root/nginxupdate.sh
用iptables命令是及时生效的,用两台机很便于测试学习
filter是最常用的表,在filter表中最常用的三个目标是ACCEPT、DROP和REJECT。
DROP会丢弃数据包,不再对其进行任何处理。REJECT会把出错信息传送至发送数据包的主机。
比如:
iptables -I INPUT -s 219.230.xxx.xxx -j DROP
这样ping会直接ping不通,无任何信息;
iptables -I INPUT -s 219.230.xxx.xxx -j REJECT
目标主机不能到达 “Destination Host Unreachable”信息说明对方主机不存在或者没有跟对方建立连接。
iptables -F
iptables -X
iptables -Z
#允许本地回环接口(即运行本机访问本机)
iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT
# 允许已建立的或相关连的通行
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
#允许所有本机向外的访问
iptables -A OUTPUT -j ACCEPT
# 允许访问22端口
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
#允许访问80端口
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
#允许FTP服务的21和20端口
iptables -A INPUT -p tcp --dport 21 -j ACCEPT iptables -A INPUT -p tcp --dport 20 -j ACCEPT
#如果有其他端口的话,规则也类似,稍微修改上述语句就行
#禁止其他未允许的规则访问
iptables -A INPUT -j REJECT iptables -A FORWARD -j REJECT
#屏蔽单个IP的命令是
iptables -I INPUT -s 123.45.6.7 -j DROP
#封整个段即从123.0.0.1到123.255.255.254的命令
iptables -I INPUT -s 123.0.0.0/8 -j DROP
#封IP段即从123.45.0.1到123.45.255.254的命令
iptables -I INPUT -s 124.45.0.0/16 -j DROP
#封IP段即从123.45.6.1到123.45.6.254的命令是
iptables -I INPUT -s 123.45.6.0/24 -j DROP
简单查看 #iptables –list
iptables -L -n
v:显示详细信息,包括每条规则的匹配包数量和匹配字节数
x:在 v 的基础上,禁止自动单位换算(K、M)
n:只显示IP地址和端口号,不将ip解析为域名
用iptables做SNAT的时候,查看需要再加 -t nat
iptables -L -t nat
将所有iptables以序号标记显示,执行:
iptables -L -n --line-numbers
比如要删除INPUT里序号为8的规则,执行:
iptables -D INPUT 3 (注意大小写)
使用ssh-keygen来生成密钥对
(具体参数请参阅man ssh-keygen)
ssh-keygen -b 1024 -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
5c:81:74:f3:00:97:65:8a:09:ce:0e:43:ee:d7:66:72 root@debian
The key’s randomart image is:
+–[ RSA 1024]—-+
| . ..oo*oo |
| o o ..=.B |
| + o o o . |
| . + o . |
| . + E |
| . = |
| |
| |
| |
+—————–+
ssh-keygen -b 2048 -t rsa -f ~/.ssh/id_rsa -q -N ""
方法1:
刚才生成了一对密钥,把私钥放在自己的机器上的~/.ssh/目录下并保证访问权限是“-rw——-”(即600)。私钥永远不要给别人。
再把生成的公钥放在要连接的远程主机的~/.ssh/目录下并改名为authorized_keys,并且保证文件除了属主外没有被人修改的权限“-rw——-”(即600)。公钥无需保密
方法2:
linux内置了ssh-copy-id命令,直接使用
ssh-copy-id [email protected]
然后按提示输入密码之后,此脚本会自动将公钥copy到目标机器用户目录下的authorized_keys中并修改权限。对于一个key管理大批量主机时自动化分发。其实就是方法1的脚本实现。
如果目标主机ssh端口不是22,公钥也不是id_rsa.pub,可以指定端口和公钥
ssh-copy-id -i /home/secure.pub "-p 3322 [email protected]"
ssh,scp使用密钥登陆(-i指定私钥路径)
ssh -i jpuyy-key [email protected]
scp -i jpuyy-key filename [email protected]:/home/
上面在生成密钥对的时候会提示输入密钥,需要更改id_rsa文件的密码时,使用如下命令即可更改。
ssh-keygen -f id_rsa -p
判断一对公私钥是不是一对
diff <( ssh-keygen -y -e -f "~/.ssh/id_rsa" ) <( ssh-keygen -y -e -f "ec2.demo.pub" )
如果 diff 有输出则不是一对
验证 cert 是不是合法
ssh-keygen -L -f ~/.ssh/id_rsa-cert.pub
办公室一台弄过来的电脑
装了debian6.0
debian/ubuntu 是好东西,也是我平时用的最多的linux
apt给人们带来的很大的方便
总是找源的问题
还是不想麻烦了,以后就用apt-spy解决找源
到这里去下载对应的版本http://packages.debian.org/sid/i386/apt-spy/download
下好后
apt-spy -d unstable -a asia -t 5
……………………………………………………………………………………………………
Tips
* To retrieve the latest list of Debian mirrors, run (as root)
# apt-spy update
* To find the fastest mirror in North America for testing, run
# apt-spy -d testing -a north-america
* To find the fastest mirror in Germany for stable, run
# apt-spy -d stable -s de
FAQ’s
Q. What are the region (-d argument) codes?
A. africa, asia, europe, north-america, oceania, and south-america
Q. What if I want apt-spy to only text x mirrors?
A. Add the argument -e x. For example, apt-spy -d unstable -a asia -e 5 would test 5 mirrors hosting unstable, and located in Asia.
把sources.list覆盖
#cat /etc/apt/sources.list.d/apt-spy.list > /etc/apt/sources.list
接下来想把这两条命令写到一个bash里,并用cron每天执行一次
#vim /root/renewapt.sh
#for update /etc/sources.list using apt-spy
#!/bin/bash
apt-spy update
apt-spy -d unstable -a asia -t 5
cat /etc/apt/sources.list.d/apt-spy.list > /etc/apt/sources.list
#crontab -e
0 0 * * * bash /root/renewapt.sh