gcc, numpy, rabbitmq等安装升级总结

1. 公司在下面目录安装了gcc-4.8.2,以支持c++11,可以通过在bashrc中添加来实现:

PATH=/opt/compiler/gcc-4.8.2/bin:$PATH

2. 公司环境切换到V2,升级和安装会带来很多方便

切换方式查看:

http://wiki.baidu.com/pages/viewpage.action?pageId=63809112

步骤:

wget  http://dl.noah.baidu.com/soft/centosv2/v2.deploy

以root账号执行以下命令:

sh  v2.deploy deploy
           exit    #退出root#

切换V2环境(所有用户都可以):

执行以下命令,当前用户自动切换到V2环境:

sudo v2 (v是小写的)

在账号的.bashrc文件最后一行添加如下内容:

[ -f /bin/v2 ] && sudo /bin/v2

相关材料:

http://wiki.baidu.com/pages/viewpage.action?pageId=150629888

http://wiki.baidu.com/pages/viewpage.action?pageId=54504744

http://wiki.baidu.com/display/BaiduLinux/V2

【注意】现在work帐号自动进入V2模式,而root帐号仍然是普通模式

如果先进入非V2模式的work,再sudo v2的时候,需要输入密码;

但是直接把sudo v2写在 ~/.bashrc里面,就不需要输入密码了

3. 安装numpy

首先安装jumbo,安装方式:

http://jumbo.baidu.com/

具体步骤:

bash -c "$( curl http://jumbo.baidu.com/install_jumbo.sh )"; source ~/.bashrc

注:据说安装了jumbo之后,直接 jumbo install python-numpy 就可以安装numpy了。

——————————

以下是其他步骤。

然后使用如下步骤:

http://wiki.baidu.com/pages/viewpage.action?pageId=182208081

首先安装python2.7:

jumbo install python

然后在这个目录:

.../installed/git

git clone http://gitlab.baidu.com/liusheng04/numpy.git

1 安装nose

  • python setup.py install

2 安装lapack

  1. cp make.inc.example make.inc
  2. 修改make.inc

FORTRAN = gfortran -m64 -fPIC
OPTS = -O2 -m64 -fPIC
DRVOPTS = $(OPTS)
NOOPT = -O0 -m64 -fPIC
LOADER = gfortran -m64 -fPIC

然后:

make blaslib

make

3 安装ATLAS

解压并且需要创建子目录:

tar jxf atlas3.8.4.tar.bz2 ; mkdir myobj64 ; cd myobj64/

编译配置:

../configure -b 64 -Fa alg -fPIC --prefix=/home/work/atlas --with-netlib-lapack=..../numpy/lapack-3.4.2/liblapack.a

make (这个过程相当漫长,几个小时)

make check (多核: make ptcheck)

make time

make install

编译动态库:

cd lib; make shared; cp *.so /home/work/atlas/lib/

设置环境变量:

LD_LIBRARY_PATH=/home/work/atlas/lib:$LD_LIBRARY_PATH

bash

4. 安装numpy

解压后,cd numpy-1.9.2

cp site.cfg.example site.cfg

修改的地方有:

[DEFAULT]
library_dirs = /usr/local/lib:/home/work/atlas/lib
include_dirs = /usr/local/include:/home/work/atlas/include
[atlas]
atlas_libs = lapack, f77blas, cblas, atlas
library_dirs = /home/work/atlas/lib
include_dirs = /home/work/atlas/include
 
[amd]
amd_libs = amd
#
[umfpack]
umfpack_libs = umfpack

然后运行命令:

python setup.py build --fcompiler=gnu95

python setup.py install

测试:

>>> from numpy import *
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/work/.jumbo/lib/python2.7/site-packages/numpy/__init__.py", line 170, in <module>
    from . import add_newdocs
  File "/home/work/.jumbo/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/home/work/.jumbo/lib/python2.7/site-packages/numpy/lib/__init__.py", line 18, in <module>
    from .polynomial import *
  File "/home/work/.jumbo/lib/python2.7/site-packages/numpy/lib/polynomial.py", line 19, in <module>
    from numpy.linalg import eigvals, lstsq, inv
  File "/home/work/.jumbo/lib/python2.7/site-packages/numpy/linalg/__init__.py", line 51, in <module>
    from .linalg import *
  File "/home/work/.jumbo/lib/python2.7/site-packages/numpy/linalg/linalg.py", line 29, in <module>
    from numpy.linalg import lapack_lite, _umath_linalg
