分类 【操作系统】 下的文章

解决insserv: warning: script '服务名' missing LSB tags and overrides的问题

编写了一个tomcat开机自启动脚本,执行没问题,但是在安装mysql的时候出现了大量的:

insserv: warning: script 'S20tomcat' missing LSB tags and overrides
insserv: warning: script 'tomcat' missing LSB tags and overrides
insserv: There is a loop at service rmnologin if started
insserv: There is a loop between service rmnologin and mountnfs if started
insserv:  loop involving service mountnfs at depth 6
insserv:  loop involving service networking at depth 5
insserv: There is a loop between service tomcat and hwclock if started
insserv:  loop involving service hwclock at depth 3
insserv:  loop involving service mountdevsubfs at depth 2
insserv: There is a loop between service tomcat and udev if started
insserv:  loop involving service udev at depth 1
insserv: Starting tomcat depends on rmnologin and therefore on system facility `$all' which can not be true!
insserv: Starting tomcat depends on rmnologin and therefore on system facility `$all' which can not be true!
insserv: Starting tomcat depends on rmnologin and therefore on system facility `$all' which can not be true!
insserv: Starting tomcat depends on rmnologin and therefore on system facility `$all' which can not be true!
insserv: Starting tomcat depends on rmnologin and therefore on system facility `$all' which can not be true!
insserv: Starting tomcat depends on rmnologin and therefore on system facility `$all' which can not be true!
insserv: Starting tomcat depends on rmnologin and therefore on system facility `$all' which can not be true!
insserv: Starting tomcat depends on rmnologin and therefore on system facility `$all' which can not be true!
insserv: Starting tomcat depends on rmnologin and therefore on system facility `$all' which can not be true!
insserv: Starting tomcat depends on rmnologin and therefore on system facility `$all' which can not be true!
insserv: Starting tomcat depends on rmnologin and therefore on system facility `$all' which can not be true!

居然还导致mysql安装后的自动配置提示失败,按照LSB tags规范改写脚本如下(debian8环境):

#!/bin/bash
### BEGIN INIT INFO
# Provides:          bbzhh.com
# Required-Start:    $local_fs $network
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: tomcat service
# Description:       tomcat service daemon
### END INIT INFO
#
# description: Apache Tomcat init script
# processname: tomcat
# chkconfig: 234 20 80
#
#
# Copyright (C) 2014 Miglen Evlogiev
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Initially forked from: gist.github.com/valotas/1000094
# Source: gist.github.com/miglen/5590986


#Location of JAVA_HOME (bin files)
export JAVA_HOME=/opt/jdk

#Add Java binary files to PATH
export PATH=$JAVA_HOME/bin:$PATH

#CATALINA_HOME is the location of the bin files of Tomcat
export CATALINA_HOME=/opt/tomcat

#CATALINA_BASE is the location of the configuration files of this instance of Tomcat
export CATALINA_BASE=/opt/tomcat
export CATALINA_BOOTSTRAP=/opt/tomcat/bin/bootstrap.jar

#TOMCAT_USER is the default user of tomcat
export TOMCAT_USER=tomcat

#TOMCAT_USAGE is the message if this script is called without any options
TOMCAT_USAGE="Usage: $0 {\e[00;32mstart\e[00m|\e[00;31mstop\e[00m|\e[00;31mkill\e[00m|\e[00;32mstatus\e[00m|\e[00;31mrestart\e[00m}"

#SHUTDOWN_WAIT is wait time in seconds for java proccess to stop
SHUTDOWN_WAIT=20

tomcat_pid() {
        echo `ps -fe | grep $CATALINA_BOOTSTRAP | grep -v grep | tr -s " "|cut -d" " -f2`
}

start() {
  pid=$(tomcat_pid)
  if [ -n "$pid" ]
  then
    echo -e "\e[00;31mTomcat is already running (pid: $pid)\e[00m"
  else
    # Start tomcat
    echo -e "\e[00;32mStarting tomcat\e[00m"
    #ulimit -n 100000
    #umask 007
    #/bin/su -p -s /bin/sh $TOMCAT_USER
        if [ `user_exists $TOMCAT_USER` = "1" ]
        then
                /bin/su $TOMCAT_USER -c $CATALINA_HOME/bin/startup.sh
        else
                echo -e "\e[00;31mTomcat user $TOMCAT_USER does not exists. Starting with $(id)\e[00m"
                sh $CATALINA_HOME/bin/startup.sh
        fi
        status
  fi
  return 0
}

status(){
          pid=$(tomcat_pid)
          if [ -n "$pid" ]
            then echo -e "\e[00;32mTomcat is running with pid: $pid\e[00m"
          else
            echo -e "\e[00;31mTomcat is not running\e[00m"
            return 3
          fi
}

terminate() {
        echo -e "\e[00;31mTerminating Tomcat\e[00m"
        kill -9 $(tomcat_pid)
}

stop() {
  pid=$(tomcat_pid)
  if [ -n "$pid" ]
  then
    echo -e "\e[00;31mStoping Tomcat\e[00m"
    #/bin/su -p -s /bin/sh $TOMCAT_USER
        sh $CATALINA_HOME/bin/shutdown.sh

    let kwait=$SHUTDOWN_WAIT
    count=0;
    until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ]
    do
      echo -n -e "\n\e[00;31mwaiting for processes to exit\e[00m";
      sleep 1
      let count=$count+1;
    done

    if [ $count -gt $kwait ]; then
      echo -n -e "\n\e[00;31mkilling processes didn't stop after $SHUTDOWN_WAIT seconds\e[00m"
      terminate
    fi
  else
    echo -e "\e[00;31mTomcat is not running\e[00m"
  fi

  return 0
}

user_exists(){
        if id -u $1 >/dev/null 2>&1; then
        echo "1"
        else
                echo "0"
        fi
}

case $1 in
        start)
          start
        ;;
        stop)
          stop
        ;;
        restart)
          stop
          start
        ;;
        status)
                status
                exit $?
        ;;
        kill)
                terminate
        ;;
        *)
                echo -e $TOMCAT_USAGE
        ;;
esac
exit 0
                                                                                                      

其实解决办法就是在#!/bin/bash下面添加:

### BEGIN INIT INFO
# Provides:          bbzhh.com
# Required-Start:    $local_fs $network
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: tomcat service
# Description:       tomcat service daemon
### END INIT INFO

当然,也可以一劳永逸的:

apt-get remove insserv

解决 golang在macos编译时fatal error: MSpanList_Insert错误

mac自从抹盘安装macOS Sierra (version 10.12)之后,就一直没有安装golang环境,这几天想写一个运维小工具,思来想去还是golang最合适,编译后的体积虽然大了一些,但是胜在完全不依赖任何环境、任何第三方库,于是开始了golang环境的折腾。
按照以往惯例,安装golang 1.5+以上版本的时候,如果需要解决交叉编译环境的问题时,需要安装golang1.4.x,于是轻车熟路的先brew安装了gvm,然后gvm install go1.4.3,再然后设置$GOROOT_BOOTSTRAP环境变量为go1.4.3的安装路径,再来gvm install go1.7.3,报错如下:

failed MSpanList_Insert 0x905000 0x9b51f3c97b8 0x0 0x0
fatal error: MSpanList_Insert
runtime stack:
runtime.throw(0x5e5cf0, 0x10)
    /home/travis/.gimme/versions/go1.6.linux.amd64/src/runtime/panic.go:530 +0x90 fp=0x7fff5fbff0b0 sp=0x7fff5fbff098
runtime.(*mSpanList).insert(0x865d08, 0x905000)
    /home/travis/.gimme/versions/go1.6.linux.amd64/src/runtime/mheap.go:933 +0x293 fp=0x7fff5fbff0e0 sp=0x7fff5fbff0b0
runtime.(*mheap).freeSpanLocked(0x865500, 0x905000, 0x100, 0x0)
    /home/travis/.gimme/versions/go1.6.linux.amd64/src/runtime/mheap.go:809 +0x4be fp=0x7fff5fbff148 sp=0x7fff5fbff0e0
runtime.(*mheap).grow(0x865500, 0x8, 0x0)
以下省略……

网上找了一坨坨的解决方案,都说重新安装golang1.7云云
最后,抱着试一试的态度,从golang官方下载了go1.7.3的pkg包,安装后,将$GOROOT_BOOTSTRAP指向了go1.7.3的安装目录(/usr/local/go),问题解决

Linux下使用shell脚本执行需要交互的命令

有些命令或者安装程序在执行时是需要有交互的,比如选择安装路径、选择Y/N等等,如果想用shell脚本中执行该命令,而命令又没有提供默认执行/安装参数时,可以先安装expect,然后按照以下的范例编写:

#!/usr/bin/expect
#spawn sh fncbins.run.LINUX.20160927191846.bin
spawn bash -c "sh fncbins*"
#expect "*"
#send " fncb*.bin\n"
expect "请输入操作系统类型(AIX/HPUX/LINUX),直接回车默认(LINUX):"
send "LINUX\n"
expect "请输入数据库类型(ORACLE/DB2/INFORMIX/PGSQL/MYSQL),直接回车默认(ORACLE):"
send "ORACLE\n"
expect "请输入中间件类型(TUXEDO/FNCBTCP/CICS/MQ),直接回车默认(TUXEDO):"
send "TUXEDO\n"
expect "请输入运行环境类型(开发环境/测试环境/生产环境):(DEV/TST/PRO),直接回车默认(DEV):"
send "DEV\n"
expect "开始安装(Y/N),默认(N)"
send "Y\n"
expect "修改对应的环境变量后,请重新登录用户、启动系统、测试使用"
send "\n"
expect eof
exit

请注意expect后要加上期望匹配的回显

找回Mac 10.12(Sierra)允许“任何来源” 的应用

有不少用户在安装了 macOS Sierra之后发现,系统偏好设置的“安全与隐私”中默认已经去除了允许“任何来源”App 的选项。如果需要恢复允许“任何来源”的选项,即关闭 Gatekeeper(一些从互联网下载和安装的 app 可能对 Mac 产生不利影响,Gatekeeper 帮助保护 Mac 免受此类 app 的影响。),我们可以在终端中使用 spctl 命令来实现:

sudo spctl --master-disable

输入上述命令之后,我们可以发现,久违的“任何来源”回来了

在ubuntu上制作openstack虚拟机centos6.5自定义镜像

基础环境信息:
客户端:ubuntu 16.04.01 LTS
服务器:openstack L版

第一步,确认硬件
KVM需要CPU硬件支持虚拟化,所以首先要确认你的CPU支持:

$ egrep -o '(vmx|svm)' /proc/cpuinfo

如果有输出回显,则代表CPU支持虚拟化

第二步,更新并安装ubuntu的kvm支持:

$ sudo apt-get update && sudo apt-get dist-upgrade -y
$ sudo apt-get install  qemu-kvm qemu-system libvirt-bin bridge-utils virt-manager virtinst virt-viewer

第三步,检查 libvirt 默认网络是否运行
运行

virsh net-list 

查看是否有active的记录,如果不存在,则使用

# virsh net-start default

添加默认记录后,再次查看是否有active的记录

第四步,创建空白镜像:

# qemu-img create -f qcow2 /tmp/centos-6.5.qcow2 10G

这里需要解释一下,最后两个参数:
/tmp/centos-6.5.qcow2:表示生成的空白镜像所在的路径
10G:是指空白镜像文件的大小,也就是以后我们虚拟机默认的初始化磁盘空间

第五步,创建kvm虚拟机,并且挂载镜像:

# virt-install --virt-type kvm --name centos-6.5-64bit --ram 1024 \
--disk /tmp/centos-6.5.qcow2,format=qcow2 \
--network network=default \
--graphics vnc,listen=0.0.0.0 --noautoconsole \
--os-type=linux --os-variant=rhel6 \
--extra-args="console=tty0 console=ttyS0,115200n8 serial" \
--location=/data/isos/CentOS-6.5-x86_64-netinstall.iso

可变参数解释:
--name:虚拟机的名称,这里要记住,下面还会用到
--ram:虚拟机的内存大小,这只是安装时使用,和之后的打包成镜像后的运行时参数无关
--disk:第四步中创建的空白虚拟机磁盘文件路径
--os-type:操作系统类型
--os-variant:操作系统标识,可以根据实际情况修改
--location:安装镜像,即需要挂载的安装光盘

第六步,虚拟机操作系统安装,过程略

第七步,安装虚拟机内部必要组件,并关机
使用

virsh dumpxml 虚拟机名称 (在本例中,为centos-6.5-64bit)

命令查看挂载的CD-ROM,并使用

# virsh attach-disk --type cdrom --mode readonly 虚拟机名称 "" 设备名(比如hdc,根据virsh dumpxml命令实际返回结果来修改)
# virsh destroy 虚拟机名称
# virsh start 虚拟机名称

卸载

# yum install acpid
# chkconfig acpid on
# yum install http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
安装必要的第三方软件,比如htop等
# echo "NOZEROCONF=yes" >> /etc/sysconfig/network   (非必要,配合cloud-init使用)
# /sbin/shutdown -h now

第八步, 清理(删除 MAC 地址相关信息):

# virt-sysprep -d 虚拟机名称

第九步,qcow2减肥,并上传至openstack控制节点:

# qemu-img convert -c -O qcow2 centos6.5-64bit.qcow2 /home/tan9le/centos65-64bit.qcow2

centos6.5-64bit.qcow2 为原始镜像
/home/tan9le/centos65-64bit.qcow2 为压缩后的镜像

第十步,导入glance镜像(openstack控制节点操作)

source admin-opensrc    #导入openstack的admin权限变量
glance image-create --name "centos65-64bit" --file /images/centos65-64bit.qcow2  --disk-format qcow2 --container-format bare --visibility public --progress

--name 镜像名称,在openstack平台上可以显示
--file 第九步中上传的qcow2镜像路径