postgres复制表结构

2014年6月17日 11:18

  • 复制表结构
create table his_process_data_201405 as 
( select * from his_process_data_201406 limit 0)
  • 完整复制一张表
create table his_process_data_201405 as 
( select * from his_process_data_201406)

 

 

评论(0) 阅读(4406)

用个人电脑搭建网站

2014年6月01日 01:47

是否可以用个人电脑搭建网站? 可以通信就一定可以相互访问.
  • 问题
通常个人电脑处在内网,连接着路由器,路由经过ads拨号,拥有临时外网地址. 当个人电脑向外网发送请求时,路由器会使用NAT协议,将请求转换为自己对为外网的请求。当外网返回数据时,路由器先接收到数据,然后根据转换关系,将请求转给个人电脑。在整个过程中,外网不知到个人电脑的存在,只知道到路由器. 在这种情况下如何将个人电脑上的服务映射出去呢?
  • 解决办法
每次个人电脑发送对外请求时,路由器都会将请求转换为自己的请求. 接收外网返回数据时,通过发送时的转换规则,返回给个人电脑。 如果转换关系是固定的,那么外网也就可以访问个人电脑了.
  • 示例
1. 启动一个简单web服务
c:\Python27>python -m SimpleHTTPServer 80
Serving HTTP on 0.0.0.0 port 80 ...
 
2. 设置路由器转发规则
 
3. 使用外网地址访问 
用百度搜索"ip地址"即可看到自己的外网地址,然后访问http://xxxxxx/
 
4. 使用域名访问
路由器的外网IP地址经常在变,不方便. 可以安装花生壳,然个人电脑拥有域名. 这样就不用管IP地址经常变化的问题.
 
花生壳下在地址
填入身份信息,注册成功,它会生成一个域名.
  • 其它
如果想把virtualbox虚拟机里面的服务映射到外网. 则需要在"网卡--网络地址转换-->端口转发"中进行设置. 
启用网卡2并设置为桥接网卡,让虚拟机拥有内网IP,然后再设置路由器转发规则,是没有用的.
 

Tags: 服务器
评论(1) 阅读(2484)

局域网如何访问外网

2014年5月31日 23:50

通常一台主机拥有外网地址,根据网络协议很容易理解,通信的过程.
 
如果主机拥有的是局域网IP地址,该如何理解?
比如:常见的一种情况,主机地址是192.168.1.100,连接着一个路由器,路由器通过拨号上网(拥有临时外网IP). 这种情况下局域网主机, 如何访问外网主机(比如www.baidu.com), 根据网络协议似乎很难理解两者是如何通信的?
 
答案是: 网络地址转换(NAT),将私有地址转化为合法IP地址。
 
当主机192.168.1.100向外网主机发送数据,在通过个人路由器时,路由器会修改IP报文,将IP和端口替换为它的外网IP和随机分配的端口,并且将修改前后的信息作为映射关系保存起来, 再将IP报文转发出去. 当外网主机返回信息时,先被路由器接收到,路由器再根据发送数据时保存的映射关系,将数据发送给内网主机.

Tags: 网络
评论(1) 阅读(2508)

ssh登陆提示Too many authentication failures for wyq

2014年5月05日 16:58

 
碰到使用ssh登陆,直接出现认证失败次数太多的问题.
 
在自己机器上模拟了下面测试.
 
ssh登陆系统,未输入密码就提示认证失败
[wyq@localhost ~]$ ssh wyq@192.168.1.107
Received disconnect from 192.168.1.107: 2: Too many authentication failures for wyq
查看/etc/sshd/sshd_config尝试认证次数
MaxAuthTries 1
 
最大认证次数为1,为什么还没有输入密码就已经提示 Too many authentication failures ?
 
