苹果相关

浏览模式: 标准 | 列表 | 图文
Linux Network Statistics Tools / Commands

Linux Network Statistics Tools / Commands

不想多说啥,直接上原文地址:http://www.cyberciti.biz/faq/network-statistics-tools-rhel-centos-debian-linux/

以下内容有部分经过我的重新排版,但由于fck编辑器中有些内容会自动被code处理,所以,如果太乱,我也不想改了
1.
Type the following command:
# nstat

Sample outputs:

#kernel
IpInReceives 133243 0.0
IpInDelivers 133243 0.0
IpOutRequests 92904 0.0
IcmpOutErrors 97 0.0
IcmpOutTimeExcds 97 0.0
IcmpMsgOutType3 97 0.0
TcpActiveOpens 538 0.0
TcpEstabResets 56 0.0
TcpInSegs 129837 0.0
TcpOutSegs 89720 0.0
TcpRetransSegs 42 0.0
TcpOutRsts 704 0.0
UdpInDatagrams 3255 0.0
UdpNoPorts 97 0.0
UdpOutDatagrams 3270 0.0
Ip6OutNoRoutes 206 0.0
TcpExtTW 141 0.0
TcpExtDelayedACKs 508 0.0
TcpExtDelayedACKLocked 1 0.0
TcpExtDelayedACKLost 42 0.0
TcpExtTCPHPHits 117659 0.0
TcpExtTCPPureAcks 2158 0.0
TcpExtTCPHPAcks 605 0.0
TcpExtTCPSackRecovery 1 0.0
TcpExtTCPLossUndo 16 0.0
TcpExtTCPSackFailures 4 0.0
TcpExtTCPFastRetrans 1 0.0
TcpExtTCPSlowStartRetrans 3 0.0
TcpExtTCPTimeouts 33 0.0
TcpExtTCPDSACKOldSent 40 0.0
TcpExtTCPDSACKRecv 5 0.0
TcpExtTCPAbortOnData 120 0.0
TcpExtTCPAbortOnClose 55 0.0
TcpExtTCPSackShiftFallback 9 0.0
IpExtInOctets 180131682 0.0
IpExtOutOctets 7289106 0.0
2.
To see summary of stats, enter:
# ss -s

Sample outputs:

Total: 786 (kernel 804)
TCP: 65 (estab 40, closed 7, orphaned 0, synrecv 0, timewait 6/0), ports 56
Transport Total IP IPv6
* 804 - -
RAW 1 1 0
UDP 12 9 3
TCP 58 52 6
INET 71 62 9
FRAG 0 0 0
See ss command tutorial for more information.
3.
To see a table of all network interfaces and its summary, enter:
# netstat -i

Sample outputs:

Kernel Interface table
Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0 1500 0 941022 0 0 0 688165 0 0 0 BMRU
lo 16436 0 9304 0 0 0 9304 0 0 0 LRU
ppp0 1496 0 3784 0 0 0 4177 0 0 0 MOPRU
more...
To see summary statistics for each protocol, enter:
# netstat -s

Sample outputs:

