Rootop 服务器运维与web架构

2015-01-12
发表者 Venus
在 ESXi“192.168.0.150”上调用对象 “storageSystem”的“HostStorageSystem.ComputeDiskPartitionInfo” 失败。已关闭评论

在 ESXi“192.168.0.150”上调用对象 “storageSystem”的“HostStorageSystem.ComputeDiskPartitionInfo” 失败。

在esxi5.5上添加ip-san,提示错误:

在 ESXi“192.168.0.150”上调用对象 “storageSystem”的“HostStorageSystem.ComputeDiskPartitionInfo” 失败。

后来查到是因为已经有了分区(之前挂载到windows下),后来找了台windows重新挂载上去,删掉分区。重新在esxi中添加。
或者是登陆到esxi主机执行命令删掉分区。
先在vsphere client中开启esxi的ssh。

#列出连接的iscsi设备

~ # esxcfg-scsidevs -l

#获取设备磁盘信息

~ # partedUtil get /dev/disks/t10.FreeBSD_iSCSI_Disk______005056bf230c000_______
13054 255 63 209715200
1 2048 209713151 0 0 #分区1

#删除分区

~ # partedUtil delete /dev/disks/t10.FreeBSD_iSCSI_Disk______005056bf230c000_________________ 1
~ # partedUtil #几个参数
Not enough arguments

Usage:
 Get Partitions : get <diskName>
 Set Partitions : set <diskName> ["partNum startSector endSector type attr"]*
 Delete Partition : delete <diskName> <partNum>
 Resize Partition : resize <diskName> <partNum> <start> <end>

解决

2014-12-31
发表者 Venus
haproxy安装配置及测试已关闭评论

haproxy安装配置及测试

系统版本:centos6.5_x64
软件版本:haproxy-1.5.9.tar.gz
后端服务器IP:10.10.10.5、10.10.10.6

这里提供haproxy的本站下载地址:wget -c https://www.rootop.org/rs/haproxy-1.5.9.tar.gz

安装:

[root@rootop-haproxy haproxy-1.5.9]# make TARGET=linux26 PREFIX=/usr/local/haproxy install

这里为什么是linux26,可以去看下README文档。

创建配置文件:
[root@rootop-haproxy ~]# mkdir /usr/local/haproxy/conf
[root@rootop-haproxy ~]# vi /usr/local/haproxy/conf/haproxy.cfg

global
    log 127.0.0.1 local0 info
    maxconn 1000
    chroot /usr/local/haproxy
    uid nobody
    gid nobody
    daemon
    nbproc 1
    pidfile /tmp/haproxy.pid

defaults
    log global
    mode http
    option httplog
    retries 3
    option httpclose
    option dontlognull
    option forwardfor
    option redispatch
    log 127.0.0.1 local3
    balance roundrobin
    maxconn 20480
    timeout connect 5000
    timeout client 50000
    timeout server 50000
    timeout check 2000

    stats enable
    stats refresh 30s
    stats uri /ha_check
    stats hide-version
    stats auth admin:admin

frontend http-in
    bind *:80
    mode http
    option httplog
    log global
    default_backend http_pool

backend http_pool
    balance roundrobin
    option httpchk HEAD /index.html HTTP/1.0
    cookie SERVERID insert indirect
    server WEBSRV1 10.10.10.5:80 maxconn 1500 cookie SRV1 check inter 2000 rise 2 fall 3 weight 1
    server WEBSRV2 10.10.10.6:80 maxconn 1500 cookie SRV2 check inter 2000 rise 2 fall 3 weight 1

启动服务:
[root@rootop-haproxy ~]# /usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/conf/haproxy.cfg

stats uri /status #监控页面
stats auth admin:admin #监控页身份认证

提供一个管理脚本:

#!/bin/bash
PROXY_CONF=/usr/local/haproxy/conf/haproxy.cfg
PROXY_BIN=/usr/local/haproxy/sbin/haproxy
CHECK_PROXY=$(ps aux | grep "haproxy -f" | grep -v grep | wc -l)

