win7/8 添加其他分区的系统启动菜单

归类于服务器 参与评论

win8安装在第一分区 C: ,使用Imagex_x64把win2008解压到第二分区 D:

Bcdedit /create /d "windows server 2008r2" -application osloader 

这条命令完后会返回一个GUID值 {xxxxxx} ,记下此号,这个GUID值就表示是win2008的菜单项。

Bcdedit /set {xxxxxx} osdevice partition=D:
Bcdedit /set {xxxxxx} device partition=D:
Bcdedit /set {xxxxxx} path \windows\system32\winload.exe
Bcdedit /set {xxxxxx} systemroot \windows
Bcdedit/displayorder {xxxxxx} -addlast

重启系统,win8就看到选择系统的菜单了。

查看: 29 次

使用FormsAuthenticationTicket 实现浏览器自动登录一法

归类于.NET | ASP.NET | ASP.NET MVC 参与评论

1.问题

同事用Flash做电子政务的ios客户端(暂且不讨论flash和ios的问题),服务端是在asp.net mvc网站上加几个接口,和客户端之间使用json传输,客户端直接使用asp.net forms身份认证。

问题:由于某方面原因在flash app中下载附件时调用浏览器来下载,但打开的浏览器因为没有登录凭证所有需要再次登录才能下载到附件。要解决这个问题,希望达到打开浏览器自动使用app当前用户认证然后下载附件。

2.解法

之前有个pc客户端已经实现过类似的功能,但由于那个用到自定义的会话管理组件,现在发现那个组件有比较大的问题需要大修,这次就干脆用个轻便点的方法。既然服务端是用asp.net 那最后的就是使用框架内置的东西来解决了。

1.服务端的获取令牌方法。

public ActionResult GetAuthTicket()
{
    FormsAuthenticationTicket authTicket = new
     FormsAuthenticationTicket(1, User.Identity.Name, DateTime.Now,
        DateTime.Now.AddMinutes(1), true, string.Empty);
    string encryptedTicket = FormsAuthentication.Encrypt(authTicket);

    return Json(new {Ticket= encryptedTicket });
}

在这里生成一个有效期为1分钟的认证票据对象,并使用FormsAuthentication.Encrypt方法对加密,要注意的是必须先在web.config配置文件中给网站指定固定的machineKey,并且在authentication.forms 节点设置属性protection="Encryption"  ,否则得到的是base64算法的令牌,不安全。这里还可以在票据对象的UserData属性中加上其他的数据,但不要太多了,否则生成的令牌太长。

2.服务端登录令牌自动登录

public ActionResult LoginByTicketAndRedirect(string ticket, string redirectUrl)
{
    FormsAuthenticationTicket id;
    try
    {
        id = FormsAuthentication.Decrypt(ticket);
    }
    catch (Exception)
    {
        return View("LoginByTicketAndRedirectFail",(object)"登录失败,令牌无效。");
    }
    if (id.Expired)
    {
        return View("LoginByTicketAndRedirectFail",(object) "登录失败,令牌已过期。");
    }

    FormsAuthentication.SetAuthCookie(id.Name, false);

    if (string.IsNullOrWhiteSpace(redirectUrl))
    {
        return Redirect("~/");
    }
    return Redirect(redirectUrl);
}

使用FormsAuthentication.Decrypt将令牌还原成票据对象,然后判断是否过期,验证通过则设置窗体认证登录cookie,再跳转到目标页面。

之前有客户提出附件不能用迅雷之类的工具下载,用这方法可以轻松搞定了。

查看: 73 次 ,

centos6上安装rmagick出错

归类于Linux 参与评论

安装Redmine 1.4,# bundle install安装到rmagick时出错,单独gem install rmagick安装也是同样的出错:

#  gem install rmagick
Building native extensions.  This could take a while...
ERROR:  Error installing rmagick:
	ERROR: Failed to build gem native extension.

/usr/bin/ruby extconf.rb
checking for Ruby version >= 1.8.5... yes
checking for gcc... yes
checking for Magick-config... no
Can't install RMagick 2.13.1. Can't find Magick-config in /usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:...