Ip:
1092065 total packets received
0 forwarded
0 incoming packets discarded
1091681 incoming packets delivered
798913 requests sent out
895 dropped because of missing route
759 reassemblies required
375 packets reassembled ok
Icmp:
17 ICMP messages received
0 input ICMP message failed.
ICMP input histogram:
timeout in transit: 8
echo replies: 9
1747 ICMP messages sent
0 ICMP messages failed
ICMP output histogram:
destination unreachable: 1730
echo request: 17
IcmpMsg:
InType0: 9
InType11: 8
OutType3: 1730
OutType8: 17
Tcp:
4822 active connections openings
1129 passive connection openings
457 failed connection attempts
165 connection resets received
7 connections established
1062519 segments received
771394 segments send out
7158 segments retransmited
6 bad segments received.
2578 resets sent
Udp:
20846 packets received
1730 packets to unknown port received.
0 packet receive errors
19242 packets sent
UdpLite:
TcpExt:
71 invalid SYN cookies received
8 resets received for embryonic SYN_RECV sockets
142 packets pruned from receive queue because of socket buffer overrun
2109 TCP sockets finished time wait in fast timer
84 packets rejects in established connections because of timestamp
19454 delayed acks sent
6 delayed acks further delayed because of locked socket
Quick ack mode was activated 7306 times
1 packets directly queued to recvmsg prequeue.
1 bytes directly received in process context from prequeue
823921 packet headers predicted
24412 acknowledgments not containing data payload received
10150 predicted acknowledgments
242 times recovered from packet loss by selective acknowledgements
33 congestion windows recovered without slow start by DSACK
335 congestion windows recovered without slow start after partial ack
336 TCP data loss events
TCPLostRetransmit: 35
1 timeouts after reno fast retransmit
156 timeouts after SACK recovery
116 timeouts in loss state
461 fast retransmits
5 forward retransmits
608 retransmits in slow start
2073 other TCP timeouts
62 SACK retransmits failed
43074 packets collapsed in receive queue due to low socket buffer
8499 DSACKs sent for old packets
101 DSACKs sent for out of order packets
308 DSACKs received
9 DSACKs for out of order packets received
427 connections reset due to unexpected data
122 connections reset due to early user close
28 connections aborted due to timeout
TCPDSACKIgnoredOld: 3
TCPDSACKIgnoredNoUndo: 60
TCPSpuriousRTOs: 4
TCPSackShifted: 282
TCPSackMerged: 740
TCPSackShiftFallback: 1017
IpExt:
InMcastPkts: 47
OutMcastPkts: 51
InBcastPkts: 1
InOctets: 1341508973
OutOctets: 72525352
InMcastOctets: 8649
OutMcastOctets: 7519
InBcastOctets: 328
See netstat command tutorial for more information.
4.
Type the following command:
# ifconfig

OR
# /sbin/ifconfig

OR
# ifconfig eth0

eth0 Link encap:Ethernet HWaddr b8:ac:6f:65:31:e5
inet addr:192.168.1.5 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::baac:6fff:fe65:31e5/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:966334 errors:0 dropped:0 overruns:0 frame:0
TX packets:703297 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1186255648 (1.1 GiB) TX bytes:73968238 (70.5 MiB)
Interrupt:17
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:9666 errors:0 dropped:0 overruns:0 frame:0
TX packets:9666 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1399578 (1.3 MiB) TX bytes:1399578 (1.3 MiB)
ppp0 Link encap:Point-to-Point Protocol
inet addr:10.1.11.70 P-t-P:10.0.31.18 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1496 Metric:1
RX packets:3784 errors:0 dropped:0 overruns:0 frame:0
TX packets:4177 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:2400265 (2.2 MiB) TX bytes:275983 (269.5 KiB)
To display network interface statistics, enter:
# ip -s link

Sample outputs:

1: lo: mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
RX: bytes packets errors dropped overrun mcast
1444187 9960 0 0 0 0
TX: bytes packets errors dropped carrier collsns
1444187 9960 0 0 0 0
2: eth0: mtu 1500 qdisc mq state UP qlen 1000
link/ether b8:ac:6f:65:31:e5 brd ff:ff:ff:ff:ff:ff
RX: bytes packets errors dropped overrun mcast
1221956483 991501 0 0 0 24
TX: bytes packets errors dropped carrier collsns
75623937 720272 0 0 0 0
3: wlan0: mtu 1500 qdisc noop state DOWN qlen 1000
link/ether 00:21:6a:ca:9b:10 brd ff:ff:ff:ff:ff:ff
RX: bytes packets errors dropped overrun mcast
0 0 0 0 0 0
TX: bytes packets errors dropped carrier collsns
0 0 0 0 0 0
4: pan0: mtu 1500 qdisc noop state DOWN
link/ether 4a:c7:5f:0e:8e:d8 brd ff:ff:ff:ff:ff:ff
RX: bytes packets errors dropped overrun mcast
0 0 0 0 0 0
TX: bytes packets errors dropped carrier collsns
0 0 0 0 0 0
8: ppp0: mtu 1496 qdisc pfifo_fast state UNKNOWN qlen 3
link/ppp
RX: bytes packets errors dropped overrun mcast
2419881 3848 0 0 0 0
TX: bytes packets errors dropped carrier collsns
284151 4287 0 0 0 0
5.
Type the following command (you need to install and enable sar via sysstat package):
sar -n DEV

