Rootop 服务器运维与web架构

2014-02-16
发表者 Venus
暂无评论

Unknown OS character set ‘GB18030’.

写了一个关于mysql的脚本,执行时提示个错误:

mysql: Unknown OS character set ‘GB18030’.
mysql: Switching to the default character set ‘latin1’.

提示说未识别操作系统字符集GB18030,切换为latin1。

我这里解决办法是修改/etc/profile文件:

export LC_ALL=”zh_CN.UTF-8″        
export LANG=”zh_CN.UTF-8″

将原先参数修改为zh_CN.UTF-8,然后执行 source /etc/profile 生效。再执行脚本不再提示错误。

2014-01-27
发表者 Venus
暂无评论

varnish启动关闭脚本

#!/bin/bash
varnish_pid=/tmp/varnish.pid
v_command="/usr/local/varnish/sbin/varnishd -a 0.0.0.0:80 -f /usr/local/varnish/etc/varnish/default.vcl -P $varnish_pid"

case $1 in
start)
        if [ -s $varnish_pid ];then
                echo "varnish already running!"
        else
                $v_command
                echo "Start Ok!"
        fi
;;

stop)
        if [ -s $varnish_pid ];then
                kill -9 $(cat $varnish_pid) && echo "Stop Ok!" && rm -rf $varnish_pid
        else
                echo "varnish pid not found!"
        fi

;;

restart)

        if [ -s $varnish_pid ];then
                kill -9 $(cat $varnish_pid) && echo "Stop Ok!" && rm -rf $varnish_pid
                $v_command
                echo "Start Ok!"
        else
                echo "varnish pid not found!"
                echo "Start It!"
                $v_command
                echo "Start Ok!"
        fi
;;

*)
echo "Just start/stop/restart"
;;
esac

exit

脚本可接受的参数,start 启动、stop 关闭、restart 重启。

可将其复制到 /etc/init.d 下使用service varnish start/stop/restart 管理。

cp varnish.sh  /etc/init.d/varnish

chmod 755  /etc/init.d/varnish

2014-01-24
发表者 Venus
暂无评论

Ruby中Require、Load、Include和Extend的区别

原文:http://ionrails.com/2009/09/19/ruby_require-vs-load-vs-include-vs-extend/

Require:

require方法让你加载一个库,并且只加载一次,如果你多次加载会返回false。只有当你要加载的库位于一个分离的文件中时才有必要使用require。使用时不需要加扩展名,一般放在文件的最前面:

require ‘test_library’

Load:

load用来多次加载一个库,你必须指定扩展名:

load ‘test_library.rb’

Include:

当你的库加载之后,你可以在你的类定义中包含一个module,让module的实例方法和变量成为类本身的实例方法和类变量,它们mix进来了。根据锄头书,include并不会把module的实例方法拷贝到类中,只是做了引用,包含module的不同类都指向了同一个对象。如果你改变了module的定义,即使你的程序还在运行,所有包含module的类都会改变行为。

module Log
def class_type
“This class is of type: #{self.class}”
end
end
class TestClass
include Log
end
tc=TestClass.new.class_type    #=>This class is of type: TestClass

Extend:

extend会把module的实例方法作为类方法加入类中:

module Log
def class_type
“This class is of type: #{self.class}”
end
end
class TestClass
extend Log
end
tc=TestClass.class_type       #=>This class is of type: TestClass

2014-01-23
发表者 Venus
暂无评论

Ruby中gets和gets.chomp()的区别

gets和gets.chomp()都表示读入用户的输入并用于输出,但两者还是有所不同.

其中gets是得到的内容后,在输出时后面接着换行;而gets.chmop()得到的内容输出时后面不带空格和换行


print "how old r u ? "   #input 1
age=gets.chomp()
print "how tall r u ? "   #input 1
height=gets.chomp()
print "how much do u weigh ? "  #input 1
weight=gets.chomp()

puts "So,u r #{age} old,#{height} tall and #{weight} heavy."

执行结果:

how old r u ? 1
how tall r u ? 1
how much do u weigh ? 1
So,u r 1 old,1 tall and 1 heavy.

2014-01-22
发表者 Venus
暂无评论

notepad++与ruby配置开发环境

像此类的开发工具有很多,因为一直习惯用notepad++,就用它来做ruby开发,配置如下:

自行下载notepad++,ruby从 http://www.ruby-lang.org/zh_cn/ (官网)

或者是: http://rubyinstaller.org/downloads/

找需要的版本。最新版本为:

http://dl.bintray.com/oneclick/rubyinstaller/rubyinstaller-2.0.0-p353.exe

安装的时候可以将其加到系统变量中,为了方便,我这里都勾选。

安装完成即可。打开命令提示符,输入 ruby -v 可以看到版本信息。

打开notepad++,新建个空白项目,输入一句: puts “Hello world!”

按F6打开 “Execute”,在Command(s):中键入:

ruby $(FULL_CURRENT_PATH)

点击save,保存为ruby即可。

点击ok,就可以运行了:

PS:

如果在notepad++中按F6没有反应的话,那就是没有安装NppExec。

按照以下步骤安装:

会列出支持的插件:

我这里已经安装,所以没有列出。选中安装即可。