王筝的博客
ruby学习

比如在databases.yml里配置了一个cms_production,

# -*- encoding : utf-8 -*-
class CmsAaat < ActiveRecord::Base
establish_connection “cms_#{Rails.env}”.to_sym

virtualenv 安装文档
Django Hello World步骤
  • virtualenv helloworld
  • source helloworld/bin/activate
  • pip install Django
  • django-admin.py startproject helloproject
  • cd helloproject
  • python manage.py startpapp app1
  • vim helloproject/urls.py
  • vim app1/views.py -> 增加def hello(request)  return HttpResponse(“Hello World”)
  • python manage.py runserver

 

http://redis.io/download

$ wget http://download.redis.io/releases/redis-3.0.3.tar.gz
$ tar xzf redis-3.0.3.tar.gz
$ cd redis-3.0.3
$ make

=========================

新项目用到了redis,

$sudo pip install redis
$which redis-server找不到

从网上下载http://www.redis.io/
解压之后进入文件夹make
$sudo make install

$which redis-server
/usr/local/bin/redis-server
然后
$/usr/local/bin/redis-server
启动成功

http://localhost:5700/home/add/b15dcb2c58c011e38b3f

/opt/app/python/aaa-control
$ bin/uwsgi.sh stop
$ bin/uwsgi.sh start

重启nginx
/opt/nginx/sbin/nginx -t
/opt/nginx/sbin/nginx -s reload

http://libmemcached.org/libMemcached.html

报错:

Exception Value:
unknown behavior names: remove_failed
Exception Location: /usr/local/lib/python2.7/site-packages/pylibmc/client.py in set_behaviors, line 171

重装过程:

查看当前ubuntu版本
cat /etc/issue

查看安装的 libmemcached-dev版本
sudo apt-cache show libmemcached-dev

sudo apt-get remove libmemcached-dev 删除老版本

wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz
tar xvf libmemcached-1.0.18.tar.gz
cd libmemcached-1.0.18/
./configure
make
sudo make install

sudo pip uninstall pylibmc
sudo pip install pylibmc
sudo ln -s /usr/local/lib/libmemcached.so /usr/lib
(Exception Value:

libmemcached.so.11: cannot open shared object file: No such file or directory

)
sudo ln -s /usr/local/lib/libmemcached.so.11 /usr/lib

查看当前安装的全局应用
pip freeze

Django==1.5.5
MySQL-python==1.2.3
PIL==1.1.7
Thrift==0.7.0
hiredis==0.1.0
kazoo==2.0b1
mongoengine==0.6.20
pycrypto==2.6
pycurl==7.19.0
pylibmc==1.3.99-dev
pymongo==2.7.1
python-memcached==1.53
redis==2.9.1
simplejson==2.3.2
tornado==2.1.1
uWSGI==2.0.6
wsgiref==0.1.2
xlrd==0.9.3
xlutils==1.7.1
xlwt==0.7.5

http://linux.vbird.org/linux_server/0250simple_firewall.php#netfilter

iptables 是利用封包过滤机制, 分析封包的表头资料,根据表头资料定义的规则来决定是否可以进入主机或者被丢弃.刚才在服务器上练习的时候把自己给屏蔽了,提醒大家拿其他同学的ip做练习,哈哈.

$iptables [-t tables] [-L] [-nv]

-t: 后面接table,  例如nat 或者filter,如果省略此项目,则使用预设的filter

-L:列出目前的table的规则

-n: 不进行IP与HOSTNAME的反查

-v: 列出更多的信息,包括通过该规则的封包总位元数等

tty:[0] jobs:[0] cwd:[/opt/app]
14:50 [root@a]$ iptables -L -n
Chain INPUT (policy ACCEPT)
target prot opt source destination
DROP all — 10.103.55.165 0.0.0.0/0

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination

————————————————

15:08 [root@a]$ iptables -h
iptables v1.3.5

