Category: Linux

  • nginx代理websocket

    map $http_upgrade $connection_upgrade {
     default upgrade;
     '' close;
    }
    
    upstream proxy_stomp {
     server 192.168.1.1:3000;
    }
    
    server {
     listen 3001;
     server_name proxy.abc.com;
     location / {
     proxy_pass http://proxy_stomp;
     proxy_http_version 1.1;
     proxy_set_header Upgrade $http_upgrade;
     proxy_set_header Connection "upgrade";
     }
    }

    upgrade 意思为升级为其他协议

    http://nginx.org/en/docs/http/websocket.html

  • rabbitmq3.3.1允许guest远程访问

    rabbitmq 默认允许 guest 本地访问
    为了方便需要允许远程访问

    把 /usr/share/doc/rabbitmq-server-3.3.1/rabbitmq.config.example 复制一份到 /etc/rabbitmq/rabbitmq.config,在 rabbit 段中,按如下格式

    [{rabbit, [{loopback_users, []}]}]

    参考:

    https://www.rabbitmq.com/access-control.html

  • 配置rsync服务

    要求:配置针对单一ip的免认证 rsync 服务,环境为 centos 6.5,需要关闭 SELINUX

    安装

    yum install -y xinetd rsync

    检查 iptables 需要使 873 端口通行

    配置 xinetd

    vim /etc/xinetd.d/rsync
    # default: off
    # description: The rsync server is a good addition to an ftp server, as it \
    #	allows crc checksumming etc.
    service rsync
    {
    	disable	= no
    	flags		= IPv4
    	socket_type     = stream
    	wait            = no
    	user            = root
    	server          = /usr/bin/rsync
    	server_args     = --daemon
    	log_on_failure  += USERID
    }
    

    配置 rsync 配置文件

    vim /etc/rsyncd.conf
    max connections = 5
    log file = /var/log/rsync.log
    uid = nobody
    gid = nobody
    [web]
    path = /home/ftpuser1
    read only = false
    hosts allow = 192.168.1.1
    

    重启 xinetd

    上面访问的路径就为 rsync -av 192.168.x.x::web .

    参考:

    Setup Rsync in 5 Minutes – Centos 6

    如果不使用 xinetd 来做守护。创建如下目录和文件

    /etc/rsyncd

    ├── rsyncd.conf

    └── rsyncd.secrets

    查看 rsyncd.conf

    pid file = /var/run/rsyncd.pid
    port = 873
    address = 192.168.1.123
    uid = root
    gid = root
    use chroot = yes
    read only = no
    hosts allow=192.168.1.0/255.255.255.0
    hosts deny=*
    max connections = 10
    motd file = /etc/rsyncd/rsyncd.motd
    log format = %t %a %m %f %b
    syslog facility = local3
    timeout = 300
    [bbs]
    path = /data/www/bbs
    list=yes
    ignore errors
    auth users = my_name
    secrets file = /etc/rsyncd/rsyncd.secrets
    comment = blog
    

    查看 rsyncd.secrets

    my_name:mypass

    之后要想传文件到 192.168.1.123 的 /data/www/bbs 下

    客户端创建文件 /etc/sersync/rsync_password
    写入
    mypass
    权限为 0400

    执行

    rsync -a -R --delete ./ --include=bbbb --exclude=* [email protected]::bbs --password-file=/etc/sersync/rsync_password

    关于权限问题而不成功参考:
    http://superuser.com/questions/243656/how-to-configure-and-use-rsyncd

    rsyncd 的 init 文件

    #! /bin/bash
    #
    # chkconfig:   2345 50 50
    # description: The rsync daemon
    #pidfile: /var/run/rsyncd.pid
    
    # source function library
     . /etc/rc.d/init.d/functions
    
    PROG='/usr/bin/rsync'
    BASE=${0##*/}
    
    # The config file must contain following line:
    #  pid file = /var/run/rsync.pid
    OPTIONS="--daemon --config=/etc/rsyncd/rsyncd.conf"
    
    case "$1" in
      start)
        echo -n $"Starting $BASE: "
        daemon $PROG $OPTIONS
        RETVAL=$?
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$BASE
        echo
        ;;
      stop)
        echo -n $"Shutting down $BASE: "
        killproc $PROG
        RETVAL=$?
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$BASE
        echo
        ;;
      restart|force-reload)
        $0 stop
        sleep 1
        $0 start
        ;;
      status)
        status $PROG
        ;;
      *)
        echo "Usage: $0 {start|stop|restart|status|force-reload}" >&2
        exit 1
        ;;
    esac
    

     

  • debian忘记密码

    下面介绍一个在所有版本linux的grub上均可以使用的方法:
    1、在Grub的引导装载程序菜单上,选择你要进入的条目,键入 “e” 来进入编辑模式。
    2、在第二行(类似于kernel /vmlinuz-2.6.15 ro root=/dev/hda2 ),键入”e”进入编辑模式;
    3、在句末加上”init=/bin/bash”,回车;
    4、按“b”启动系统。
    这样我们即可获得一个bash的shell。
    进入shell后,根分区的挂载模式默认是只读,我们要将其改为可写,否则不能更改root密码:

    mount -no remount,rw /
    passwd root
    sync
    mount -no remount,ro /
    reboot
  • Error: rpmdb open failed

    解决办法

    Error: rpmdb open failed

    rm -rf /var/lib/rpm/__db*

    rpm –rebuilddb

  • linux使用inode笔记

    今天使用ansible生成文件时,提示目标文件有 hard 硬链接,执行失败。

    想要查到到底有哪些硬链,那么可以找到这些文件

    find . -type f -links +1

    要找到文件的inode, 使用 ls -li, 显示如下,第一列为inode number

    6160399 -rw-r--r--. 3 root root 72 5月 6 2014 ifcfg-eth0

    再找到都有哪些文件硬链到这个文件,使用find命令

    find / -follow -inum 6160399

    另一个例子,有时候shell下会生成一些乱码或touch ‘~’,这样删除挺麻烦的,即然是文件就有inode number,结合上面的命令,先找到inode number

    rm `find . -follow -inum 1192387`