*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
	--with-opt-dir
	--without-opt-dir
	--with-opt-include
	--without-opt-include=${opt-dir}/include
	--with-opt-lib
	--without-opt-lib=${opt-dir}/lib
	--with-make-prog
	--without-make-prog
	--srcdir=.
	--curdir
	--ruby=/usr/bin/ruby
...

原来是 yum install ImageMagick-devel包没安装

# yum install ImageMagick-devel

安装成功后再重复先前的过程就OK了。

查看: 88 次 , ,

wget 莫名其妙的“失败:没有到主机的路由。”

归类于Linux 参与评论

二台主机,
A:双网卡,内网IP是10.0.0.20是反向代理服务器和网关
B:内网服务器,10.0.0.41 centos6,刚装好系统,A能ssh到B,B也能通过A作网关访问外网。在B上配置好redmine,thin默认使用3000端口,使用端口映射能正常访问到redmine。

从A配置Nginx转向到B主机,从外网访问A主机的redmine二级域名,但nginx提示 502 Bad Gateway ,从A主机用wget访问B主机的redmine,提示“没有主机的路由”

# wget http://10.0.0.41
--2012-04-14 16:36:03--  http://10.0.0.41/
正在连接 10.0.0.41... 失败:没有到主机的路由。

AB主机都能互ping,而且AB主机都能相互ssh登录,没有理由是路由问题!

十分郁闷!

找来找去发现是防火墙的问题,centos默认防火墙开放ssh但没开80!

在防火墙中打开80端口后,正常访问,NND 2B的出错提示。

查看: 97 次 ,

Linux TOP的替代工具 htop

归类于Linux 参与评论

top太老了,试下htop吧:
交互式的进程管理器
支持鼠标操作
按不同字段排序
按进程树查看

在Centos中使用yum安装步骤:

# cd
# wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm
# sudo rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
# sudo rpm -i rpmforge-release-0.5.2-2.el6.rf.*.rpm
# sudo yum install htop
# htop

看几个界面图。

P1 默认进程列表

image

p2 帮助界面

image

p3进程树

image

查看: 80 次

Hyper-V2安装Centos6.2无法使用网络问题

归类于Linux 参与评论

刚才安装好centos6.2之后,挂载上LinuxIC v21.iso,发布编译出错了。网上搜索一下,

Linux Integration Services Version v3.2已经放出来了,下载地址:http://www.microsoft.com/downloads/zh-cn/details.aspx?FamilyID=216de3c4-f598-4dff-8a4e-257d4b7a1c12。3.2版本提供rpm包安装,不需要再去编译源码了。

从虚拟机中挂上ISO文件到光驱,在centos中加载并安装

# mount /dev/cdrom /mnt
# cd /mnt
# ./install.sh

等待几分钟,安装完成后重启。看下hyper-v的模块是否安装成功。

# lsmod | grep hv
hv_mouse                4217  0
hv_netvsc              21591  0
hv_utils                5661  0
hv_timesource           1079  0 [permanent]
hv_storvsc              9087  2
hv_vmbus               29482  5 hv_mouse,hv_netvsc...

添加一下二个网络配置文件:

# cat /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no

eth0网络配置文件

#cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes

BOOTPROTO=dhcp

重启网卡服务再查看网络连接信息。

# /etc/init.d/network restart
# ifconfig

没意外的话就能看到有eth0网卡信息了。

查看: 100 次 , ,

Centos6启动光盘本地源,使用yum安装软件包

归类于Linux 参与评论

Centos 6.2安装好后在 /etc/yum.repos.d/目录已经有这三个文件:
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo

要启动本地光盘源,打开 CentOS-Media.repo ,将此文件中的 enabled=0改为enaled=1 即可。
保存退出后,用yum list,即可看到本地光盘中的包有列出。