开启ssh的debug模式
[wyq@localhost ~]$ ssh -v wyq@192.168.1.107
OpenSSH_6.4, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /home/wyq/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 51: Applying options for *
debug1: Connecting to 192.168.1.107 [192.168.1.107] port 22.
debug1: Connection established.
debug1: identity file /home/wyq/.ssh/id_rsa type 1
debug1: identity file /home/wyq/.ssh/id_rsa-cert type -1
debug1: identity file /home/wyq/.ssh/id_dsa type -1
debug1: identity file /home/wyq/.ssh/id_dsa-cert type -1
debug1: identity file /home/wyq/.ssh/id_ecdsa type -1
debug1: identity file /home/wyq/.ssh/id_ecdsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.4
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.4
debug1: match: OpenSSH_6.4 pat OpenSSH*
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5-etm@openssh.com none
debug1: kex: client->server aes128-ctr hmac-md5-etm@openssh.com none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA 66:29:e1:f3:32:92:64:da:98:bc:ab:f8:9c:a4:63:02
debug1: Host '192.168.1.107' is known and matches the ECDSA host key.
debug1: Found key in /home/wyq/.ssh/known_hosts:21
debug1: ssh_ecdsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: gssapi-keyex
debug1: No valid Key exchange context
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure.  Minor code may provide more information
Cannot determine realm for numeric host address

debug1: Unspecified GSS failure.  Minor code may provide more information
Cannot determine realm for numeric host address

debug1: Unspecified GSS failure.  Minor code may provide more information


debug1: Unspecified GSS failure.  Minor code may provide more information
Cannot determine realm for numeric host address

debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/wyq/.ssh/id_rsa
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Trying private key: /home/wyq/.ssh/id_dsa
debug1: Trying private key: /home/wyq/.ssh/id_ecdsa
debug1: Next authentication method: password
wyq@192.168.1.107's password: 
发现在提示输入密码前它已经进行了几次验证
debug1: Next authentication method: gssapi-keyex
debug1: Next authentication method: gssapi-with-mic
debug1: Next authentication method: publickey
debug1: Next authentication method: password
原来在密码认证之前,ssh已经进行了几种认证.
应该是他们导致的,具体原因就不是很清楚.
 
还有一个问题就是MaxAuthTries值再大,也只能输入三次密码.
这个问题也很疑惑的.
 
挺奇怪的,管理人员怎么喜欢修改MaxAuthTries的值?
ssh登陆密码输入错误,被中断后,别人再ssh不行吗?
默认值很合理的,完全没有必要修改.
 

Tags: ssh
评论(2) 阅读(7148)

sqlfront.h 没有那个文件或目录

2014年4月23日 17:12

  • 安装pymssql,出现下面情况
[wyq@localhost ~]$ sudo pip install pymssql
Downloading/unpacking pymssql
  Downloading pymssql-2.1.0.tar.bz2 (1.9MB):   0%  8.2kB
  Downloading pymssql-2.1.0.tar.bz2 (1.9MB): 1.9MB downloaded
  Running setup.py egg_info for package pymssql
    setup.py: platform.system() => 'Linux'
    setup.py: platform.architecture() => ('64bit', 'ELF')
    setup.py: platform.linux_distribution() => ('Fedora', '20', 'Heisenbug')
    setup.py: platform.libc_ver() => ('glibc', '2.2.5')
    setup.py: Not using bundled FreeTDS
    setup.py: include_dirs = ['/usr/local/include']
    setup.py: library_dirs = ['/usr/local/lib']
    
    warning: no files found matching 'pymssql_version.py'
    warning: no files found matching 'win32/freetds.zip'
    warning: no previously-included files matching '*' found under directory 'docs/_build'