Linux 2.6.32-220.2.1.el6.x86_64 (www.cyberciti.biz) Tuesday 13 March 2012 _x86_64_ (2 CPU)
12:00:01 CDT IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
12:10:01 CDT lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
12:10:01 CDT eth0 127.13 121.32 95.45 18.34 0.00 0.00 0.00
12:10:01 CDT eth1 98.48 110.62 16.72 96.33 0.00 0.00 0.00
12:20:01 CDT lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
12:20:01 CDT eth0 139.95 133.41 106.30 19.95 0.00 0.00 0.00
12:20:01 CDT eth1 110.65 121.85 18.14 107.13 0.00 0.00 0.00
12:30:01 CDT lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
12:30:01 CDT eth0 147.85 132.49 115.78 20.45 0.00 0.00 0.00
12:30:01 CDT eth1 111.88 127.39 18.61 117.65 0.00 0.00 0.00
12:40:01 CDT lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
12:40:01 CDT eth0 136.75 124.64 105.24 19.48 0.00 0.00 0.00
12:40:01 CDT eth1 101.65 115.32 17.58 104.50 0.00 0.00 0.00
12:50:01 CDT lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
12:50:01 CDT eth0 131.45 125.69 96.49 19.58 0.00 0.00 0.00
12:50:01 CDT eth1 101.41 111.31 17.54 96.78 0.00 0.00 0.00
01:00:01 CDT lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
01:00:01 CDT eth0 140.30 133.27 102.17 20.75 0.00 0.00 0.00
01:00:01 CDT eth1 106.90 119.51 18.53 103.09 0.00 0.00 0.00
01:10:01 CDT lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
01:10:01 CDT eth0 152.03 127.74 125.56 19.85 0.00 0.00 0.00
01:10:01 CDT eth1 115.60 134.57 18.73 126.96 0.00 0.00 0.00
01:20:01 CDT lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
01:20:01 CDT eth0 138.55 130.55 103.03 20.20 0.00 0.00 0.00
....
..
....
..
.
01:00:01 CDT eth1 156.82 169.48 28.83 138.49 0.00 0.00 0.00
01:10:01 CDT lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
01:10:01 CDT eth0 215.19 194.82 163.11 30.99 0.00 0.00 0.00
01:10:01 CDT eth1 162.49 183.79 28.36 163.70 0.00 0.00 0.00
01:20:01 CDT lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
01:20:01 CDT eth0 200.20 192.23 140.64 30.93 0.00 0.00 0.00
01:20:01 CDT eth1 153.60 166.96 27.32 140.26 0.00 0.00 0.00
01:30:01 CDT lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
01:30:01 CDT eth0 111.98 103.58 79.12 16.52 0.00 0.00 0.48
01:30:01 CDT eth1 87.50 95.58 14.74 79.35 0.00 0.00 0.00
Average: IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
Average: lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
Average: eth0 211.21 196.20 156.18 31.20 0.00 0.00 0.01
Average: eth1 159.10 174.52 28.00 149.95 0.00 0.00 0.00
Or type the following command:
# sar -n DEV 1 3

Sample outputs:

