集成启动服务脚本设计
... 12
总体思路需求
根据计算机系统启动顺序,启动项的优先级设定
1):rabbitMQ 2):mysql 3):redis 4):tomcat
2:对磁盘空间检测结果是否达到一定容量,达到后,就不启动相应程序(如:mysql)
if
执行启动脚本过程中,依照启动项依赖强度,决定后续依赖是否启动(例:mysql不能启动,后续tomcat启动脚本就不执行)
if 集成脚本命名
ramr (rabbit apache mysql redis) 1.rabbtmq安装
1.1 安装Erlang 说明: RabbitMQ是基于Erlang的,所以首先必须配置Erlang环境。
$ tar xvzf otp_src_R14B03.tar.gz
$ cdotp_src_R14B03
$./configure
fop is missing. 可忽略
提示没有wxWidgets和fop,但是问题不大。继续:
$ make
$ sudo make install
***************************************************************************************** 可能出现问题: $ ./configure执行时 问题1:
configure:error: No curses library functions found
configure:error: /bin/sh '/var/rabbit/otp_src_R13B04/erts/configure' failed for erts
解决:yum -y install ncurses-dev 问题2:
*********************************************************************
********************** APPLICATIONS DISABLED **********************
*********************************************************************
crypto : No usable OpenSSL found
odbc : ODBC library - link check failed
orber : No C++ compiler found
ssh : No usable OpenSSL found
ssl : No usable OpenSSL found
解决:
1:ODBC library - link check failed 需要安装 unixODBC
> yum list|grep unixODBC
> yum install unixODBC-devel
2. No usable OpenSSL found 需要安装 openssl
> yum list|grep ssl
> yum install openssl-devel
3. No C++ compiler found: 需要安装gc c++ 编译器
> yum list|grep gcc
> yum install gcc-c++ 安装一个比较新的Python版本
①解压安装文件
$ tar –jxvfPython-2.7.3.tar.bz2
②进入解压后的目录
$ cdPython-2.7.3
③执行安装步骤
$./configure
$ make
$ makeinstall
3. 测试
在命令行下输入python,出现python解释器即表示已经正确安装。 可能出现问题 执行python会发现显示结果为原来的版本信息 问题:1
#python
退出:ctrl+D
Python 2.4.3 (#1, May 5 2011, 16:39:10)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2
Type "help", "copyright", "credits" or "license" for more information. 解决:
Java代码
#cd /usr/bin
#ll |grep python //查看该目录下python
#rm -rf python
#ln -s /usr/local/Python-2.7.3/python ./python //建立对应的软链接
#python
[root@localhost bin]# python
Python 3.3.5 (default, Dec 23 2014, 16:01:57)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] 问题2: 使用yum的时候出现
File"/usr/bin/yum", line 30
except KeyboardInterrupt, e: ^
SyntaxError: invalidsyntax 原因
解决:
修改yum的解释器为旧版本python2.6:
vi/usr/bin/yum
将第一行"#!/usr/bin/python"改为"#!/usr/bin/python2.6"即可
1.3 需要安装simplejson
http://pypi.python.org/pypi/simplejson#downloads
解压
#tar zxvf simplejson-3.6.5.tar.gz
#cd simplejson-3.6.5
#sudo pythonsetup.py install 1.4 安装rabbitMQ
http://www.rabbitmq.com/server.html
下载最新的版本
解压到指定目录
[root@localhostrabbit]# ls
otp_src_R13B04 Python-3.3.5 rabbitmq_server-3.4.2 simplejson-3.6.5
[root@localhostrabbitmq_server-3.4.2]# ls
ebin LICENSE-MIT-eldap
etc LICENSE-MIT-Flot
include LICENSE-MIT-jQuery164
INSTALL LICENSE-MIT-Mochi
LICENSE LICENSE-MIT-Sammy060
LICENSE-APACHE2-ExplorerCanvas LICENSE-MPL-RabbitMQ
LICENSE-Apache-Basho plugins
LICENSE-APL2-Stomp-Websocket sbin
LICENSE-BSD-base64js share
LICENSE-BSD-glMatrix var
LICENSE-MIT-EJS10
此时已经有sbin
sbin下面
[root@localhostsbin]# ls
rabbitmqctl rabbitmq-defaults rabbitmq-env rabbitmq-plugins rabbitmq-server
启动
[root@localhost]#sbin /rabbitmq-server --detached 可能出现问题 question 1 erl:command not found
解决:
如果为了rc.local启动方便,可以将 export PATH=$PATH:/../ bin 这一行写入到 rabbitmq-server 文件中:
question 2 erlexec:HOME must be set
解决 第二行添加
question 3 停止rabbitmq服务运行错误 [root@localhost sbin]# service rabbitmq stop Stoping rabbitmq Server:rabbitmq\n/var/rabbit/rabbitmq_server-3.4.2/sbin/rabbitmqctl: line 24: erl:command not found
解决 同理和1一样在rabbitmctl中添加 question 4服务不支持 chkconfig
解决
#!/bin/bash
# chkconfig: 235 20 80
# description: Saves andrestores system entropy pool for
# higher quality randomnumber generation.
!!注意chkconfig前面的冒号“:” question5:启动系统卡住
5:打开另一个客户端
[root@localhost redis-2.8.3]# src/redis-cli
127.0.0.1:6379> set name chenzhou
OK
127.0.0.1:6379>get name
"chenzhou"
127.0.0.1:6379>exit 启动过程问题
/etc/init.d/redis: line 10: [: too manyarguments
因为环境变量没放在双引号中,所以 bash 认为方括号中的自变量过多。可以用双引号将字符串自变量括起来消除该问题。请记住,如果养成将所有字符串自变量用双引号括起的习惯,将除去很多类似的编程错误。
卡在启动地方
WARNINGovercommit_memory is set to 0! Background save may fail under low memorycondition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.confand then reboot or run the command 'sysctl vm.overcommit_memory=1' for this totake effect