CentOS-Yum: warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID 6b8d79e6
April 8th, 2011
遇到 Header V3 DSA signature: NOKEY, key ID 6b8d79e6这里问题的时候就是需要更新key,这里提供几个国外的key文件更新源:
rpm—import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt rpm—import http://quattor.web.lal.in2p3.fr/packages/os/sl520-x86_64/base/RPM-GPG-KEYs/RPM-GPG-KEY-CentOS-5
mysql master slave setting
April 1st, 2011
目前情况: 1.系统版本都是rhel5 mysql版本相同 2.主服务器正在运行,不能停止。 3.主服务器IP为:192.168.1.100 从服务器IP为:192.168.1.101 4.从服务器MSYQL slave 为停止状态 配置步骤: 1、主库创建/etc/my.cnf,修改[mysqld]里边的键值增加
server-id=1
log-bin=binlog_name
2、主库增加用户,用于从库读取主库日志。
grant replication slave,reload,super on .* to ‘slave’@’192.168.1.101’ identified by ‘123456’;
flush privileges;
3、从库连接主库进行测试。
mysql -u slave -p -h 192.168.1.100 //master的IP
4、停从库,修改从库/etc/my.cnf,增加选项:
[mysqld]
server-id=2
master-host=192.168.1.100
master-user=slave
master-password=123456
5.锁表
mysql > FLUSH TABLES WITH READ LOCK;
注意:为了保证FLUSH TABLES语句让读锁定保持有效。(如果退出客户程序,锁被释放)。建立新的SSH连接,然后对主服务器上的数据进行快 照。
6.建立快照 tar -cvf data.tar /var/lib/mysql 将压缩包拷贝过去后解压缩
也可以用scp拷贝过去: scp -r /var/lib/mysql/ 192.168.1.101:/var/lib/mysql/ 注意拷贝过去后权限的设置 chown -R mysql.mysql /var/lib/mysql
数据量大可以用mysqldump导出.
7.解锁
mysql > UNLOCK TABLES;
8.记下file pos值
当FLUSH TABLES WITH READ LOCK所置读锁定有效时,读取主服务器上当前的二进制日志名(file)和偏移量值(pos):
mysql > SHOW MASTER STATUS;
—-—-—-—-—-—-—-——-—-—--+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
—-—-—-—-—-—-—-——-—-—--+
| mysql-bin.003 | 73 | test | manual,mysql |
—-—-—-—-—-—-—-——-—-—--+
File列显示日志名,而Position显示偏移量。在该例子中,二进制日志值为mysql-bin.003,偏移量为73。记录该值。以后设置从服务器时需要
使用这些值。它们表示复制坐标,从服务器应从该点(也可以是任何点)开始从主服务器上进行新的更新。
- mysql>start slave;
- mysql>load data from master;
10.验证配置 登录从服务器输入如下命令:
mysql> show slave status\G;
会得到类似下面的列表:
Slave_IO_Running: Yes Slave_SQL_Running: Yes
都为yes,则配置正确.
11.进行测试:
主库创建表,
mysql>create database sampdb;
mysql>use sampdb;
mysql>create table new (name char(20),phone char(20));
mysql>insert into new (’abc‘,’0532555555’); 主从服务器重启;
打开从库,查看: #mysql -u root -p mysql>show databases; //应该能看到master创建的库sampdb
mysql
sampdb
test
mysql>use sampdb;
mysql>show tables;
new
说明主从数据库创建成功。
附: 一些错误信息的处理,主从服务器上的命令,及状态信息。 在从服务器上使用show slave status\G Slave_IO_Running,为No, 则说明IO_THREAD没有启动,请执行start slave io_thread Slave_SQL_Running为No 则复制出错,查看Last_error字段排除错误后执行start slave sql_thread 查看Slave_IO_State字段空 //复制没有启动 Connecting to master//没有连接上master Waiting for master to send event//已经连上 主服务器上的相关命令: show master status show slave hosts show logs show binlog events purge logs to ‘log_name’ purge logs before ‘date’ reset master(老版本flush master) set sql_log_bin=
从服务器上的相关命令: slave start slave stop SLAVE STOP IO_THREAD //此线程把master段的日志写到本地 SLAVE start IO_THREAD SLAVE STOP SQL_THREAD //此线程把写到本地的日志应用于数据库 SLAVE start SQL_THREAD reset slave SET GLOBAL SQL_SLAVE_SKIP_COUNTER load data from master show slave status(SUPER,REPLICATION CLIENT) CHANGE MASTER TO MASTER_HOST=, MASTER_PORT=,MASTER_USER=, MASTER_PASSWORD= //动态改变master信息 PURGE MASTER [before ‘date’] 删除master端已同步过的日志
几个跟热备有关的mysql命令:(需要在mysql命令行界面或query )
- stop slave #停止同步
- start slave #开始同步,从日志终止的位置开始更新。
- SET SQL_LOG_BIN=0|1 #主机端运行,需要super权限,用来开停日志,随意开停,会造成主机从机数据不一致,造成错误
- SET GLOBAL SQL_SLAVE_SKIP_COUNTER=n # 客户端运行,用来跳过几个事件,只有当同步进程出现错误而停止的时候才可以执行。
- RESET MASTER #主机端运行,清除所有的日志,这条命令就是原来的FLUSH MASTER
- RESET SLAVE #从机运行,清除日志同步位置标志,并重新生成master.info 虽然重新生成了master.info,但是并不起用,最好,将从机的mysql进程重启一下,
- LOAD TABLE tblname FROM MASTER #从机运行,从主机端重读指定的表的数据,每次只能读取一个,受timeout时间限制,需要调整timeout时间。执行这个命令需要同步账号有 reload和super权限。以及对相应的库有select权限。如果表比较大,要增加net_read_timeout 和 net_write_timeout的值
- LOAD DATA FROM MASTER #从机执行,从主机端重新读入所有的数据。执行这个命令需要同步账号有reload和super权限。以及对相应的库有select权限。如果表比较大,要增加net_read_timeout 和 net_write_timeout的值
- CHANGE MASTER TO master_def_list #在线改变一些主机设置,多个用逗号间隔,比如 CHANGE MASTER TO MASTER_HOST=’master2.mycompany.com’, MASTER_USER=’replication’, MASTER_PASSWORD=’bigs3cret’
- MASTER_POS_WAIT() #从机运行
- SHOW MASTER STATUS #主机运行,看日志导出信息
- SHOW SLAVE HOSTS #主机运行,看连入的从机的情况。
- SHOW SLAVE STATUS (slave)
- SHOW MASTER LOGS (master)
- SHOW BINLOG EVENTS IN ‘logname’ [ LIMIT [offset,] rows ]
- PURGE [MASTER] LOGS TO ‘logname’ ; PURGE [MASTER] LOGS BEFORE ‘date’
文章出处:http://www.diybl.com/course/6_system/linux/Linuxjs/2008108/149090.html
shell sed get string behind : or =
March 30th, 2011
to find ‘yang’ that just behind ‘name:’
echo ‘adsd asd name:yang asdf asd’ |sed ’s/. ]\)./\1/’
another sed
ttt.txt
DEVICE1
HDWR_TYPE=1 DEVICE_ASSUMED=NONE IP_ADDR=10.2.0.45
DEVICE2
IP_ADDR=10.2.0.40
sed ’s/^.\(IP_ADDR=.*\)/\1/’ ttt.txt
find all port used
March 25th, 2011
netstat -lnptu netstat—tcp—udp—listening—program
http://hemju.com/2011/03/04/rails-cron-job-scheduling-using-redis-resque-and-rufus/
detect charset by rails gem
March 16th, 2011
1.Here is a rails gem: chardet
gem install chardet
require ‘UniversalDetector’
irb(main):>p UniversalDetector::chardet('Ascii text')
{"confidence"=>1.0, "encoding"=>"ascii"}
=>nil
irb(main):>p UniversalDetector::chardet('åäö')
{"confidence"=>0.87625, "encoding"=>"utf-8"}
2.change to UTF-8
require "iconv"
Iconv.iconv("utf-8", UniversalDetector::chardet(str)["encoding"],str)
Install Ruby and Rails on Ubuntu in One Line
February 23rd, 2011
wget—no-check-certificate https://github.com/joshfng/railsready/raw/master/railsready.sh && bash railsready.sh
From Rubyinside.com http://www.rubyinside.com/rails-ready-ruby-and-rails-on-ubuntu-in-one-line-4214.html
Create new model class Dynamically
December 2nd, 2010
Create a custom model by given model_name
def define_customed_model
Object.const_set(@model_name, Class.new(ActiveRecord::Base))
end
Recursive organization tree
November 26th, 2010
Use a helper method to create multi level tree:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
def generate_nodes(root_node) otype = ['company', 'org', 'project', 'group'] if root_node.children.size > 0 @html += '<ul>' for n in root_node.children n.description = '' if n.description.nil? if n.children.size > 0 @html += '<li><span class="' + otype[n.otype] + '"><a href="/org_units/' + n.id.to_s + '">' + n.name + '</a></span>' + '<div>(' + n.description + ')</div>' generate_nodes(n) @html += '</li>' else @html += '<li><span class="' + otype[n.otype] + '"><a href="/org_units/' + n.id.to_s + '">' + n.name + '</a></span>' + '<div>(' + n.description + ')</div>' end end @html += '</ul>' end end |
Rails -- Use helper method in moder
November 26th, 2010
1. Create helpers.rb in /lib/
1 2 3 4 5 6 7 8 9 10 |
def help Helper.instance end class Helper include Singleton # look inside ActionView::Helpers to include any other helpers that you might need include ActionView::Helpers::DateHelper include ActionView::Helpers::TextHelper end |
1 2 3 4 5 6 7 |
require "#{Rails.root}/lib/helpers" def self.link help.pluralize 10, "person" help.link_to('a', :controller => 'user') end |
Ubuntu 10.04下安装Google拼音输入法
October 8th, 2010
在Ubuntu 10.04下安装Google拼音输入法,如下:
A. 获取代码:(没有git的先安装git:sudo apt-get install git-core)
$ git clone git://github.com/tchaikov/scim-googlepinyin.git
$ cd scim-googlepinyin
B. 编译前提:
上面给的链接里面有介绍怎么编译的,但少提了几个必需组件,这里列一下:
- autotools-dev
- libgtk2.0-dev
- libscim-dev
- libtool
- automake
用下面命令看看是不是安装了,如果没有,会自动帮你安装上:
$ aptitude install autotools-dev libgtk2.0-dev libscim-dev libtool automake
C. 编译:
记住系统必须先存在SCIM(没有的话 sudo apt-get install scim 一下)
$ ./autogen.sh
$ make
$ sudo make install
现在重启scim:
关闭scim:pkill scim
然后启动: scim -d
去首选项里的“语言支持”的“输入法”选择scim作为默认输入法,然后注销就OK了。
摘自 http://www.linuxidc.com/Linux/2010-06/26440.htm
shell -- AWK
September 12th, 2010
awk ‘{ s += $1 } END { print “sum: ”, s, ” average: ”, s/NR, ” samples: ”, NR }’
let’s say you have this log file: The output would then be:
1 sum: 15 average: 3 samples: 5
Code Style 2
September 6th, 2010
Developer Review¶ Part to copy for push to Dev QA
Migrations (No duplicate numbers, class names) - Code Indentation and Style (2 spaces + formatted) - Naming (meaningfull method names, ! ?) - Structure and Length (no long methods, light controllers, repeated code)- Javascript Checks (JSLint, Global, Namespacing) - Unit Tests - HTML and CSS (IE6, IE7, FF)- SQL (ansi, capitals, indentation) -
Checklist¶ 1. Style
Have you followed the coding style guide for all of your javascript, html, css, js and ruby?
2. Naming
Do your method names and attribute names convey meaning?
If a method alters or modifies something you should consider ending the method with ! remove_all_units!
if it's a method that returns true or false it should end with a question mark is_allowed?
3. Structure and length
Have you got long methods, do they need to be separated out into smaller easy to manage chunks?
Have you moved methods up to models where possible?
Are there repeated chunks that should be refactored into a single function?
4. Comments for hard or odd bits
Have you done something weird that's going to confuse one of the other coders, put in quick comments to explain why.
Are your comments in english? Does the english make sense or do you need to get it checked?
5. Javascript
Have you run your code and passed through JSLint?
Have you ensured that your not polluting the global namespace.
Are your functions in namespaced appropriately (i.e. the order me a coffee functions are all in SomeNamespace.CoffeeOrdering = {}
Are all of your function names in camel case?
6. Unit tests
Does your code have sufficient unit test coverage where appropriate?
7. HTML / CSS
Does it work and look good in IE6 / IE7 /FF / Safari (Where possible and necessary to test)
Ensure that there are no inline styles (unless absolutely necessary)
Is your html formatted
8. SQL
Are all of your sql statements in capital letters?
9. Ansi Standard Joins
Have you used Ansi-Standard joins and ensured that your table joins are separated from your where clauses.
e.g.The developer review is to ensure high quality, maintainable readable code. Each developer should "review" the code themselves before submitting it, but it needs to cover the following aspects:
1. Code indentation and style.
Is the entire file you submitted neat, indented (2 spaces) and formatted correctly?
Ruby¶
Spacing
2 Spaces for every piece of indented code
Comments
Comments should the follow the styles in:
http://rdoc.sourceforge.net/doc/index.html
In short
# Calculates some_code by using bla and some other business rule
some_code = bla + 1
and
# Test to see if a new word contains the same
# letters as the original
def is_anagram?(text)
@initial_letters == letters_of(text)
end
If the functionality is not obvious, there needs to be a comment describing what it does in English. If you think your English is wrong, then you can just ask someone else to review it for you.
Spacing between functions
use
a = 1
not
a=1
Lining functions up
use
dog = 1
cattle = 2
something_else = 3
not
dog=1
cattle=2
something_else=3
Comments should use the rubydoc styles shown at
Javascript¶
Function calls should be:
this.foo(bar);
Not
this.foo (bar);
The space differentiates them from method invocations.
Control statements should be:
// space between if and parentheses
if (something == x) {
doSomethingElse();
} else { // else on same line as close and open braces
doSomethingNice();
}
//space between switch and parentheses
switch (x) {
case 'y' :
return 'something';
break;
case 'n' :
return 'somethingElse';
break;
}
//space between for and parentheses
for (var i=0; i<n; i++) {
...
}
Conditions and assignments should have spaces ( except maybe in for loop declarations )
Use:
if (x == y) {
...
}
y = x;
Not
if (x==y) {
...
}
y=x;
HTML Formatting (2 spaces)¶
<div>
<ul>
<li><a href="bla.html">something</a></li>
</ul>
<p>Some Paragarph</p>
<p>Some other paragraph</p>
</div>
CSS Formatting (2 spaces)¶
#something {
border: 1px solid red;
color: green}
#something a {
font-weight: bold;}
#something div {
background-color: red;}
.some_other_class {
border: none;}
.some_other_class {
border: 1px solid blue;}
Javascript¶
The majority of javascript should be stored in separate files, which group functionality together. E.g. the functionality for a page.
The javascript should be namespaced and not pollute the global namaspace.
Only very small inline javascript should exist. E.g.
<% js do %>
Prohost.admin_page.init(<%= @init.to_json %>);
<% end %>
h2. SQL Formatting Note:
* Capital Letters for SQL keywords
* Line everything up
Instead of:
SELECT *
FROM table_a, table_b, table_c
WHERE table_a.id = table_b.foreign_key_id and
table_a.desc LIKE '%hello%' and
table_c.foreign_key_id = table_a.id (+)
Format it like this:
SELECT *
FROM table_a
JOIN table_b ON table_b.foreign_key_id = table_a.id
LEFT JOIN table_c ON table_c.foreign_key_id = table_a.id
WHERE table_a.desc LIKE '%hello%'
Code Style 1
September 6th, 2010
project_item
@product_name
def find_people
endattr_reader :product, :quantity
find_product(name, id, time)win = new Ext.Window({
applyTo: 'hello-win',
layout: 'fit',
width: 500,
height: 300,
closeAction: 'hide',
plain: true,
items: new Ext.TabPanel({
applyTo: 'hello-tabs',
autoTabs: true,
activeTab: 0,
deferredRender: false,
border: false
}),
buttons: [{
text: 'Submit',
disabled: true
},{
text: 'Close',
handler: function(){
win.hide();
}
}]
});SELECT CONCAT(parent.name,' , ',p.name) AS Project,
t.name AS Task,
wi.wComment AS Description,
sec_to_time(wi.wBegin) AS 'Start Time',
sec_to_time(wi.wEnd) AS 'End_time',
sec_to_time(wi.wEnd-wi.wBegin) AS Time
FROM WORKITEMS wi
INNER JOIN DAYINFOS di ON ( wi.dayinfo_id = di.id )
INNER JOIN TASKS t ON ( wi.task_id = t.id )
INNER JOIN PROJECTS p ON ( wi.project_id = p.id )
INNER JOIN PERSONS per ON ( di.person_id = per.id )
INNER JOIN PROJECTS parent ON ( IFNULL(p.parent_id,p.id) = parent.id )
WHERE di.daydate = '2009-03-10'
AND per.surName LIKE "eric%" mongodb group
September 6th, 2010
db.foo.group(
{key:{'sddf':true},
initial:{sum:0},
reduce:function(doc,prev){prev.sum += 1}
});Paypal in rails
September 6th, 2010
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
class PaypalController < ApplicationController include ActiveMerchant::Billing begin setup_response = gateway.setup_purchase(@total_price * 100, :ip => member_info[:ip], :return_url => pay_url(:controller => 'paypal',:action=>'confirm', :order_ids => @order_id.to_s,:only_path => false), :cancel_return_url => url_for(:controller => 'order',:action=>'payment',:order_id=>@order_id.to_s, :only_path => false) ) redirect_to gateway.redirect_url_for(setup_response.token) rescue redirect_to "/paypal/error?order_id=#{@order_id}" end private def gateway @gateway ||= PaypalExpressGateway.new( :login => 'API Login', :password => 'API Password', :signature => 'API Signature' ) end def confirm @orders = Order.find_orders_by_seq_no @order_id, current_member.id details_response = gateway.details_for(params[:token]) if !details_response.success? @message = details_response.message redirect_to "/paypal/error?order_id=#{@order_id}" return end @address = details_response.address end <% form_tag :action => 'complete', :token => params[:token], :payer_id => params[:PayerID] do %> <%= submit_tag 'Complete Payment' %> <% end %> def complete purchase = gateway.purchase(5000, :ip => request.remote_ip, :payer_id => params[:payer_id], :token => params[:token] ) if !purchase.success? @message = purchase.message render :action => 'error' return end end |
Referencial url http://www.codyfauser.com/2008/1/17/paypal-express-payments-with-activemerchant