Linux 2.6.32-220.2.1.el6.x86_64 (www.cyberciti.biz) Tuesday 13 March 2012 _x86_64_ (2 CPU)
01:44:03 CDT IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
01:44:04 CDT lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
01:44:04 CDT eth0 161.70 154.26 105.20 26.63 0.00 0.00 0.00
01:44:04 CDT eth1 145.74 142.55 25.11 144.94 0.00 0.00 0.00
01:44:04 CDT IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
01:44:05 CDT lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
01:44:05 CDT eth0 162.14 156.31 107.46 42.18 0.00 0.00 0.00
01:44:05 CDT eth1 135.92 138.83 39.38 104.92 0.00 0.00 0.00
01:44:05 CDT IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
01:44:06 CDT lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
01:44:06 CDT eth0 303.92 293.14 272.91 37.40 0.00 0.00 0.00
01:44:06 CDT eth1 252.94 290.20 34.87 263.50 0.00 0.00 0.00
Average: IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
Average: lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
Average: eth0 210.37 202.34 163.19 35.66 0.00 0.00 0.00
Average: eth1 178.93 191.64 33.36 171.60 0.00 0.00 0.00
-----
最后再附送两个
1、netstat -s TCP连接失败 相关统计 解释 (http://blog.sina.com.cn/s/blog_781b0c850101pu2q.html)
针对问题:TCP连接失败
分析:netstat -s输出中和连接失败相关的参数
202270382 invalid SYN cookies received --- 三次握手ack包,syncookies校验没通过;
13700572 resets received for embryonic SYN_RECV sockets ---syn_recv状态下,收到非重传的syn包,则返回reset
1123035 passive connections rejected because of time stamp ---开启sysctl_tw_recycle,syn包相应连接的时间戳 小于 路由中保存的时间戳;
14886782 failed connection attempts --- syn_recv状态下,socket被关闭; 或者 收到syn包(非重传)
438798 times the listen queue of a socket overflowed ---收到三次握手ack包,accept队列满
438798 SYNs to LISTEN sockets ignored ---收到三次握手ack包,因各种原因(包括accept队列满) 创建socket失败
2、Linux 2.6 - man page for nstat (linux section 8) (http://www.unix.com/man-page/linux/8/nstat/)
3、老王的监控Netstat数据 (http://huoding.com/2015/04/09/427)
关于CodeAnyWhere

关于CodeAnyWhere

最近收到一封邮件,大意是,phpanywhere已经改名为codeanywhere了,我看了一下邮件中提及的博客日期,发现贴子地址是:http://www.neatstudio.com/show-1305-1.shtml ,已经是N年前的事情了。

邮件中提及:As you may have heard we have changed our name to Codeanywhere a couple of years back and now we have an issue. Namely we lost the domain phpanywhere.net and know all your link lead to nowhere.

为了以防万一,我查了一下百科:

History[edit]
In 2009 PHPanywhere (the predecessor of Codeanywhere) was launched, which was a web-based FTP client and text editor, designed for PHP.[4] That project stayed idle until May 22, 2013 when the founders launched Codeanywhere.

Codeanywhere raised $600,000 from World Wide Web Hosting on July 15, 2013 when Ben Welch-Bolen became a board member.[5] In August of 2014 Codeanywhere was accepted in Techstars’s Fall Boston Class.[6] In 2014, as part of the TechCrunch Disrupt NY Conference, the audience voted Codeanywhere the best company in Startup Alley.[1]

so,phpanywhere确实是codeanywhere的前身。。。于是顺手改掉了那篇博客,顺便说一下,codeanywhere很早就在ipad上面有APP了,而且我还用过,只是居然真的不知道它就是phpanywhere....


How to get a “codesigned” gdb on OSX?

How to get a “codesigned” gdb on OSX?

这是一篇backup的文章。起因是我的命令行下的gdb出现了:

Starting program: /usr/local/Cellar/php56/5.6.9/bin/php /server/yii hprose
Unable to find Mach task port for process-id 30717: (os/kern) failure (0x5).
(please check gdb is codesigned - see taskgated(8))

于是google了一下,发现也有人在问类似的问题:

Because I need a Python-enabled gdb, I installed another version via

brew tap homebrew/dupes
brew install gdb
I want to use this gdb with Eclipse CDT, where I entered the path to the binary in the Debugging settings. However, launching a program for debugging fails with the following message:

Error in final launch sequence
Failed to execute MI command:
-exec-run
Error message from debugger back end:
Unable to find Mach task port for process-id 39847: (os/kern) failure (0x5).\n (please check gdb is codesigned - see taskgated(8))
Unable to find Mach task port for process-id 39847: (os/kern) failure (0x5).\n (please check gdb is codesigned - see taskgated(8))
What does "codesigned" mean in this context? How can I get this gdbrunning?

有一个5个点赞的,我发现无效:

t would seem you need to sign the executable. See these links for more information. You should be able to get away with self signing if you don't plan on redistributing that version of gdb.

https://developer.apple.com/library/mac/#documentation/Security/Conceptual/CodeSigningGuide/Introduction/Introduction.html

https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man1/codesign.1.html

Alternatively, you could disable code signing on your system, although this presents a security risk. To do so try running sudo spctl --master-disable in the Terminal.

24人点赞的看上去不错:

I.1 Codesigning the Debugger

The Darwin Kernel requires the debugger to have special permissions before it is allowed to control other processes. These permissions are granted by codesigning the GDB executable. Without these permissions, the debugger will report error messages such as:

Starting program: /x/y/foo
Unable to find Mach task port for process-id 28885: (os/kern) failure (0x5).
(please check gdb is codesigned - see taskgated(8))
Codesigning requires a certificate. The following procedure explains how to create one:

Start the Keychain Access application (in /Applications/Utilities/Keychain Access.app)
Select the Keychain Access -> Certificate Assistant -> Create a Certificate... menu
Then:
Choose a name for the new certificate (this procedure will use "gdb-cert" as an example)
Set "Identity Type" to "Self Signed Root"
Set "Certificate Type" to "Code Signing"
Activate the "Let me override defaults" option
Click several times on "Continue" until the "Specify a Location For The Certificate" screen appears, then set "Keychain" to "System"
Click on "Continue" until the certificate is created
Finally, in the view, double-click on the new certificate, and set "When using this certificate" to "Always Trust"
Exit the Keychain Access application and restart the computer (this is unfortunately required)
Once a certificate has been created, the debugger can be codesigned as follow. In a Terminal, run the following command...

codesign -f -s "gdb-cert" <gnat_install_prefix>/bin/gdb
... where "gdb-cert" should be replaced by the actual certificate name chosen above, and should be replaced by the location where you installed GNAT.
source: https://gcc.gnu.org/onlinedocs/gcc-4.8.1/gnat_ugn_unw/Codesigning-the-Debugger.html

这个4人点赞的简洁明了:

I made gdb work on OSX 10.9 without codesigning this way (described here):

Install gdb with macports. (may be you can skip it)

sudo nano /System/Library/LaunchDaemons/com.apple.taskgated.plist
change option string from -s to -sp at line 22, col 27.

reboot the computer.

Use gdb

然而这都没有什么卵用,这时候一个2人点赞的说了一个重点:

It's a very old topic, but I am adding a response, because out of many available instructions, only one contained just the right steps to make a self-signed debugger work.

You have to create a self-signed root certificate and then sign the gdb executable with it, but many people complained that it did not work for them. Neither did it for me until I stumbled upon this link.

The key point missing in other manuals is that you have to restart your computer for the changes to take effect. Once I did that, everything worked as intended.

I hope, this will help others.

是的,他在have to restart上加粗了!!!

最后一个回复表示使用了4人点赞的那个建议,并表示他就是这么完成的!原文来自:http://stackoverflow.com/questions/13913818/how-to-get-a-codesigned-gdb-on-osx

hostname被清除后导致proftpd无法启动的故障

hostname被清除后导致proftpd无法启动的故障

由于需要上传一个文件到服务器,所以才发现ftp服务居然没有启动。

到线上进行检查:

root@(none):~# ps aux|grep proftpd
root 31447 0.0 0.0 9288 2004 pts/0 S+ 17:11 0:00 grep proftpd
root@(none):~# /etc/init.d/proftpd start
[....] Starting ftp server: proftpd_none_ proftpd[31473]: warning: unable to determine IP address of '_none_'
_none_ proftpd[31473]: error: no valid servers configured
_none_ proftpd[31473]: Fatal: error processing configuration file '/etc/proftpd/proftpd.conf'
failed!

咦,启动失败,这个_none_是什么意思?难道就是那个hostname没有设定的原因?

于是:hostname neatstudio.com ,然后重新退出ssh并登录,再启动ftp就OK了。

上文中的root@(none),我也不知道这个hostname是被哪个程序给清除了。不过也确实才知道,原来hostname不设置还会导致proftpd无法启动!汗

快速将googleapis的链接换为useso的国内镜像

快速将googleapis的链接换为useso的国内镜像

在使用第三方的程序时,特别是国外的项目,总是会碰到引用googleapis的问题,比如字体之类的,对于国外用户来说这玩意真方便,google也会帮你做CDN,多好啊,但在国内,你遇到的卡顿就不是一点两点了,有时候甚至会拖慢得页面打不开

所以,Wordpress、drupal 之类的程序在拿到手的第一时间就应该将里面的地址换掉,当然Wordpress还有插件,但drupal就不一定有了!

那怎么办?偷懒的办法是用PHP程序,递归查找并替换,如果是在本地,找个工具替换一下即可,现在的IDE都有这功能,如果已经部署到线上,那么只要你有ssh,你就可以尝试:sed -i s/googleapis/useso/g `grep -rl googleapis ./` ,该命令是将当前目录下含有googleapis的文件列出来,然后用sed进行全文替换。

如果做国外站的用户,我想他们一定是很痛苦的,如果用googleapis的数据吧,国内打开就卡死,用国内的cdn吧,国外又卡。当然 有解决方案~~

How to set up a clean UTF-8 environment in Linux

How to set up a clean UTF-8 environment in Linux

本来不想转,但真心是有用,以前的方法也有点过时,而且主要是不方便,所以就来贴个更全的。这种问题非常容易 遇到,用ubuntu、debian在阿里云上,原来都正常的,你只要一apt-get update一下,原来的LC环境就全没了。

原文地址在:http://perlgeek.de/en/article/set-up-a-clean-utf8-environment , 我上一次写关于这个的问题是在2012年了,那篇的标题是:perl: warning: Setting locale failed. 也可以看一下

How to set up a clean UTF-8 environment in Linux

Many people have problems with handling non-ASCII characters in their programs, or even getting their IRC client or text editor to display them correctly.

To efficiently work with text data, your environment has to be set up properly - it is so much easier to debug a problem which has encoding issues if you can trust your terminal to correctly display correct UTF-8.

I will show you how to set up such a clean environment on Debian Lenny, but most things work independently of the distribution, and parts of it even work on other Unix-flavored operating systems like MacOS X.

Choosing an encoding

In the end the used character encoding doesn't matter much, as long as it's a Unicode encoding, i.e. one which can be used to encode all Unicode characters.

UTF-8 is usually a good choice because it efficiently encodes ASCII data too, and the character data I typically deal with still has a high percentage of ASCII chars. It is also used in many places, and thus one can often avoid conversions.

Whatever you do, chose one encoding and stick to it, for your whole system. On Linux that means text files, file names, locales and all text based applications (mutt, slrn, vim, irssi, ...).

For the rest of this article I assume UTF-8, but it should work very similarly for other character encodings.

Locales: installing

Check that you have the locales package installed. On Debian you can do that with.

$ dpkg -l locales Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Cfg-files/Unpacked/Failed-cfg/Half-inst/trig-aWait/Trig-pend |/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad) ||/ Name           Version        Description +++-==============-==============-============================================ ii  locales        2.7-18         GNU C Library: National Language (locale) da

The last line is the important one: if it starts with ii, the package is installed, and everything is fine. If not, install it. As root, type

$ aptitude install locales

If you get a dialog asking for details, read on to the next section.

Locales: generation

make sure that on your system an UTF-8 locale is generated. As root, type

$ dpkg-reconfigure locales

You'll see a long list of locales, and you can navigate that list with the up/down arrow keys. Pressing the space bar toggles the locale under the cursor. Make sure to select at least one UTF-8 locale, for example en_US-UTF-8 is usually supported very well. (The first part of the locale name stands for the language, the second for the country or dialect, and the third for the character encoding).

In the next step you have the option to make one of the previously selected locales the default. Picking a default UTF-8 locale as default is usually a good idea, though it might change how some programs work, and thus shouldn't be done servers hosting sensitive applications.

Locales: configuration

If you chose a default locale in the previous step, log out completely and then log in again. In any case you can configure your per-user environment with environment variables.

The following variables can effect programs: LANG, LANGUAGE, LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES, LC_PAPER, LC_NAME, LC_ADDRESS, LC_TELEPHONE, LC_MEASUREMENT, LC_IDENTIFICATION.

Most of the time it works to set all of these to the same value. Instead of setting all LC_ variables separately, you can set theLC_ALL. If you use bash as your shell, you can put these lines in your ~/.bashrc and ~/.profile files:

export LC_ALL=en_US.UTF-8 export LANG=en_US.UTF-8 export LANGUAGE=en_US.UTF-8

To make these changes active in the current shell, source the .bashrc:

$ source ~/.bashrc

All newly started interactive bash processes will respect these settings.

A Warning about Non-Interactive Processes

There are certain processes that don't get those environment variables, typically because they are started by some sort of daemon in the background.

Those include processes started from cron, at, init scripts, or indirectly spawned from init scripts, like through a web server.

You might need to take additional steps to ensure that those programs get the proper environment variables.

Locales: check

Run the locale program. The output should be similar to this:

LANG=en_US.UTF-8 LANGUAGE=en_US.UTF-8 LC_CTYPE="en_US.UTF-8" LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.UTF-8" LC_COLLATE="en_US.UTF-8" LC_MONETARY="en_US.UTF-8" LC_MESSAGES="en_US.UTF-8" LC_PAPER="en_US.UTF-8" LC_NAME="en_US.UTF-8" LC_ADDRESS="en_US.UTF-8" LC_TELEPHONE="en_US.UTF-8" LC_MEASUREMENT="en_US.UTF-8" LC_IDENTIFICATION="en_US.UTF-8" LC_ALL=en_US.UTF-8

If not you've made a mistake in one of the previous steps, and need to recheck what you did.

Setting up the terminal emulator

Setting up the terminal emulator for your terminal emulator strongly depends on what you actually use. If you use xterm, you can start it as xterm -en utf-8, konsole and the Gnome Terminal can be configured in their respective configuration menus.

Testing the terminal emulator

To test if you terminal emulator works, copy and paste this line in your shell:

perl -Mcharnames=:full -CS -wle 'print "\N{EURO SIGN}"'

This should print a Euro sign € on the console. If it prints a single question mark instead, your fonts might not contain it. Try installing additional fonts. If multiple different (nonsensical) characters are shown, the wrong character encoding is configured. Keep trying :-).

SSH

If you use SSH to log in into another machine, repeat the previous steps, making sure that the locale is set correctly, and that you can view a non-ASCII character like the Euro sign.

Screen

The screen program can work with UTF-8 if you tell it to.

The easiest (and sometimes the only) way is to start it with the -U option:

$ screen -U

and also when detaching (screen -Urd or so).

Inside a running screen you can try Ctrl+a :utf8 on<return>. If that doesn't work, exit your screen and start a new one with -U

Irssi

There's a complete guide for setting up irssi to use UTF-8, which partially overlaps with this one. The gist is:

/set term_charset utf-8 /set recode_autodetect_utf8 ON /set recode_fallback ISO-8859-15 /set recode ON
gogs 如何不使用端口进行访问

gogs 如何不使用端口进行访问

gogos 默认是 3000端口,如果你本身已经有了其他WEB服务,比如apache,当然不可能同时占用80端口,这时候就可以利用apapche的proxy功能。如果你是apt-get 安装 的apache,就方便了,debian/ubuntu 都支持a2ensiate,a2enmod这样的小脚本。你只要打开a2enmod proxy proxy_http就行了,然后新建一个site加入以下配置

<VirtualHost *:80>
ServerAdmin test@test.com
ServerName yoursitename
ProxyRequests off
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000
<Proxy *>
Order Deny,Allow
Allow from all
</Proxy>
ErrorLog ${APACHE_LOG_DIR}/yoursitename.log
LogLevel warn
</VirtualHost>
是不是很简单,这时候你用supervisor启动后就可以通过WEB访问了.不过这时候有具小缺点,那就是如果你killall gogs进程的话,你会发现再也启动不了了.看启动的LOG会告诉你3000端口被占用,用netstat -an|grep 3000,发现有N个进程都是在CLOSE_WAIT的情况,这时候用: echo $(netstat -anp|grep 127.0.0.1:3000 |awk '{print $7}') 发现,全是apache2占着这些进程.

怀疑刚才在强杀gogs进程的时候,apache因为开着proxy导致刚刚向3000端口发起请求就挂起,导致异常关闭所以一直卡住(以前用nginx的做反代的时候也有类似问题,只要客户机挂了,nginx必须 重启),所以我重启了一下apache,立刻发现gogs启动成功.

至此,如果要 重启gogs最好是/etc/init.d/supervisor restart ,如果不正常就再重启一下apache...

OK,问题全部解决

Linux 系统挂载数据盘

Linux 系统挂载数据盘

下面的文字来自于aliyun的帮助文件,原文地址:http://help.aliyun.com/knowledge_detail.htm?spm=5176.7114037.1996646101.3.7IHA8N&categoryId=8314844&knowledgeId=5974196&pos=2。

步骤很简单
1、fdisk -l ,看一下有哪些磁盘没有挂载,如果是阿里云的第一块磁盘,默认就是/dev/xvdb
2、fdisk -S 56 /dev/xvdb ,按顺序输入:n , p , 1 ,后面就直接回车两次就行了,这时候再fdisk -l,会看到有一块硬盘是/dev/xvdb1
3、mkfs.ext3 /dev/xvdb1 ,对分区进行格式化,你可以选择ext3或者4
4、将分区信息写到/etc/fstab里,echo '/dev/xvdb1 /datas ext3 defaults 0 0 ' >> /etc/fstab
5、mkdir /datas
6、mount /dev/xvdb1 /datas
就是这样简单。如果需要图文并茂,还是看上面的网址吧
/etc/apt/sources.list won't accept URLs with https connection

/etc/apt/sources.list won't accept URLs with https connection

因为安装gogs遇到了一些奇怪的问题,所以我不得不尝试换个方式,于是我想,我是不是可以用apt来安装 ,毕竟官方在这一页有说明:http://gogs.io/docs/installation/install_from_packages.html,于是我到 https://packager.io/gh/pkgr/gogs/install?bid=190#debian-7-gogs 进行了查看,按照上面写的进行操作:

wget -qO - https://deb.packager.io/key | sudo apt-key add -
echo "deb https://deb.packager.io/gh/pkgr/gogs wheezy pkgr" | sudo tee /etc/apt/sources.list.d/gogs.list
sudo apt-get update
sudo apt-get install gogs

执行到第三步就报错了:

E: The method driver /usr/lib/apt/methods/https could not be found.

这,这搞什么?google了一下,原来有这个问题的人很多,但也很好解决,先把刚才的gogs.list中的内容注释掉,运行一下:

apt-get install apt-transport-https

然后就OK了。上面的帮助内容来自:http://unix.stackexchange.com/questions/166917/etc-apt-sources-list-wont-accept-urls-with-https-connection,我还以为是stackfollow呢。结果居然不是。。。

几个常见的命令:cat,head,tail,vim

几个常见的命令:cat,head,tail,vim

常常遇到这样的问题,出门在外,突然收到消息说程序出错了,打开网页一看,居然是xxxx.php 第 n行处理xxx有错误。这时候,如果有电脑,还好办一点。如果没有怎么办?

手机上我装 了issh ,远程上线后直接看一下好象也是个办法,这时候,上面的几个命令就有用了。cat / head /tail / vim

cat -n xxxx.php ,先大概的瞄一下。

如果是前10行,默认head就可以看了,如果超出一点,比如前20行,head -n 20 xxx.php

如果是尾部,tail -n 20 xxxx.php (tail 命令更适合用来查看log文件,如tail -f xxx.log,你就可以盯着屏幕了)

看起来这样都能看到问题,可如果不知道文件行数怎么办?

cat xxx.php |wc -l,先看一下行数

如果想直接改掉,就vim xxx.php,然后 :30 ,直接跳至30行,直接xxxx就改了

嗯,如果是自己的项目这样可以,如果不行,还是安稳点,不过这些小技巧还是可以记一下的