ImportError: liblapack.so: cannot open shared object file: No such file or directory

尝试导入LD_LIBRARY_PATH,或者更改PATH环境变量,都没有用。

最后发现root帐号并没有进入V2模式,将root帐号进入v2模式之后,

cp /home/work/atlas/lib/*so /usr/lib

就可以让python找到这些so了。

重新测试:

$python              
Python 2.7.3 (default, May 22 2016, 13:10:59) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from numpy import *
>>> random.rand(4,4)
array([[ 0.77309727,  0.99562093,  0.56372469,  0.26073266],
       [ 0.43501491,  0.37941785,  0.20861747,  0.71097027],
       [ 0.59923152,  0.16949823,  0.22485638,  0.72099852],
       [ 0.56264422,  0.75829963,  0.57674857,  0.95737122]])

以上,numpy的安装完成。

RabbitMQ

注:在mac机器上,brew install rabbitmq来安装的。

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

以下为其他安装步骤。

4. 安装erlang

下载 http://erlang.org/download/otp_src_18.3.tar.gz

解压到installed/otp_src_18.3

./configure

make

make install

此时root账号已经使用erl

# erl
Eshell V7.3 (abort with ^G)
1>

但是发现work帐号还是不能使用erl,可能还是v2系统造成的

work帐号找不到/usr/bin目录下的文件

所以将erlang重新安装到work可见的目录(installed/erlang)

$erl
Erlang/OTP 18 [erts-7.3] [source] [64-bit] [smp:24:24] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V7.3 (abort with ^G)
1>

4. 安装xmlto

yum install xmlto

5. 安装rabbitmq

(rabbitmq3.6.0安装不了)

解压rabbitmq-server-generic-unix-3.6.0.tar 进入目录:cd rabbitmq_server-3.6.0/

安装rabbitmq-3.5.0

wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.5.0/rabbitmq-server-3.5.0.tar.gz
tar -xvf rabbitmq-server-3.5.0.tar.gz

编译安装

make TARGET_DIR=/xxx/installed/rabbitmqSBIN_DIR=/xxx/installed/rabbitmq/sbin MAN_DIR=/xxx/installed/rabbitmq/man DOC_INSTALL_DIR=/xxx/installed/rabbitmq/doc install

配置

进入安装目录 installed/rabbitmq , mkdir system

vi sbin/rabbitmq-defaults , 设置SYS_PREFIX=刚刚的system目录

cd system/

mkdir -p etc/rabbitmq

启动

进入 sbin, ./rabbitmq-server start 默认端口 5672

集群的创建可以参考 http://wiki.baidu.com/pages/viewpage.action?pageId=53397963

启动之后,在服务器端出现一些error,待查:

Error in log handler
====================
Event: {info_msg,<0.70.0>,
                 {<0.439.0>,"closing AMQP connection ~p (~s)~n",
                  [<0.439.0>,"127.0.0.1:44625 -> 127.0.0.1:5672"]}}
Error: function_clause
Stack trace: [{error_logger_file_h,write_event,
 
停止rabbitmq服务器的命令:./rabbitmqctl stop
 

安装python amqp进行测试。安装及测试步骤如下。

6. 安装pyamqp

下载 https://codeload.github.com/barryp/py-amqplib/zip/master

unzip解压,python setup.py install

测试rabbitmq及pyamqplib

生产者代码及显示:

$python
Python 2.7.3 (default, May 22 2016, 13:10:59)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from amqplib import client_0_8 as amqp
>>> import sys
>>> msglist = ['a', 'c', 'bbb', 'hi']
>>> conn = amqp.Connection(host="localhost:5672", userid="guest", password="guest", virtual_host="/", insist=False)
>>> chan = conn.channel()
>>> for i in msglist:
...     msg = amqp.Message(i)
...     msg.properties["delivery_mode"] = 2 #在消息中将"delivery_mode"设置为2就表示持久化存储, 默认是1, 非持久化
...     chan.basic_publish(msg,exchange="sorting_room",routing_key="jason")
...     import time
...     time.sleep(2)
...
>>> chan.close()
>>> conn.close()

消费者代码及显示:

$python
Python 2.7.3 (default, May 22 2016, 13:10:59)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from amqplib import client_0_8 as amqp
>>> conn = amqp.Connection(host="localhost:5672 ", userid="guest", password="guest", virtual_host="/", insist=False)
>>> conn
<amqplib.client_0_8.connection.Connection object at 0x7ff4e0f23e10>
>>> chan = conn.channel()
>>> chan.queue_declare(queue="po_box", durable=True, exclusive=False, auto_delete=False)
(u'po_box', 0, 0)
>>> chan.exchange_declare(exchange="sorting_room", type="direct", durable=True, auto_delete=False,)
>>> chan.queue_bind(queue="po_box", exchange="sorting_room", routing_key="jason")
>>> def recv_callback(msg):
...     print 'Received: ' + msg.body + ' from channel #' + str(msg.channel.channel_id)
...
>>> chan.basic_consume(queue='po_box', no_ack=True, callback=recv_callback, consumer_tag="testtag")
u'testtag'
>>> while True:
...     chan.wait()
...
Received: a
Received: c
Received: bbb
Received: hi 

KeyboardInterrupt
>>> chan.basic_cancel("testtag")
>>> chan.close()
>>> conn.close()

参考:http://www.cnblogs.com/chengxin1982/p/3820759.html

打开web管理界面,可以在安装目录的sbin目录中,敲入命令:

./rabbitmq-plugins enable rabbitmq_management

原来的默认web端口是15672,但是我们的机器端口只有8000-9000能提供外部web访问,所以修改配置:

在 installed/rabbitmq/system/etc/rabbitmq 这个目录,如果没有rabbitmq.config,创建文件,添加:

{rabbitmq_management, [{listener, [{port, 8696}]}]}

在disable管理界面后,重新enable:

./rabbitmq-plugins disable rabbitmq_management

./rabbitmq-plugins enable rabbitmq_management

发现还是没有生效,推测需要重新server。

启动server, ./rabbitmq-server 报错:

installed/rabbitmq/system/etc/rabbitmq/rabbitmq.config" (none): no ending <dot> found)

原来rabbitmq.config最后要用 . 结束。修改之后,重启。

这次直接erlang报错:

{"init terminating in do_boot",{function_clause,[{proplists,get_value,[kernel,{rabbitmq_management,[{listener,[{port,8696}]}]},[]],[{file,"proplists.erl"},{line,226}]},{rabbit_prelaunch,dist_port_set_check,0,[{file,"src/rabbit_prelaunch.erl"},{line,88}]},{rabbit_prelaunch,start,0,[{file,"src/rabbit_prelaunch.erl"},{line,48}]},{init,start_it,1,[]},{init,start_em,1,[]}]}}

原来配置文件的格式需要是erlang的hash:

[
{rabbitmq_management,[{listener, [{port, 8696}]}]}
].

然后再启动,就可以看到端口了:

$netstat -nap | grep 8696
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 0.0.0.0:8696 0.0.0.0:* LISTEN 7156/beam.smp

访问 x.x.x.x:8696 出现管理端界面。

这时候直接用guest还是登录不上。因为rabbitmq的管理界面禁止非localhost来源的guest访问(http://www.rabbitmq.com/access-control.html)

所以需要添加用户

rabbitmqctl add_user admin 123456

这时候,用admin还是登不上,因为需要增加权限

rabbitmqctl set_user_tags admin administrator

其他的一些配置也可以看看这里:https://www.kakata.com/archives/1190

经过以上步骤,就可以在管理界面 x.x.x.x:8696 使用 admin/123456 来登录了。

以上,rabbitmq的安装大功告成。

gcc, numpy, rabbitmq等安装升级总结

上一篇:Key Lookup开销过大导致聚集索引扫描


下一篇:JAVA进阶之旅(一)——增强for循环,基本数据类型的自动拆箱与装箱,享元设计模式,枚举的概述,枚举的应用,枚举的构造方法,枚举的抽象方法