我是在hyper-v虚拟机上安装Centos,刚装好系统时centos认识不了hyper-v的虚拟网卡,没有网络可使用,如果直接使用yum list时,还会到默认的源网站去搜索,但连接不上网络就会提示出错了。于我把 /etc/yum.repos.d/目录下的CentOS-Base.repo改名为CentOS-Base.repo.org,这样yum就会忽略掉此配置文件了,然后再用yum install … 来安装,就只从光盘中搜索安装包了。

查看: 94 次 ,

nginx proxy_buffering参数导致反向代理文件下载缓慢问题

归类于nginx 参与评论

从柳州访问OA系统下载附件速度非常慢,下载速度只有5KB/s左右,但从南宁的机房访问速度却很快,达到800KB/s,初步判断是柳州机房到桂林的网络问题。

无意中做了个测试,在nginx代理服务器上做个主机,指向同一主机的一个目录,目录内有个200M的iso文件,此时从柳州和南宁下载这个文件都有1Mb/s以上。断定是反向代理的原因。

再测试了反向代理到内网的一个hyper-v虚拟机和一个物理主机上的网站,在柳州下载都是只有几k,南宁下载有800kb/s左右。排除hyper-v主机机网络性能原因。

把nginx参数一个一个修改测试,最后在将 proxy_buffering 设置为 off  时,从柳州下载达到了1.5MB/s,从南宁机房下载有2.5MB/s。确定是代理缓存参数引起。

nginx官网对proxy_buffering参数是这么说的:

proxy_buffering

syntax: proxy_buffering on|off;

default: proxy_buffering on;

context: http, server, location

This directive activate response buffering of the proxied server.

If buffering is activated, then nginx reads the answer from the proxied server as fast as possible, saving it in the buffer as configured by directivesproxy_buffer_size and proxy_buffers. If the response does not fit into memory, then parts of it will be written to disk.

If buffering is switched off, then the response is synchronously transferred to client immediately as it is received. nginx does not attempt to read the entire answer from the proxied server, the maximum size of data which nginx can accept from the server is set by directive proxy_buffer_size.

Also note that caching upstream proxy responses won’t work if proxy_buffering is set to off.

For Comet applications based on long-polling it is important to set proxy_buffering to off, otherwise the asynchronous response is buffered and the Comet does not work.

Buffering can be set on a per-request basis by setting the X-Accel-Buffering header in the proxy response.

此参数默认值是on,意思是nginx从后端网站接收到数据后,先缓存起来,等buffer满了之后再发送给客户机,如果无法保存在缓冲区则会写入磁盘。将此参数关闭后,nginx从后端获取多少数据就发送多少到客户端。

问题虽然解决了,但还有困惑没解。

出处:blog.lizj.me

参考资料:
http://gcoder.blogbus.com/tag/proxy_buffering/
http://www.ithov.com/linux/109035.shtml

查看: 94 次

Ubuntu中安装WEBMIN

归类于Linux 参与评论

1.使用Debian包安装

http://sourceforge.net/projects/webadmin/files/webmin/下载最新版本,然后再用dpkg命令安装如:

apt-get install perl libnet-ssleay-perl openssl libauthen-pam-perl\
     libpam-runtime libio-pty-perl apt-show-versions python

wget http://prdownloads.sourceforge.net/webadmin/webmin_1.580_all.deb
dpkg --install webmin_1.580_all.deb

2.使用apt源安装

首先添加GPG key:

wget http://www.webmin.com/jcameron-key.asc
apt-key add jcameron-key.asc

打开/etc/apt/sources.list,在末尾添加

deb http://download.webmin.com/download/repository sarge contrib
deb http://webmin.mirror.somersettechsolutions.co.uk/repository sarge contrib

保存后安装:

apt-get update
apt-get install webmin

安装好后可以通过http://localhost:10000/访问,如果开了防火墙,需要开放1000端口。

 

参考:http://www.webmin.com/deb.html

查看: 83 次

wget配置使用代理

归类于Linux 参与评论

编辑 ~/.wgetrc 文件,内容如下:

http_proxy = http://proxy_server_ip:1080
ftp_proxy  = http://proxy_server_ip:1080

use_proxy=on
wait=15

查看: 87 次

顶部