case $1 in

        start)
        if [ $CHECK_PROXY -ge 1 ]; then
                echo "already running , exit"
                exit
        else
        $PROXY_BIN -f $PROXY_CONF
                if [ $? == 0 ]; then
                        echo "start ok"
                else
                        echo "start failed"
                fi
        fi
        ;;

        stop)
        kill -9 $(cat /tmp/haproxy.pid)
                if [ $? == 0 ]; then
                        rm -f /tmp/haproxy.pid && echo "stop ok"
                else
                        echo "stop failed"
                fi
        ;;

        restart)
        kill -9 $(cat /tmp/haproxy.pid)
                if [ $? == 0 ]; then
                        rm -f /tmp/haproxy.pid && echo "stop ok"
                else
                        echo "stop failed"
                fi

        $PROXY_BIN -f $PROXY_CONF
                if [ $? == 0 ]; then
                        echo "start ok"
                else
                        echo "start failed"
                fi
        ;;

        *)
        echo "only start/stop/restart"
esac

exit

然后通过多个客户端访问haproxy的ip地址可以看到后端不同服务器提供的内容。

cookie SERVERID insert indirect  其中这句设置了会话保持,通过插入cookie方式,测试效果。

访问到服务器1:

访问到服务器2:

浏览器关闭后,会话断开。

2014-12-18
发表者 Venus
试用Microsoft Azure 微软云计算平台已关闭评论

试用Microsoft Azure 微软云计算平台

Microsoft Azure 是一个开放且灵活的云平台,通过该平台,您可以在 Microsoft 管理的数据中心的全球网络中快速构建、部署和管理应用程序。

官方网站:http://www.windowsazure.cn/  说由世纪互联公司运营,最近提供免费试用,申请了个账户,试用30天。

在里面创建了两个虚拟机,一个server 2012 一个openlogic。 可以看到后面有一个DNS名称,这个就是用来访问的地址,通过这个域名解析出来的ip就是虚拟机的ip。

远程登陆windows:

点击虚拟机,点下面的连接,会弹出来下载提示,这里下载了一个 test.rdp 文件,也就是远程桌面的配置文件,直接双击连接,输入创建虚拟机时的用户名和密码即可登陆。还有一种方法就是直接利用系统的远程桌面连接,输入 dns名称:52555 ,端口为52555,这个端口号是端点中定义的,映射为系统的3389,提高了安全性。登陆为管理员权限。在里面安装了一个iis,发布服务。这里需要在端点中放行80端口。openstack中记得叫安全访问。

下面那个勾还没搞明白,第一次勾选了最后一个复选框,结果发布的iis服务访问不到,删掉重新创建端点。负载平衡集,类似于阿里云的SLB,应该是四层或七层代理。

访问linux虚拟机openlogic (一个衍生rhel的再编译产物):

通过DNS名称解析出来的ip即为服务器ip。通过域名或者ip访问都行,输入创建虚拟机时创建的账户,我这里在创建虚拟机时没有导入密钥。直接密码登陆,修改root密码。

sudo passwd root   #修改root密码

安装nginx,启动nginx服务,关闭系统自带防火墙,在虚拟机端点中放行80端口。

[root@openlogic7 ~]# service firewalld stop
Redirecting to /bin/systemctl stop firewalld.service

还有其它功能,比如hadoop,cdn,SQL等。使用起来感觉比较繁琐。想熟悉azure平台得可以注册个账户熟悉一下。

2014-12-11
发表者 Venus
nginx负载均衡-基于客户端cookie的会话保持已关闭评论

nginx负载均衡-基于客户端cookie的会话保持

通过ip_hash做会话保持有一定的缺陷,这个是通过客户端ip来实现。同一个网络下众多客户端访问服务器会被扔到同一台机器,再或者是CDN也会导致负载不均衡。所以要实现通过客户端cookie实现,包括F5、深信服设备其中的会话保持也是通过插入cookie值来实现会话保持。下次客户端访问服务器,带上本地cookie,nginx中的sticky模块分析并扔到对应服务器中。

软件版本:
nginx-1.6.0 (后来用nginx-1.2.3)
nginx-sticky-module-1.1

安装:
[root@localhost nginx-1.6.0]# ./configure –prefix=/usr/local/nginx/ –add-module=../nginx-sticky-module-1.1
[root@localhost nginx-1.6.0]# make
make时报错:
objs/addon/nginx-sticky-module-1.1/ngx_http_sticky_misc.o] 错误 1

