Category: Life

  • 制作MariaDB5.5.31的rpm包

    制作MariaDB的rpm包使用CMake CPack Package Generators,这种制作出来的包叫做CPackRPM包。

    首先安装好环境(必须全部检查):

    bzr > 2.0
    gunzip
    GNU tar
    gcc 2.95.2 or later
    g++
    GNU make 3.75 or later
    libtool 1.5.24 or later
    bison (2.0 for MariaDB 5.5)
    libncurses (在centos下名为ncurses-devel)
    zlib-dev
    GNU automake
    GNU autoconf
    cmake >= 2.8.7 (在centos下名为cmake28)

    使用非root用户,将下载好的mariadb-5.5.31.tar.gz解压,这里是 /home/jpuyy/mariadb-5.5.31。

    将要编译的参数写到cmake后面,这里是最关键的是制作rpm包的参数-DRPM=centos6,语句的最后要有一个点号,表示在当前目录生成。

    cmake28 -DRPM=centos6 \
    -DCMAKE_INSTALL_PREFIX=/usr/local/DBServer/MariaDB5.5.31 \
    -DWITH_INNOBASE_STORAGE_ENGINE=1 \
    -DWITH_PARTITION_STORAGE_ENGINE=1 \
    -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
    -DWITH_MYISAM_STORAGE_ENGINE=1 \
    -DENABLED_LOCAL_INFILE=1 \
    -DDEFAULT_CHARSET=utf8 \
    -DDEFAULT_COLLATION=utf8_general_ci \
    -DWITH_EXTRA_CHARSETS=complex .

    当最后几行是如下信息时,表示检查编译通过

    -- Configuring done
    -- Generating done
    -- Build files have been written to: /home/jpuyy/mariadb-5.5.31

    打包

    make package

    连spec文件都不用写,cmake会自动生成制作rpm的环境,位置在/home/jpuyy/mariadb-5.5.31/_CPack_Packages/Linux/RPM

    最后生成的rpm包如下

    MariaDB-5.5.31-centos6-x86_64-client.rpm
    MariaDB-5.5.31-centos6-x86_64-common.rpm
    MariaDB-5.5.31-centos6-x86_64-devel.rpm
    MariaDB-5.5.31-centos6-x86_64-server.rpm
    MariaDB-5.5.31-centos6-x86_64-shared.rpm
    MariaDB-5.5.31-centos6-x86_64-test.rpm

    这些包的作用

    https://kb.askmonty.org/en/about-the-mariadb-rpm-files/

    安装方法:

    需要解决冲突和依赖

    冲突:查找已经安装的mysql包,rpm -qa ‘mysql*’,移除查找到的mysql包

    rpm -e mysql-libs-5.1.66-2.el6_3.x86_64 --nodeps
    rpm -e `rpm -qa mysql-libs*` --nodeps
    

    依赖:在执行rpm -ivh MariaDB-5.5.31-centos6-x86_64*时,如果出现依赖,如

    error: Failed dependencies:
    perl(DBI) is needed by MariaDB-server-5.5.31-1.x86_64
    perl(Time::HiRes) is needed by MariaDB-test-5.5.31-1.x86_64

    可以yum安装perl-DBI,perl-Time-HiRes。也可以使用

    rpm -ivh MariaDB-5.5.31-centos6-x86_64-* --nodeps

    不去检测依赖。PS:有些依赖确实无用可不用安装。

    参考:

    https://kb.askmonty.org/en/source-building-mariadb-on-centos/

    https://kb.askmonty.org/en/installing-mariadb-with-the-rpm-tool/

  • dd创建大文件制作iso启动盘

    生成一个2GB的文件
    dd if=/dev/zero of=test bs=1024k count=2048
    生成一个10GB的文件
    dd if=/dev/zero of=test bs=1024k count=10240

    dd if=/dev/zero of=test bs=8M count=128

    mac下用dd制作启动u盘

    确定盘符

    ➜  quick diskutil list

    /dev/disk0

    #:                       TYPE NAME                    SIZE       IDENTIFIER

    0:      GUID_partition_scheme                        *121.3 GB   disk0

    1:                        EFI EFI                     209.7 MB   disk0s1

    2:                  Apple_HFS mac                     120.5 GB   disk0s2

    3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3

    /dev/disk1

    #:                       TYPE NAME                    SIZE       IDENTIFIER

    0:      GUID_partition_scheme                        *500.1 GB   disk1

    1:                        EFI EFI                     209.7 MB   disk1s1

    2:                  Apple_HFS 500G                    499.8 GB   disk1s2

    /dev/disk2

    #:                       TYPE NAME                    SIZE       IDENTIFIER

    0:     FDisk_partition_scheme                        *7.7 GB     disk2

    1:               Windows_NTFS 21                      7.7 GB     disk2s1

    去掉挂载

    ➜  quick diskutil umountDisk /dev/disk2

    Unmount of all volumes on disk2 was successful

    用dd写入光盘镜像

    ➜  quick sudo dd if=/Users/jpuyy/Downloads/CentOS-7.0-1406-x86_64-GnomeLive.iso of=/dev/disk2 bs=1m

  • C2960S交换机汇聚

    这里的汇聚要达到的目的:交换机之间可以扩展带宽,同时增强可用性。C2960S是二层交换机。实现汇聚的两个协议

    Link Aggregation Control Protocol (LACP) 和 Port Aggregation Protocol (PAgP)

    LACP是IEEE 802.3ad中规定的协议,所以具有通用性,所以linux又网卡绑定时,需要选择Mode 4 (802.3ad),这样交换机与服务器之间就能增加带宽。

    而PAgP是思科自己的汇聚协议,它适用于思科产品之间的连接。

    一句话,服务器与交换机,只能用LACP才有汇聚效果,而交换机与交换机既可以是LACP,也可以是PAgP,同时要注意,互相连接的端口之间协议要统一。不管是LACP还是PAgP,组成的新的虚拟通道在思科里叫做etherchannel。

    下面是将1/0/1与1/0/2汇聚,前提进入enable模式,

    配置LACP

    Switch#configure terminal
    Switch(config)#interface range gigabitEthernet 1/0/1 - 2
    Switch(config-if-range)#switchport mode trunk
    Switch(config-if-range)#channel-group 1 mode active
    Switch(config-if-range)#end

    配置PAgP

    Switch#configure terminal
    Switch(config)#interface range gigabitEthernet 1/0/1 - 2
    Switch(config-if-range)#switchport mode trunk
    Switch(config-if-range)#channel-group 1 mode desirable
    Switch(config-if-range)#end

    几个有用的查看命令

    show running-config查看当前配置信息

    interface GigabitEthernet1/0/1
     switchport mode trunk
     spanning-tree portfast
     channel-group 1 mode active
     !
     interface GigabitEthernet1/0/2
     switchport mode trunk
     spanning-tree portfast
     channel-group 1 mode active

    show ip interfaces brief 显示interfaces的状态

    Port-channel1          unassigned      YES unset  up               up

    show spanning-tree 查看生成树,如果汇聚成功会只显示

    Po1                 Desg FWD 3         128.224  P2p

    更改port-channel的负载均衡的方式为src-mac

    Switch#configure terminal
    Switch(config)#port-channel load-balance src-mac

    可选的方式有:

    dst-ip Dst IP Addr
    dst-mac Dst Mac Addr
    src-dst-ip Src XOR Dst IP Addr
    src-dst-mac Src XOR Dst Mac Addr
    src-ip Src IP Addr
    src-mac Src Mac Addr

    查看etherchannel负载均衡的方式:

    Switch#show etherchannel load-balance
    EtherChannel Load-Balancing Configuration:
    src-mac

    查看interfaces的trunk状态

    Switch#show interfaces trunk

    Port Mode Encapsulation Status Native vlan
     Po1 on 802.1q trunking 1
     Po3 on 802.1q trunking 1
     Po4 on 802.1q trunking 1
    Port Vlans allowed on trunk
     Po1 1-4094
     Po3 1-4094
     Po4 1-4094
    Port Vlans allowed and active in management domain
     Po1 1
     Po3 1
     Po4 1
    Port Vlans in spanning tree forwarding state and not pruned
     Po1 1
     Po3 1
     Po4 1

    查看ether channel状态

    Switch#show etherchannel summary
    
    Flags: D - down P - bundled in port-channel
    I - stand-alone s - suspended
    H - Hot-standby (LACP only)
    R - Layer3 S - Layer2
    U - in use f - failed to allocate aggregator
    
    M - not in use, minimum links not met
    u - unsuitable for bundling
    w - waiting to be aggregated
    d - default port
    Number of channel-groups in use: 4
    Number of aggregators: 4
    
    Group Port-channel Protocol Ports
    ------+-------------+-----------+--------------------------------------------
    1 Po1(SU) PAgP Gi1/0/1(P) Gi1/0/2(P)
    2 Po2(SD) LACP Gi1/0/3(D) Gi1/0/4(D)
    3 Po3(SU) LACP Gi1/0/5(P) Gi1/0/6(P)
    4 Po4(SD) LACP Gi1/0/7(D) Gi1/0/8(D)

    可以看到正在运行的是第一个PAgP,第3LACP

    参考:

    http://www.cisco.com/en/US/docs/switches/lan/catalyst2960/software/release/12.2_55_se/configuration/guide/swethchl.html#wpxref12539

    服务器 bond0  mode0 交换机做 etherchannel 使交换机 show logging 没有 flapping.

    在 configure terminal 下,做好 port-channel

    switch(config)#interface port-channel 2
    switch(config-if)#switchport mode access
    switch(config-if)#switchport access vlan 6

    将 gi 口加入到 port-channel,这里用的 mode 是 on

    switch(config-if)#int range gi 1/0/10 - 13
    switch(config-if-range)#channel-group 2 mode on

    默认是 no shutdown ,这样以后会有几十秒的中断,然后查看 etherchannel

    2 Po2(SU) - Gi1/0/10(P) Gi1/0/11(P) Gi1/0/12(P)
     Gi1/0/13(P)
  • rsync使用方法

    服务器1:192.168.1.1
    服务器2:192.168.1.2
    要求:
    将192.168.1.1的abc目录同步到192.168.1.2上的/tmp/temp下
    rsync -a [email protected]:/home/bak/abc /tmp/temp/

    如果端口为非22,则加上 -e 'ssh -p 537', –progress显示进度

    rsync -a --progress -e 'ssh -p 537' [email protected]:/data/jpuyy.com /home/bak/

    rsync增量备份

    增量硬链备份,对比bk1,如果有增量则备份到bk2中

    rsync -au myadmin bk1
    rsync -au --link-dest=/root/bk1 myadmin bk2

    实际增量备份脚本

    #!/bin/bash
    
    cur_date=`date +%F`
    rsync="/usr/bin/rsync"
    args="-au --bwlimit=30000 --copy-links"
    user='root'
    local_dir='/data/all_web_backup/abc.com/'
    
    IFS=' '
    while read project ip path
    do
    # rsync loop , project one by one
    mkdir -p $local_dir/$project
    last_rsync=`ls $local_dir/$project | grep -P "\d{4}-\d{2}-\d{2}" | sort | tail -1`
    if [ -d "$local_dir/$project/$last_rsync" ]; then
    $rsync $args -e 'ssh -p 22' --link-dest=$local_dir/$project/$last_rsync $user@$ip:$path $local_dir/$project/$cur_date
    else
    $rsync $args -e 'ssh -p 22' $user@$ip:$path $local_dir/$project/$cur_date
    fi
    done < backup_list
    

    backup_list的内容需要如下格式

     bbs 192.168.1.5 /home/www/abc/bbs

    rsync的时候同步到远端并exclude .git目录

    rsync -r --exclude=.git . /var/www/html/jpuyy.com

    控制传输带宽

    rsync --bwlimit=kb/second source dest
  • sublime的使用

    ubuntu下的安装方法:

    add-apt-repository ppa:webupd8team/sublime-text-2
    apt-get update
    apt-get install sublime-text

    ctrl+tab可以快速切换标签

    ctrl+w关闭当前的标签

    ctrl+r快速跳转到文档中相关函数

    ctrl+p加#可以在当前文件中进行搜索

    ctrl+g加上数字跳到对应的行

    ctrl+`调出console

    使用vim模式:
    按下 Shift + Command + P 调出命令面板,输入 settings user 调出 Preferences:Settings – User,这时添加:

    {
     "ignored_packages": []
    }
  • linux双网卡绑定

    以下操作均在CentOS下,网卡绑定有多种模式,这里是为了增加带宽

    安装需要的组件

    yum install ethtool -y

    添加一个ifcfg-bond0的配置文件,做为master,需要绑定的物理网卡(ifcfg-eth0, ifcfg-eth1)做为slave

    vim /etc/sysconfig/network-scripts/ifcfg-bond0

    添加

    DEVICE=bond0
    ONBOOT=yes
    IPADDR=192.168.1.12
    NETMASK=255.255.255.0
    NETWORK=192.168.1.0
    USERCTL=no
    BOOTPROTO=none

    vim /etc/sysconfig/network-scripts/ifcfg-eth0

    添加

    DEVICE=eth0
    ONBOOT=yes
    USERCTL=no
    MASTER=bond0
    SLAVE=yes
    BOOTPROTO=none

    vim /etc/sysconfig/network-scripts/ifcfg-eth1

    添加

    DEVICE=eth1
    ONBOOT=yes
    USERCTL=no
    MASTER=bond0
    SLAVE=yes
    BOOTPROTO=none

    USERCTL=yes/no 是否允许非root用户控制该设备

    BOOTPROTO=none/static/dhcp 指定启动协议,这里不指定

    如果还有更多网卡,照上面写即可

    接下来需要在CentOS中注册一下bonding模块

    vim /etc/modprobe.d/bonding.conf

    添加

    alias bond0 bonding
    options bond0 mode=4 miimon=100

    mode参数见:

    http://unixfoo.blogspot.com/2008/02/network-bonding-part-ii-modes-of.html

    • Mode 0 (balance-rr)
      This mode transmits packets in a sequential order from the first available slave through the last. If two real interfaces are slaves in the bond and two packets arrive destined out of the bonded interface the first will be transmitted on the first slave and the second frame will be transmitted on the second slave. The third packet will be sent on the first and so on. This provides load balancing and fault tolerance.
    • Mode 1 (active-backup)
      This mode places one of the interfaces into a backup state and will only make it active if the link is lost by the active interface. Only one slave in the bond is active at an instance of time. A different slave becomes active only when the active slave fails. This mode provides fault tolerance.
    • Mode 2 (balance-xor)
      Transmits based on XOR formula. (Source MAC address is XOR’d with destination MAC address) modula slave count. This selects the same slave for each destination MAC address and provides load balancing and fault tolerance.
    • Mode 3 (broadcast)
      This mode transmits everything on all slave interfaces. This mode is least used (only for specific purpose) and provides only fault tolerance.
    • Mode 4 (802.3ad)
      This mode is known as Dynamic Link Aggregation mode. It creates aggregation groups that share the same speed and duplex settings. This mode requires a switch that supports IEEE 802.3ad Dynamic link.
    • Mode 5 (balance-tlb)
      This is called as Adaptive transmit load balancing. The outgoing traffic is distributed according to the current load and queue on each slave interface. Incoming traffic is received by the current slave.
    • Mode 6 (balance-alb)
      This is Adaptive load balancing mode. This includes balance-tlb + receive load balancing (rlb) for IPV4 traffic. The receive load balancing is achieved by ARP negotiation. The bonding driver intercepts the ARP Replies sent by the server on their way out and overwrites the src hw address with the unique hw address of one of the slaves in the bond such that different clients use different hw addresses for the server.

    mode的值表示工作模式,共有7种模式,常用的为0,1,4三种。

    mode=0表示load balancing (round-robin)为负载均衡方式,两块网卡都工作。
    mode=1表示fault-tolerance (active-backup)提供冗余功能,工作方式是主备的工作方式,也就是说默认情况下只有一块网卡工作,另一块做备份
    mode=4是通用的802.3ad协议,类似于第一种,接思科交换机时需要选LACP模式。

    miimon是用来进行链路监测的。比如:miimon=100,那么系统每100ms监测一次链路连接状态,如果有一条线路不通就转入另一条线路;

    重启网络服务

    service network restart

    使用watch -n 1可以每秒更新bond0的状态

    watch -n 1 'cat /proc/net/bonding/bond0'

    参考:http://www.cyberciti.biz/howto/question/static/linux-ethernet-bonding-driver-howto.php