Installing collected packages: pymssql
  Running setup.py install for pymssql
    setup.py: platform.system() => 'Linux'
    setup.py: platform.architecture() => ('64bit', 'ELF')
    setup.py: platform.linux_distribution() => ('Fedora', '20', 'Heisenbug')
    setup.py: platform.libc_ver() => ('glibc', '2.2.5')
    setup.py: Not using bundled FreeTDS
    setup.py: include_dirs = ['/usr/local/include']
    setup.py: library_dirs = ['/usr/local/lib']
    building '_mssql' extension
    gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/local/include -I/usr/include/python2.7 -c _mssql.c -o build/temp.linux-x86_64-2.7/_mssql.o -DMSDBLIB
    _mssql.c:346:22: 致命错误:sqlfront.h:没有那个文件或目录
     #include "sqlfront.h"
                          ^
    编译中断。
    error: command 'gcc' failed with exit status 1
    Complete output from command /usr/bin/python -c "import setuptools;__file__='/tmp/pip_build_root/pymssql/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-K_4vEY-record/install-record.txt --single-version-externally-managed:
    setup.py: platform.system() => 'Linux'

setup.py: platform.architecture() => ('64bit', 'ELF')

setup.py: platform.linux_distribution() => ('Fedora', '20', 'Heisenbug')

setup.py: platform.libc_ver() => ('glibc', '2.2.5')

setup.py: Not using bundled FreeTDS

setup.py: include_dirs = ['/usr/local/include']

setup.py: library_dirs = ['/usr/local/lib']

running install

running build

running build_ext

building '_mssql' extension

creating build

creating build/temp.linux-x86_64-2.7

gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/local/include -I/usr/include/python2.7 -c _mssql.c -o build/temp.linux-x86_64-2.7/_mssql.o -DMSDBLIB

_mssql.c:346:22: 致命错误:sqlfront.h:没有那个文件或目录

 #include "sqlfront.h"

                      ^

编译中断。

error: command 'gcc' failed with exit status 1

----------------------------------------
Cleaning up...
Command /usr/bin/python -c "import setuptools;__file__='/tmp/pip_build_root/pymssql/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-K_4vEY-record/install-record.txt --single-version-externally-managed failed with error code 1 in /tmp/pip_build_root/pymssql
Traceback (most recent call last):
  File "/bin/pip", line 9, in <module>
    load_entry_point('pip==1.4.1', 'console_scripts', 'pip')()
  File "/usr/lib/python2.7/site-packages/pip/__init__.py", line 147, in main
    return command.main(args[1:], options)
  File "/usr/lib/python2.7/site-packages/pip/basecommand.py", line 169, in main
    text = '\n'.join(complete_log)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe8 in position 21: ordinal not in range(128)
  • 需要安装freetds
sudo yum install freetds-devel
SQLServer和Sybase使用的协议是TDS协议,linux中使用freetds连接SQLServer.
 
 

Tags: sqlserver;python;pymssql
评论(1) 阅读(5632)

净空法师:听经的好处,就像用火去点燃湿透的木头

2014年4月15日 06:43

我们听经有没有好处?有好处,这个好处就是薰习,一遍一遍的薰习,你才能真觉悟。我们像一根木头掉在水里,在水里泡了几千年,湿透了,今天拿出来用一支火柴去把它点燃,能不能点燃?点不燃。不要紧,再点一支,点上一万支,点上十万支,点上一百万支,点燃了。这叫什么?长时薰修,肯定它会燃的,木头怎么会不燃?水里面泡久了,就是习气太深、习气太重,经虽然是听明白,回不了头来,一转眼老毛病又发了,就这么个道理,怎么点都点不燃。这就说明长时薰修的必要。

像惠能大师那种人,那一点就燃,佛法里称他做上上根人。怎么那么容易就开悟?祖师大德告诉我们,他不是偶然的,他是无量劫就在修大乘。就好像这一根泡在水里的木头,它已经被燃烧过一百万次,还没有点著,这一支就把它点著。我们呢?我们前面没有这个数字,没有长时间薰修。有没有薰修?肯定有,如果要是没有的话,这个经你听不下去,你在这里两小时坐不住。你不相信到外面找个人来,你叫他在这里坐两个钟点,他能坐五分钟就不错,坐不住!那就是什么?他没善根。你能坐得住,证明你过去决定不止一世、二世、三四五世,你大概至少也有十几二十世的薰修,你听到佛法才能欢喜,才欢欢喜喜能坐两个钟点,天天都会来,不是容易事情。还是转不过来,就是习气太重,烦恼太深,天天薰习对你就有很大的帮助。如果每天不间断,连续薰个十年、二十年、三十年,你成功了,你就会大彻大悟。