参考解决方法:

方法一:
http://www.blogjava.net/sliverfancy/archive/2014/03/28/411594.html
说安装openssl-devel,试过无效。

方法二(未测试):
nginx-1.5.x和nginx-sticky-module-1.1编译会有点问题,应该是nginx新版本没有相应的nginx-sticky-module,解决办法是把nginx-sticky-module-1.1/ngx_http_sticky_misc.c的281行修改为:

digest->len = ngx_sock_ntop(in,sizeof(struct sockaddr_in), digest->data, len, 1);

方法三:
降低nginx版本,我这里换为nginx-1.2.3编译通过。

sticky模块参数只用于upstream段中,并且不能和ip_hash同时存在。
支持的参数:
sticky [name=route] [domain=.foo.bar] [path=/] [expires=1h] [hash=index|md5|sha1] [no_fallback];
name: 可以为任何的string字符,默认是route
domain:哪些域名下可以使用这个cookie
path:哪些路径对启用sticky,例如path/test,那么只有test这个目录才会使用sticky做负载均衡
expires:cookie过期时间,默认浏览器关闭就过期,也就是会话方式。
no_fallbackup:如果设置了这个,cookie对应的服务器宕机了,那么将会返回502(bad gateway 或者 proxy error),建议不启用。

配置参考(反向代理部分略过):

upstream apache {
 sticky name=srv_id expires=1h domain=.test.com path=/;

 server 192.168.5.4 max_fails=3 fail_timeout=20s;
 server 192.168.5.5 max_fails=3 fail_timeout=20s;
}

参考链接:
http://nginx.org/en/docs/http/ngx_http_upstream_module.html#sticky
http://blog.csdn.net/dc_726/article/details/12348907

2014-12-04
发表者 Venus
xshell使用密钥登陆linux服务器已关闭评论

xshell使用密钥登陆linux服务器

使用用户名方式登陆linux服务器,存在暴力破解可能,如果使用证书就可以避免这种问题。当然也可以通过修改ssh端口的方式绕开非法的扫描。

通过密钥方式登陆,需要在xshell中创建私钥和公钥,私钥位于客户端,公钥位于服务器端,通过私钥去解公钥。

在xshell中制作密钥:

1、点击“工具”-“新建用户密钥生成向导”

2、密钥类型选择 rsa (默认可以),长度1024(默认)

3、

4、密钥名称,自己修改。

5、公钥格式选”ssh2-openssh”,并另存为到桌面上。

6、完成后会自动弹出 用户密钥 (私钥)   #主机密钥为公钥

xshell的密钥生成完毕。现在需要将桌面上的公钥id_rsa_1024_2014-12-03.pub上传到服务器中,路径:~/.ssh/

[root@g2 ~]# cd .ssh/
[root@g2 .ssh]# ll
总用量 4
-rw-r--r-- 1 root root 208 12月 3 14:30 id_rsa_1024_2014-12-03.pub
[root@g2 .ssh]# mv id_rsa_1024_2014-12-03.pub authorized_keys
[root@g2 .ssh]# chmod 400 authorized_keys
[root@g2 .ssh]# ll
总用量 4
-r-------- 1 root root 208 12月 3 14:30 authorized_keys

修改/etc/ssh/sshd_config下面4项:
RSAAuthentication yes #RSA加密方式认证
PubkeyAuthentication yes #公钥验证
AuthorizedKeysFile .ssh/authorized_keys #公钥文件
PasswordAuthentication no #禁止密码登陆
重启ssh服务

xshell认证方式修改为密钥验证:

方法:Public Key 用户名:root 用户密钥:生成密钥时的私钥。 密码没有设置,为空。

这样就可以密钥登陆了。

PS:

一个服务器上会有多个人员的账号,这样就需要为不同人员创建不同的密钥实现权限分离,比如说为用户A创建密钥,将公钥放到/home/A/.ssh下,给用户A私钥让其登陆,用户B也如此操作。如果用同一个私钥及公钥,那么其他用户直接可以在xshell中修改用户为root,直接跃为root权限,风险太大,所以为不同用户创建不同密钥。