Blog

  • systemd使用笔记

    由 chkconfig 转变到 systemd,有点不习惯,查看所有服务

    systemd 是 Linux 内核发起的第一个程序

    systemctl list-unit-files --type=service

    查看具体一个服务信息

    systemctl status keepalived.service

    查看所有服务

    systemctl status

    具体服务的配置文件在

    /usr/lib/systemd/system/mariadb.service

    参考:
    https://linux.cn/article-6888-1.html?utm_source=weibo&utm_medium=weibo

  • vagrant使用笔记

    安装 vagrant

    https://www.vagrantup.com/downloads.html
    

    如果网络不好首先下载 box ,比如 centos6.box centos7.box

    注册一个 box,经常用的可以添加为 base,做为 default box

    vagrant box add base ~/osx-dmg/centos7.box
    vagrant box add centos6 ~/osx-dmg/centos6.box
    vagrant box add centos7 ~/osx-dmg/centos7.box
    

    查看已经导入的 box

    vagrant box list
    #或者
    ls -l ~/.vagrant.d/boxes
    

    如果网络条件好,添加官方的 centos/7 (注意写法)

    $ vagrant box add centos/7
    ==> box: Loading metadata for box 'centos/7'
        box: URL: https://vagrantcloud.com/centos/7
    This box can work with multiple providers! The providers that it
    can work with are listed below. Please review the list and choose
    the provider you will be working with.
    
    1) hyperv
    2) libvirt
    3) virtualbox
    4) vmware_desktop
    
    Enter your choice: 2
    

    工作目录为 ~/test,进入目录,创建一台 centos7 的机器,--minimal 生成的文件没有注释

    vagrant init centos/7 --minimal
    

    启动

    vagrant up

    连接 vagrant

    vagrant ssh
    

    执行 id 命令

    vagrant ssh -c 'id'

    查看当前 vagrant 管理的机器,最前面为机器 id

                                                                                    
    vagrant global-status
    

    修剪 vagrant 已经坏掉的机器

                                                       
    vagrant global-status --prune
    

    如果有不需要的 box

                                                                    
    vagrant destroy id
    

    准备多台虚拟机环境

      config.vm.define "web" do |web|                                               
        web.vm.box = "centos6"                                                      
      end                                                                           
                                                                                    
      config.vm.define "db" do |db|                                                 
        db.vm.box = "centos6"                                                       
      end
    

    查看机器的状态

    vagrant status

    查看 ssh 信息

    vagrant ssh-config

    关闭 vm

    vagrant halt

    不需要的 box 删除

    vagrant box remove centos/7

    vagrant 官方 centos7 box:

    https://vagrantcloud.com/centos/7/

    centos 提供的 box:

    http://cloud.centos.org/centos/7/vagrant/x86_64/images/

    windows 10 将 virtualbox 换为 hyperv
    上面获取 box 步骤时选 hyperv, 将原来 virtualbox 的相关 box 删除

    vagrant.exe box  remove centos/7 --provider virtualbox --all

    切到目录下,删除相关的 vm
    vagrant.exe destroy
    启动

    vagrant up --provider hyperv
  • 2016年5月面试经历

    车享网 国企
    陆金所
    http://www.chinadep.com/

    杨洋,达达运维岗位,面试时间26号周二上午10:00。面试地址:上海市浦东南路1036号隆宇大厦6楼

    wiwidi

    面试职位:OPS运维工程师

    面试时间:2016年4月26日(周二)上午14:00

    面试地址:上海市徐汇区漕东支路81号漕河泾实业大厦9楼(地铁1号线漕宝路站下,3号口出)

    联系电话:021-6283 8830、14782288717(蔡丽莹)

    地 图:

    ele.me

    [email protected]

    iqiyi

  • ssh config 针对某些机器密码登陆

    一些机器不要公钥登陆,在每次连的时候提示密码

    Host kong
    Hostname 192.168.1.200
    User jpuyy                                                              
    Port 22                                                                         
    PreferredAuthentications password
    

    服务端,例如 sftp 可以允许密码登录的话

    Match user jpuyy address 192.168.1.0/24
        PasswordAuthentication yes
        # also since we want only sftp
        ForceCommand internal-sftp
    
    
  • nginx upgrade 失败

    CentOS 下使用 yum 安装。为了平滑升级

    yum update nginx

    安装完成之后

    /etc/init.d/nginx upgrade

    提示失败,nginx_error.log 中出现

    [alert] 10690#0: execve() failed while executing new binary process "nginx" (2: No such file or directory)

    原因是之前启动没有使用 /usr/sbin/nginx -c /etc/nginx/nginx.conf 启动,而是通过环境变量里的 nginx 启动的。这样的话只能想办法把这台踢出集群,然后

    /etc/init.d/nginx restart

    参考:https://groups.google.com/forum/#!topic/openresty/HiV3c-JwTZ4

  • rediscluster缩容和扩容

    rediscluster 配置的过量,浪费了资源。不够时又加加资源

    查看当前 rediscluster 的主从关系,并记下来 hash 值。

    redis-cli -c cluster nodes

    现在先进行扩容,192.168.11.3:6379 是当前 cluster 的一个 master 节点。

    添加 192.168.22.3:6379,从节点 192.168.22.4:6379

    查看 cluster 状态

    redis-trib.rb info 192.168.11.3:6379

    添加,默认为 master

    redis-trib.rb add-node 192.168.22.3:6379 192.168.11.3:6379

    添加 –slave, 主动找没有 slave 的 master 节点

    redis-trib.rb add-node --slave 192.168.22.4:6379 192.168.11.3:6379

    查看 cluster nodes

    redis-cli -c cluster nodes

    接下来确定哪些 master 的 slots 迁到新加的实例,找到新加的 master hash 值为 e0d88661607192a4ffac1b74412c6cd6d0932067

    从已有 slot 里分配 100 个 slots 到 e0d88661607192a4ffac1b74412c6cd6d0932067

    redis-trib.rb reshard --from 32f38c9e5e42f6a66e67abdd540cce72e4bf399c --to e0d88661607192a4ffac1b74412c6cd6d0932067 --slots 100 --yes 192.168.11.3:6379

    如果遇到失败,进行 fix

    redis-trib.rb fix 192.168.11.3:6379

    反复几次,并查看可以达到迁移目的。

    总是 fix 特别烦,写个有限循环搞定。

    for i in $(seq 20); do redis-trib.rb reshard --from 32f38c9e5e42f6a66e67abdd540cce72e4bf399c --to e0d88661607192a4ffac1b74412c6cd6d0932067 --slots 100 --yes 192.168.11.3:6379 || redis-trib.rb fix 192.168.11.3:6379; done
    

    缩容即是把里面的 slots 移到其他实例里,然后删除 node 对应的 hash

    redis-trib.rb del-node 192.168.11.3:6379 e0d88661607192a4ffac1b74412c6cd6d0932067

    查看当前实例是否还在提供服务

    redis-cli monitor

    当缩容或扩容完之后,如果 slots 的数量差的多的话, 可以对整个集群 rebalance

    redis-trib.rb rebalance 192.168.11.3:6379

    同样的如果中间中断,就 fix

    redis-trib.rb fix 192.168.11.3:6379

    到最后会提示

    *** No rebalancing needed! All nodes are within the 2.0% threshold.

    查看整个集群的情况

    #redis-cli -c cluster info
    
    cluster_state:ok
    cluster_slots_assigned:16384
    cluster_slots_ok:16384
    cluster_slots_pfail:0
    cluster_slots_fail:0
    cluster_known_nodes:12
    cluster_size:6
    cluster_current_epoch:46
    cluster_my_epoch:40
    cluster_stats_messages_sent:912305
    cluster_stats_messages_received:912227
    
    

    ok,到这里结束。