净土宗的人大彻大悟就是彻底放下,身心世界、世出世法统统放下,一部经、一句佛号。这是什么?这是真正觉悟的人,不是真正觉悟的人做不到。诸位细细想想,取西方极乐世界,亲近阿弥陀佛,不是难事。善导大师所说「万修万人去」,一个都不漏,这个话是真的,不是假的。李老师告诉我们,一万个念佛人,真正能往生的也只有三、五个人。他的话也是真的,不是假的。为什么?大多数念佛人不想去,口里想,心里不想,口里说要去,心里对这个世间还留恋得很,不肯放下,不是去不了,不想去那就没法子。所以能不能往生,权操在你自己手上,谁都管不了。往生的权不是在阿弥陀佛手上,这个要知道,在自己的手上,自己想不想去。

评论(1) 阅读(3612)

cnpm包管理工具

2014年3月26日 14:33

通常的包管理工具是npm,npm使用的镜像源在国外,经常被gfw屏蔽掉.

发现另一个包管理工具cnpm,可以正常使用.

  • 安装cnpm

npm install -g cnpm --registry=http://r.cnpmjs.org

  • 使用

cnpm install package

用法与npm一样

Tags: npm nodejs
评论(0) 阅读(1474)

npm无反应

2014年3月25日 15:42

通过npm安装node包时,发现卡住了,没有反应

查找原因

加上参数-verbose,查看详细信息
发现卡在下面这个地方
npm http GET https://registry.npmjs.org/express
npm info retry will retry, error on last attempt: Error: connect ETIMEDOUT
通过提示知道应该是出现超时.

解决方法

最后找到,通过修改它的安装源,换成国内的http://registry.cnpmjs.org 即可.
  • config命令
npm config set registry http://registry.cnpmjs.org
npm info underscore
  • 命令行指定
npm --registry http:/registry.cnpmjs.org install express
  • 修改~/.npmrc配置文件,加入以下内容
registry = http://registry.cnpmjs.org

cnpm

更方便的方法是使用cnpm,安装后用法与npm一样
sudo npm install -g cnpm --registry http://r.cnpmjs.org
 

 

Tags: nodejs
评论(0) 阅读(4699)

linux端口使用权限

2014年3月25日 09:55

在Linux系统中,监听1024以下端口需要root权限。因此,如果想监听80,需要使用sudo命令启动程序。
  • 示例
[wyq@localhost ~]$ python -m SimpleHTTPServer 80
Traceback (most recent call last):
  File "/usr/lib64/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib64/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/usr/lib64/python2.7/SimpleHTTPServer.py", line 220, in <module>
    test()
  File "/usr/lib64/python2.7/SimpleHTTPServer.py", line 216, in test
    BaseHTTPServer.test(HandlerClass, ServerClass)
  File "/usr/lib64/python2.7/BaseHTTPServer.py", line 595, in test
    httpd = ServerClass(server_address, HandlerClass)
  File "/usr/lib64/python2.7/SocketServer.py", line 419, in __init__
    self.server_bind()
  File "/usr/lib64/python2.7/BaseHTTPServer.py", line 108, in server_bind
    SocketServer.TCPServer.server_bind(self)
  File "/usr/lib64/python2.7/SocketServer.py", line 430, in server_bind
    self.socket.bind(self.server_address)
  File "/usr/lib64/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
socket.error: [Errno 13] Permission denied

 

评论(2) 阅读(4031)