Usage: iptables -[AD] chain rule-specification [options]
iptables -[RI] chain rulenum rule-specification [options]
iptables -D chain rulenum [options]
iptables -[LFZ] [chain] [options]
iptables -[NX] chain
iptables -E old-chain-name new-chain-name
iptables -P chain target [options]
iptables -h (print this help information)

Commands:
Either long or short options are allowed.
–append -A chain Append to chain
–delete -D chain Delete matching rule from chain
–delete -D chain rulenum
Delete rule rulenum (1 = first) from chain
–insert -I chain [rulenum]
Insert in chain as rulenum (default 1=first)
–replace -R chain rulenum
Replace rule rulenum (1 = first) in chain
–list -L [chain] List the rules in a chain or all chains
–flush -F [chain] Delete all rules in chain or all chains
–zero -Z [chain] Zero counters in chain or all chains
–new -N chain Create a new user-defined chain
–delete-chain
-X [chain] Delete a user-defined chain
–policy -P chain target
Change policy on chain to target
–rename-chain
-E old-chain new-chain
Change chain name, (moving any references)
Options:
–proto -p [!] proto protocol: by number or name, eg. `tcp’
–source -s [!] address[/mask]
source specification
–destination -d [!] address[/mask]
destination specification
–in-interface -i [!] input name[+]
network interface name ([+] for wildcard)
–jump -j target
target for rule (may load target extension)
–goto -g chain
jump to chain with no return
–match -m match
extended match (may load extension)
–numeric -n numeric output of addresses and ports
–out-interface -o [!] output name[+]
network interface name ([+] for wildcard)
–table -t table table to manipulate (default: `filter’)
–verbose -v verbose mode
–line-numbers print line numbers when listing
–exact -x expand numbers (display exact values)
[!] –fragment -f match second or further fragments only
–modprobe=<command> try to insert modules using this command
–set-counters PKTS BYTES set the counter during insert/append
[!] –version -V print package version.

接下来新建一条

15:10 [root@a]$ iptables -A INPUT -s 16.16.136.66 -j DROP

由于写的是自己的ip地址,回车后已不能继续在服务器上继续操作…只能找同学帮忙删了服务器上的配置

接下来查看一下

15:12 [root@a]$ iptables -L -n
Chain INPUT (policy ACCEPT)
target prot opt source destination
DROP all — 10.166.55.11 0.0.0.0/0
DROP all — 12.16.136.66 0.0.0.0/0

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination

删除刚才新建的那条

15:12 [root@a]$ iptables -D INPUT 2

https://rubygems.org/

 

今天看到了如下的提示:

Warning: You’re using Rubygems 1.8.23.2 with Spring. Upgrate to at least Rubygems 2.1.0 and run Rails 4.1.4

 

$gem update –system

update to the latest RubyGems version

 

(1)base64(n=nil)

::base64 generates a random base64 string.

The argument n specifies the length of the random length. The length of the result string is about 4/3 of n.

If n is not specified, 16 is assumed. It may be larger in future.

The result may contain A-Z, a-z, 0-9, “+”, “/” and “=”.

p SecureRandom.base64 #=> "/2BuBuLf3+WfSKyQbRcc/A=="
p SecureRandom.base64 #=> "6BbW0pxO0YENxn38HMUbcQ=="


(2)hex(n=nil)

::hex generates a random hex string.

The argument n specifies the length of the random length. The length of the result string is twice of n.

If n is not specified, 16 is assumed. It may be larger in future.

The result may contain 0-9 and a-f.

p SecureRandom.hex #=> "eb693ec8252cd630102fd0d0fb7c3485"
p SecureRandom.hex #=> "91dc3bfb4de5b11d029d376634589b61"


(3)uuid()
::uuid generates a v4 random UUID (Universally Unique IDentifier).
p SecureRandom.uuid #=> "2d931510-d99f-494a-8c67-87feb05e1594"
p SecureRandom.uuid #=> "bad85eb9-0713-4da7-8d36-07a8e4b00eab"
p SecureRandom.uuid #=> "62936e70-1815-439b-bf89-8492855a7e6b"