分类: 计算机 Computer

  • Linux 下用 netcat 测量 tcp 连接建立时间

    本文未经验证,仅供参考。

    我们希望测量两机之间 tcp 连接的建立时间,以排查网络连接缓慢的问题。
    测量连接建立可以用 nc (netcat)。

    以下是在 RHEL5 (CentOS 5) 的测试方法,其他发行版的 nc 参数可能会有所不同。

    Server端监听 1567 端口:
    ~~~
    # nc -k -l 1567
    ~~~
    使用 -k 参数使之一直保持监听。

    Client 端使用脚本建立1000次连接,并用 time 命令进行计时:

    /tmp/testcon.sh
    ~~~
    #!/bin/bash

    NUM=1000 # How many connection to establish.
    IPADDR=”192.168.122.136″
    PORT=”1567″

    for((i=0; i<$NUM; i++)) do nc $IPADDR $PORT < /dev/null if [ $? -ne "0" ];then echo "*" fi done ~~~ (更多…)

  • Mysql 5.5 的 UNIX Domain Socket 通信方式

    疑问

    我们看到用 mysql_secure_installation 安装配置的 mysql-server (mariadb-server),默认的 host 有 localhost, 127.0.0.1 和 ::1 .

    那么问题来了,默认情况下,对于 IPv4, localhost 跟 127.0.0.1 应该是等同的。为什么在 mysql 这个数据库的认证记录中,会同时出现 localhost 和 127.0.0.1 两个不同的记录呢?

    MariaDB [mysql]> select host,user,password from user;
    +-----------+------+-------------------------------------------+
    | host | user | password |
    +-----------+------+-------------------------------------------+
    | localhost | root | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 |
    | 127.0.0.1 | root | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 |
    | ::1 | root | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 |
    +-----------+------+-------------------------------------------+


    (更多…)

  • 对 Capabilities (libcap, getcap, setcap) 的基本了解

    安装 Wireshark 的时候,有一步是给 dumpcap 读网卡的权限,使得普通用户也可以使用 Wireshark 进行抓包。

    # setcap 'CAP_NET_RAW+eip CAP_NET_ADMIN+eip' /usr/sbin/dumpcap
    

    那么 setcap 是个啥玩意呢?


    (更多…)

  • RHEL7 无法启动KVM (virt-manager: KVM is not installed)

    1. 检查CPU是否支持硬件辅助虚拟化
    ~~~
    egrep ‘^flags.*(vmx|svm)’ /proc/cpuinfo
    ~~~

    2. 安装所需的包
    ~~~
    # yum install qemu-kvm qemu-img virt-manager libvirt libvirt-python python-virtinst libvirt-client
    ~~~

    3. 检查BIOS是否禁用了虚拟化支持,如果是,修改BIOS设置。
    ~~~
    [root@dhcp-192-114 ~]# dmesg | grep kvm
    [ 10.737953] kvm: disabled by bios
    [ 10.756640] kvm: disabled by bios
    [ 1078.359177] kvm: disabled by bios
    [ 1081.517789] kvm: disabled by bios
    ~~~

    4. 检查内核模块
    ~~~
    [root@dhcp-192-114 ~]# lsmod | grep kvm
    kvm_intel 138567 3
    kvm 441119 1 kvm_intel
    ~~~

  • debian vim 中文/日文乱码的解决方法

    1. 尝试在vim中输入命令
    ~~~
    :set encoding=utf-8
    set fileencoding=utf-8
    ~~~
    如果之后能正常显示中文/日文,说明是编码的问题。

    2. 编辑~/.vimrc文件,加上如下几行:
    ~~~
    set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
    set termencoding=utf-8
    set encoding=utf-8
    ~~~
    问题即可修复。

  • Run multiple background task using only one line of command

    Issue:
    [root@host1 Code-Intro]# ./cpu A & ; ./cpu B & ; ./cpu C & ; ./cpu D &
    -bash: syntax error near unexpected token `;’

    Resolution:
    You don’t need to add “;” between background tasks, just enter the command as follow:
    [root@host1 Code-Intro]# ./cpu A & ./cpu B & ./cpu C & ./cpu D &
    [1] 2284
    [2] 2285
    [3] 2286
    [4] 2287

  • RHEL7: Samba文件共享

    Samba – Server 配置

    1. 安装所需软件

    [root@s1 ~]# yum install samba -y
    [root@s1 ~]# yum install samba-client -y
    [root@s1 ~]# yum install policycoreutils-python
    

    2. 创建共享目录

    [root@s1 ~]# mkdir /sharedpath
    [root@s1 ~]# semanage fcontext -a -t samba_share_t '/sharedpath(/.*)?'
    [root@s1 ~]# restorecon -vvFR /sharedpath/
    restorecon reset /sharedpath context unconfined_u:object_r:default_t:s0->system_u:object_r:samba_share_t:s0
    

    (更多…)

  • How to force firefox accessing Facebook/Twitter via IPv4

    [Issue]

    1. Facebook and Twitter are special treated in China.
    2. I use IPv4/IPv6 tunnel to access Internet, so disabling IPv6 globally is not desirable.
    3. I need to use school’s DNS server, but that DNS return wrong answer of facebook/twitter.
    (更多…)

  • OSTEP GCC 编译报错 undefined reference to `pthread_create’

    Issue

    [root@host1 Code-Intro]# gcc -o cpu cpu.c -Wall
    /tmp/ccG1P1Rf.o: In function `Pthread_create’:
    cpu.c:(.text+0xce): undefined reference to `pthread_create’
    /tmp/ccG1P1Rf.o: In function `Pthread_join’:
    cpu.c:(.text+0x11a): undefined reference to `pthread_join’
    collect2: ld returned 1 exit status

    Resolution

    [root@host1 Code-Intro]# gcc -o cpu cpu.c -Wall -lpthread
    (add “-lpthread” option.)