nodejs理解[笔记]

2014年3月24日 10:47

 
node.js是什么
node 是一个服务器端 JavaScript 解释器,它将改变服务器应该如何工作的概念。它的目标是帮助程序员构建高度可伸缩的应用程序,编写能够处理数万条同时连接到一个(只有一个)物理机的连接代码。
 
Node 旨在解决什么问题?
当前服务瓶颈:服务器能够处理的并发连接的最大数量。
 
Node 解决这个问题的方法:更改连接到服务器的方式。每个连接发射一个在 Node 引擎的进程中运行的事件,而不是为每个连接生成一个新的 OS 线程(并为其分配一些配套内存)。Node 声称它绝不会死锁,因为它根本不允许使用锁,它不会直接阻塞 I/O 调用。Node 还宣称,运行它的服务器能支持数万个并发连接。
 
 
Node 如何工作?
Node 本身运行 V8 JavaScript。
什么是 V8?V8 JavaScript 引擎是 Google 用于其 Chrome 浏览器的底层 JavaScript 引擎。
 
Node 使用事件驱动编程模型。
 
Node 适用场景?
Node 非常适合以下情况:在响应客户端之前,您预计可能有很高的流量,但所需的服务器端逻辑和处理不一定很多。
 
典型示例:
  • RESTfull API
提供 RESTful API 的 Web 服务接收几个参数,解析它们,组合一个响应,并返回一个响应(通常是较少的文本)给用户。这是适合 Node 的理想情况,因为您可以构建它来处理数万条连接。它仍然不需要大量逻辑;它本质上只是从某个数据库中查找一些值并将它们组成一个响应。由于响应是少量文本,入站请求也是少量的文本,因此流量不高,一台机器甚至也可以处理最繁忙的公司的 API 需求。
  • Twitter队列
想像一下像 Twitter 这样的公司,它必须接收 tweets 并将其写入数据库。实际上,每秒几乎有数千条 tweet 达到,数据库不可能及时处理高峰时段所需的写入数量。Node 成为这个问题的解决方案的重要一环。如您所见,Node 能处理数万条入站 tweet。它能快速而又轻松地将它们写入一个内存排队机制(例如 memcached),另一个单独进程可以从那里将它们写入数据库。Node 在这里的角色是迅速收集 tweet,并将这个信息传递给另一个负责写入的进程。想象一下另一种设计(常规 PHP 服务器会自己尝试处理对数据库本身的写入):每个 tweet 都会在写入数据库时导致一个短暂的延迟,因为数据库调用正在阻塞通道。由于数据库延迟,一台这样设计的机器每秒可能只能处理 2000 条入站 tweet。每秒处理 100 万条 tweet 则需要 500 个服务器。相反,Node 能处理每个连接而不会阻塞通道,从而能够捕获尽可能多的 tweets。一个能处理 50,000 条 tweet 的 Node 机器仅需 20 台服务器即可。
  • 电子游戏统计数据
如果您在线玩过《使命召唤》这款游戏,当您查看游戏统计数据时,就会立即意识到一个问题:要生成那种级别的统计数据,必须跟踪海量信息。这样,如果有数百万玩家同时在线玩游戏,而且他们处于游戏中的不同位置,那么很快就会生成海量信息。Node 是这种场景的一种很好的解决方案,因为它能采集游戏生成的数据,对数据进行最少的合并,然后对数据进行排队,以便将它们写入数据库。使用整个服务器来跟踪玩家在游戏中发射了多少子弹看起来很愚蠢,如果您使用 Apache 这样的服务器,可能会 有一些有用的限制;但相反,如果您专门使用一个服务器来跟踪一个游戏的所有统计数据,就像使用运行 Node 的服务器所做的那样,那看起来似乎是一种明智之举.
 
来源 http://www.ibm.com/developerworks/cn/opensource/os-nodejs/
 
 

Tags: nodejs
评论(4) 阅读(1659)