Category Archives: unix/linux

unix,linux related

ruby gems 更改源

因为众所周知的原因,gem update,install等命令经常会遇到超时timeout,半天无响应,卡住等问题,建议换成淘宝的镜像源:

$ gem sources --remove https://rubygems.org/
$ gem sources -a https://ruby.taobao.org/
$ gem sources -l
*** CURRENT SOURCES ***

https://ruby.taobao.org
# 请确保只有 ruby.taobao.org
$ gem install rails

 

 

参考资料:http://ruby.taobao.org/

ubuntu 12.04安装jekyll

ubuntu版本

$ cat /etc/issue
Ubuntu 12.04 LTS \n \l

$ uname -a
Linux ubuntu 3.2.0-23-generic-pae #36-Ubuntu SMP Tue Apr 10 22:19:09 UTC 2012 i686 i686 i386 GNU/Linux

安装ruby和jekyll

没有gem就安装。

调整为taobao源

$ gem sources --remove https://rubygems.org/
$ gem sources --remove http://rubygems.org/
$ gem sources -a https://ruby.taobao.org/
$ gem sources -l
\*** CURRENT SOURCES ***

https://ruby.taobao.org
# 请确保只有 ruby.taobao.org

安装rvm和ruby:

$ sudo apt-get install curl
$ sudo gem install rvm
$ \curl -sSL https://get.rvm.io | bash
$ source /home/user/.rvm/scripts/rvm
$ rvm install ruby-2.1.2
$ rvm use ruby-2.1.2

安装js runtime:

$ sudo apt-get install nodejs
$ gem install execjs

安装jekyll:

$ gem install jekyll

备注: 由于apt-get安装的软件可能版本相对较老,因此推荐用rvm安装ruby。

可能遇到的一些问题

ERROR: Failed to build gem native extension

错误情况:

$ sudo gem install jekyll
Fetching: liquid-2.6.1.gem (100%)
Fetching: kramdown-1.4.1.gem (100%)
Fetching: mercenary-0.3.4.gem (100%)
Fetching: safe_yaml-1.0.3.gem (100%)
Fetching: colorator-0.1.gem (100%)
Fetching: yajl-ruby-1.1.0.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing jekyll:
        ERROR: Failed to build gem native extension.

        /usr/bin/ruby1.9.1 extconf.rb
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
        from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from extconf.rb:1:in `<main>'


Gem files will remain installed in /var/lib/gems/1.9.1/gems/yajl-ruby-1.1.0 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/yajl-ruby-1.1.0/ext/yajl/gem_make.out

原因: ruby版本过老,apt-get install ruby的版本一般是1.8,请使用rvm安装2.1版本的ruby;哪些最新可用版本请用rvm list known查看。

Could not find a JavaScript runtime

错误情况:

$ jekyll new myblog
/home/user/.rvm/gems/ruby-2.1.2/gems/execjs-2.2.1/lib/execjs/runtimes.rb:51:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
        from /home/user/.rvm/gems/ruby-2.1.2/gems/execjs-2.2.1/lib/execjs.rb:5:in `<module:ExecJS>'
        from /home/user/.rvm/gems/ruby-2.1.2/gems/execjs-2.2.1/lib/execjs.rb:4:in `<top (required)>'
        from /home/user/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /home/user/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /home/user/.rvm/gems/ruby-2.1.2/gems/coffee-script-2.3.0/lib/coffee_script.rb:1:in `<top (required)>'
        from /home/user/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /home/user/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /home/user/.rvm/gems/ruby-2.1.2/gems/coffee-script-2.3.0/lib/coffee-script.rb:1:in `<top (required)>'
        from /home/user/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /home/user/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /home/user/.rvm/gems/ruby-2.1.2/gems/jekyll-coffeescript-1.0.0/lib/jekyll-coffeescript.rb:2:in `<top (required)>'
        from /home/user/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /home/user/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /home/user/.rvm/gems/ruby-2.1.2/gems/jekyll-2.3.0/lib/jekyll/deprecator.rb:46:in `block in gracefully_require'
        from /home/user/.rvm/gems/ruby-2.1.2/gems/jekyll-2.3.0/lib/jekyll/deprecator.rb:44:in `each'
        from /home/user/.rvm/gems/ruby-2.1.2/gems/jekyll-2.3.0/lib/jekyll/deprecator.rb:44:in `gracefully_require'
        from /home/user/.rvm/gems/ruby-2.1.2/gems/jekyll-2.3.0/lib/jekyll.rb:141:in `<top (required)>'
        from /home/user/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /home/user/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from /home/user/.rvm/gems/ruby-2.1.2/gems/jekyll-2.3.0/bin/jekyll:6:in `<top (required)>'
        from /home/user/.rvm/gems/ruby-2.1.2/bin/jekyll:23:in `load'
        from /home/user/.rvm/gems/ruby-2.1.2/bin/jekyll:23:in `<main>'
        from /home/user/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `eval'
        from /home/user/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `<main>'

错误原因: 未安装相关js库,请安装nodejs和execjs,请参照以上步骤。

注意事项

安装步骤是针对ubuntu 12.04,其他版本的ubuntu可能有最新的ruby,也可能没有,没经过测试,仅作参考。

解决freebsd升级到最新ports遇到的问题

系统环境

uname -a
FreeBSD AN 7.0-RELEASE FreeBSD 7.0-RELEASE #0: Wed Jul 31 16:20:23 CST 2013   amd64

更新系统的ports tree

先su获取root权限:

portsnap fetch
portsnap extract

出错

安装vim:

cd /usr/ports/editors/vim
make install clean

出错:

Unknown modifier 't'

Unknown modifier 't'

Unknown modifier 't'

Unknown modifier 't'

"Makefile", line 137: Malformed conditional (${PYTHON_REL} < 300)
"Makefile", line 142: if-less endif
Unknown modifier 't'

Unknown modifier 't'

Unknown modifier 't'

Unknown modifier 't'

Unknown modifier 't'

"/usr/ports/Mk/bsd.sites.mk", line 953: Malformed conditional (!empty(_PERL_CPAN_ID) && ${_PERL_CPAN_FLAG:tl} == "cpan")
Unknown modifier 't'

Unknown modifier 't'

Unknown modifier 't'

Unknown modifier 't'

"/usr/ports/Mk/bsd.port.mk", line 2877: Unclosed conditional/for loop
"/usr/ports/Mk/bsd.port.mk", line 2877: Unexpected end of file in for loop.

"/usr/ports/Mk/bsd.port.mk", line 6590: Unclosed conditional/for loop
"/usr/ports/Mk/bsd.port.mk", line 6590: Unexpected end of file in for loop.

1 open conditional:
         at line 1177 (evaluated to true)
make: fatal errors encountered -- cannot continue

谷歌查了一下,原因是7.0这个release不是一个正在维护的版本了,更新后的ports tree和当前的版本不兼容。

解决办法

  • 升级当前系统到最新版本
  • 重新恢复port tree到当前对应版本

stackoverflow的一篇帖子给了我灵感,到freebsd的找到了ports tree的官方备份网站找到了压缩包,恢复之: 用root用户下载install.sh和ports.tgz到/root文件夹,执行脚本解压

sh ./install.sh

FreeBSD源代码安装tsung

我之前的一篇文章《FreeBSD安装tsung》介绍过在FreeBSD下用ports安装erlang和tsung,但是FreeBSD里面的软件太古老,很难安装成功,特别是安装java遇到很大的挫折,之后又尝试源代码安装erlang和tsung,发现一般情况下可以去掉java选项,可以使安装过程变得简单很多。

1.OS版本

64位的Freebsd,uname -a命令:

FreeBSD AN 7.0-RELEASE FreeBSD 7.0-RELEASE #2: Fri Apr 11 10:34:32 CST 2014   amd64

2.安装gmake

需要root权限:

cd /usr/ports/devel/gmake/
make install clean

2.安装erlang

版本:otp-src-R16B03.tar.gz,“gmake install”需要root权限:

tar zxvf otp_src_R16B03.tar.gz
cd otp_src_R16B03 && ./configure --without-javac && gmake && gmake install

3.安装tsung

版本:tsung-1.5.0.tar.gz,“gmake install”需要root权限:

tar zxvf tsung-1.5.0.tar.gz
cd tsung-1.5.0 && ./configure && gmake && gmake install

4.参考文献

总结升级ubuntu和debian遇到的一些错误及解决办法

如没有特别说明,以下操作均需要root权限。

mysql: symbol lookup error

cd /usr/local/lib
mkdir temp
mv /usr/local/lib/libreadline* temp
ldconfig
apt-get update

The following signatures couldn’t be verified because the public key is not available

apt-get update的时候,有时候会出现公钥错误,比如:

W: GPG error: http://ppa.launchpad.net precise Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 2EA8F35793D8809A

或者:

W: There is no public key available for the following key IDs:
8B48AD6246925553

解决办法:安装keyring,往ubuntu server添加公钥信息.

sudo apt-get install debian-keyring debian-archive-keyring && sudo apt-key update
sudo apt-key adv --recv-key --keyserver keyserver.ubuntu.com 8B48AD6246925553

注意第二条命令中的key ID替换成你的key ID.

升级ubuntu从11.10到12.04,网络出现异常

错误描述:无法打开网络配置工具,开机启动出现如下:

Waiting up to 60 more seconds for network configuration...

解决办法:确保你的文件”/etc/network/interfaces”只有如下两行:

auto lo
iface lo inet loopback

有多余的请删除,然后重新启动。

debian安装goagent

debian 版本:Debian GNU/Linux 7 按照官方网站的ubuntu的安装步骤安装所需软件,因为debian里面的包比较古老,因此推荐从源代码安装或者从github安装最新的软件版本。我在运行proxy.py的时候就出现如下问题:

Traceback (most recent call last):
  File "proxy.py", line 1341, in <module>
    http_util = HTTPUtil(max_window=common.GOOGLE_WINDOW, ssl_validate=common.GAE_VALIDATE or common.PAAS_VALIDATE, ssl_obfuscate=common.GAE_OBFUSCATE, proxy=common.proxy)
  File "proxy.py", line 810, in __init__
    self.ssl_context = OpenSSL.SSL.Context(OpenSSL.SSL.TLSv1_METHOD)
AttributeError: 'NoneType' object has no attribute 'SSL'

原因是debian的pyopenssl包比较老,推荐用python的包管理器安装:

sudo apt-get install python-pip
sudo pip install pyOpenSSL

bitbucket SSH快速入门指南

1.基本思路

生成私钥和公钥,把公钥的内容贴到bitbucket的账户选项设置那里,然后ssh-agent加载本地私钥。

2.linux下的步骤

2.1 生成密钥

ssh-keygen
ssh-agent /bin/bash
ssh-add ~/.ssh/id_rsa

然后ssh-add -l查看一下ssh-agent是否成功加载私钥,例如:

$ ssh-add -l
2048 7a:9c:b2:9c:8e:4e:f4:af:de:70:77:b9:52:fd:44:97 /Users/manthony/.ssh/id_rsa (RSA)

2.2 把公钥贴到账户ssh key那里

点击你的头像 -> “Account settings -> SSH keys.”把 “~/.ssh/idrsa.pub”内容复制到key那里,如下图: http://pic.yupoo.com/zhongyijun/CP6dT7kL/cKvj.jpg

对于windows,用git bash,类似,请参考以下官方网站的链接。

3.可能会出现的问题

Permission denied (publickey).
fatal: The remote end hung up unexpectedly

一般原因是因为ssh-agent没有成功加载你的私钥。

FreeBSD安装tsung

1.OS版本

FreeBSD AN 7.0-RELEASE FreeBSD 7.0-RELEASE #0: Wed Dec 12 23:19:45 CST 2012

2.tsung的一些依赖关系

  • Erlang/OTP R12B-5 and up (http://www.erlang.org/download.html). Erlang is now part of fedora and debian/ubuntu repositories.
  • pgsql module made by Christian Sunesson (for the PostgreSQL plugin): sources available at http://jungerl.sourceforge.net/ . The module is included in the source and binary distribution of Tsung. It is released under the EPL License.
  • mysql module made by Magnus Ahltorp & Fredrik Thulin (for the mysql plugin): sources available at http://www.stacken.kth.se/projekt/yxa/ . The modified module is included in the source and binary distribution of Tsung. It is released under the three-clause BSD License.
  • eldap module (for the LDAP plugin): sources available at http://jungerl.sourceforge.net/ . The module is included in the source and binary distribution of Tsung. It is released under the GPL License.
  • mochiweb libs (for xpath parsing, optionally used for dynamic variables in the HTTP plugin): sources available at http://code.google.com/p/mochiweb/ . The module is included in the source and binary distribution of Tsung. It is released under the MIT License.
  • gnuplot and perl5 (optional; for graphical output with tsungstats.pl script). The Template Toolkit is used for HTML reports (see http://template-toolkit.org/)
  • python and mathplotlib (optional; for graphical output with tsung-plotter).

for distributed tests, you need an ssh access to remote machines without password (use a RSA/DSA key without pass-phrase or ssh-agent) (rsh is also supported)

  • bash

一般情况下,我们只需要安装erlang,Freebsd默认没有java解释器,所以需要安装java解析器还有erlang.

3.FreeBSD安装java

有开源的java解决方案,也有oracle的官方版本,详情请看: http://www.freebsd.org/java/ http://www.freebsd.org/java/install.html

这里使用开源的openjdk:

cd /usr/ports/java/openjdk6 
make install clean

4.安装tsung

获得tsung,不需要最新的,用官方推荐的R12B版本就行:

wget http://www.erlang.org/download/otp_src_R12B-5.tar.gz
tar zxvf otp_src_R12B-5.tar.gz
cd cd otp_src_R12B
./configure && make && make install

5.可能会出现的问题

5.1 无法找到java解释器

*********************************************************************
------------------  APPLICATIONS DISABLED  **********************
*******************************************************************

jinterface     : No Java compiler found
odbc           : ODBC library - link check failed

*********************************************************************

需要按照步骤3安装java解释器

5.2 安装openssl出错

bss_dgram.c: In function 'dgram_sctp_handle_auth_free_key_event':
bss_dgram.c:962: error: 'SCTP_AUTH_FREE_KEY' undeclared (first use in this function)
bss_dgram.c:962: error: (Each undeclared identifier is reported only once
bss_dgram.c:962: error: for each function it appears in.)
bss_dgram.c: In function 'dgram_sctp_read':
bss_dgram.c:1053: error: 'SCTP_SENDER_DRY_EVENT' undeclared (first use in this function)
bss_dgram.c:1085: error: 'struct sctp_event_subscribe' has no member named 'sctp_sender_dry_event'
bss_dgram.c: In function 'BIO_dgram_sctp_wait_for_dry':
bss_dgram.c:1544: error: 'struct sctp_event_subscribe' has no member named 'sctp_sender_dry_event'
bss_dgram.c:1595: error: 'SCTP_SENDER_DRY_EVENT' undeclared (first use in this function)
bss_dgram.c:1612: error: 'struct sctp_event_subscribe' has no member named 'sctp_sender_dry_event'
--- Error code 1

Stop in /usr/ports/security/openssl/work/openssl-1.0.1c/crypto/bio.

make -DBATCH install clean
--- Error code 1

Stop in /usr/ports/security/openssl/work/openssl-1.0.1c/crypto.
--- Error code 1

Stop in /usr/ports/security/openssl/work/openssl-1.0.1c.
--- Error code 1

Stop in /usr/ports/security/openssl.
--- Error code 1

Stop in /usr/ports/security/openssl.

去掉STCP的选项:

cd /usr/ports/security/openssl
make config

去掉 []SCTP SCTP protocol support,然后:

make clean
make instal clean

5.3 很多已经安装,需要更新

出错信息类似:

tall'' to upgrade it properly.
      If you really wish to overwrite the old port of devel/libcheck
      without deleting it first, set the variable "FORCE_PKG_REGISTER"
      in your environment or the "make install" command line.
--- Error code 1

安装的时候加入选项FORCEPKGREGISTER=”yes”

make FORCE_PKG_REGISTER="yes" install clean

安装过程可能还会缺少很多软件,很可能需要手工安装。顺便发一下牢骚,freebsd的ports系统真没有gentoo好用。

6.参考文献

这里还教你如何使用tsung

解决vmware里面的xorg窗口管理器无法全屏的问题

最近正在用debian折腾各种窗口管理器,包括awesome,fluxbox,期间发现并解决了一个虚拟机里运行xorg无法全屏的问题。 环境: (1)OS: Debian GNU/Linux 6.0 \n \l Linux debian 2.6.32-5-686 #1 SMP Wed Jan 12 04:01:41 UTC 2011 i686 GNU/Linux 运行于vmware虚拟机里面;刚开始安装的是GNOME桌面环境,vmware-tools也已经安装好,GNOME下使用一切正常,没有什么大问题,包括全屏,和宿主机器之间复制,粘贴什么的;该系统用的是现成的vmware镜像文件,下载地址:http://www.trendsigma.net/vmware/debian6t.html

(2)vmware版本: 6.5.2 build-156735

由于系统太慢,跑这种大型的桌面环境太费劲,所以想着更换一些轻便的桌面环境或者窗口管理器,诸如openbox,blackbox,fluxbox,awesome等等都是很不错的选择;但是安装进入之后,在vmware里面无法全屏,即使vmware-tools已经正确安装。上网google半天,终于找到解决办法:基本思路就是自己生成xorg.conf文件,然后进行一些简单配置;以下是步骤。

1.进入console终端模式,也就是字符界面

如果用的是GNOME,按照网上说的方法,说是Ctrl + Alt + F2就能进入,但是我试了好几次都无法进入字符界面,所以我用的是另一种方法:删除/etc/X11/default-display-manager里面的/usr/sbin/gdm3,也就是登录的时候不要启动登录管理器gdm,这样启动之后就会自动进入字符界面了。

2.生成xorg.conf文件

这一步确保你已经安装好xorg;然后执行下列操作:

su #切换到root用户
Xorg -configure
cp /root/xorg.conf.new /etc/X11/xorg.conf

3.配置你的xorg.conf

两个地方,很重要:

Section "Monitor"
...
EndSection

Section "Screen"
...
EndSection

Monitor那里要加入HorizSync和VertRefresh属性,Screen那里要调整分辨率,下面是我的配置:

Section "Monitor"
        Identifier   "Monitor0"
        VendorName   "Monitor Vendor"
        ModelName    "Monitor Model"
        HorizSync 1.0 - 10000.0
        VertRefresh 1.0 - 10000.0
EndSection

Section "Screen"
        Identifier "Screen0"
        Device     "Card0"
        Monitor    "Monitor0"
        DefaultDepth 24
        SubSection "Display"
                Viewport   0 0
                Depth     24
                Modes   "1440x900"
        EndSubSection
EndSection

换成你显示器的分辨率就行了重新startx就可以了。理论上,不管你用什么窗口管理器,安装vmware-tools之后按键”Ctrl + Alt + Enter”都能进入全屏模式。

最后贴上我的xorg.conf文件,仅供参考:

Section "ServerLayout"
        Identifier     "X.org Configured"
        Screen      0  "Screen0" 0 0
        InputDevice    "Mouse0" "CorePointer"
        InputDevice    "Keyboard0" "CoreKeyboard"
EndSection

Section "Files"
        ModulePath   "/usr/lib/xorg/modules"
        FontPath     "/usr/share/fonts/X11/misc"
        FontPath     "/usr/share/fonts/X11/cyrillic"
        FontPath     "/usr/share/fonts/X11/100dpi/:unscaled"
        FontPath     "/usr/share/fonts/X11/75dpi/:unscaled"
        FontPath     "/usr/share/fonts/X11/Type1"
        FontPath     "/usr/share/fonts/X11/100dpi"
        FontPath     "/usr/share/fonts/X11/75dpi"
        FontPath     "/var/lib/defoma/x-ttcidfont-conf.d/dirs/TrueType"
        FontPath     "built-ins"
EndSection

Section "Module"
        Load  "extmod"
        Load  "glx"
        Load  "record"
        Load  "dbe"
        Load  "dri2"
        Load  "dri"
EndSection

Section "InputDevice"
        Identifier  "Keyboard0"
        Driver      "kbd"
EndSection

Section "InputDevice"
        Identifier  "Mouse0"
        Driver      "mouse"
        Option      "Protocol" "auto"
        Option      "Device" "/dev/input/mice"
        Option      "ZAxisMapping" "4 5 6 7"
EndSection

Section "Monitor"
        Identifier   "Monitor0"
        VendorName   "Monitor Vendor"
        ModelName    "Monitor Model"
        HorizSync 1.0 - 10000.0
        VertRefresh 1.0 - 10000.0
EndSection

Section "Device"
        ### Available Driver options are:-
        ### Values: <i>: integer, <f>: float, <bool>: "True"/"False",
        ### <string>: "String", <freq>: "<f> Hz/kHz/MHz"
        ### [arg]: arg optional
        #Option     "HWcursor"                  # [<bool>]
        #Option     "Xinerama"                  # [<bool>]
        #Option     "StaticXinerama"            # <str>
        #Option     "AddDefaultMode"            # [<bool>]
        Identifier  "Card0"
        Driver      "vmwlegacy"
        VendorName  "VMware"
        BoardName   "SVGA II Adapter"
        BusID       "PCI:0:15:0"
EndSection

Section "Screen"
        Identifier "Screen0"
        Device     "Card0"
        Monitor    "Monitor0"
        DefaultDepth 24
        SubSection "Display"
                Viewport   0 0
                Depth     24
                Modes   "1440x900"
        EndSubSection
EndSection

参考文献

Page 1 of 812345...Last »