标签归档:ubuntu

ubuntu中创建程序为自启动

#!/bin/bash
### BEGIN INIT INFO
# Provides:          appname
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: appinfo
# Description:       appinfo
### END INIT INFO

bin="/home/user/app"

start(){
  ps -ef | grep $bin | grep -v grep > /dev/null
  if [ $? -eq 0 ]; then
    echo "The Service has started."
  else
    echo -n "Starting..."
    $bin 1>/dev/null 2>/dev/null &
    echo "Done!"
  fi
}

stop(){
  ps -ef | grep $bin | grep -v grep > /dev/null
  if [ $? -eq 0 ]; then
    echo -n "Stoping..."
    killall $bin
    echo "Done!"
  else
    echo "The service did not start."
  fi
}

case $1 in
start)
  start
;;
stop)
  stop
;;
status)
  ps -ef | grep $bin | grep -v grep > /dev/null
  if [ $? -eq 0 ]; then
    echo "The service is running."
  else
    echo "The service is not running."
  fi
;;
*)
  echo "Usage: $0 {start|stop|status}"
;;
esac

脚本放在 /etc/init.d/ 目录下,添加 执行 权限。

# 添加到服务
sudo systemctl enable app  # app 是服务文件名
# 启动服务
sudo service app start

继续阅读

ubuntu 中利用 docker 搭建 php + oracle 开发环境

利用 docker 部署 oracle 11g

安装 docker

拉取镜像

docker pull sath89/oracle-xe-11g

创建实例

docker run -d --restart always -p 8080:8080 -p 1521:1521 -v /etc/localtime:/etc/localtime:ro -v /my/oracle/data:/u01/app/oracle sath89/oracle-xe-11g

<!–more–>

时间同步的参数详见: <http://jerry.red/453/docker-容器与宿主机时间不同步的解决办法>

连接信息

Connect database with following setting:

hostname: localhost
port: 1521
sid: xe
username: system
password: oracle
Password for SYS & SYSTEM:
oracle

Connect to Oracle Application Express web management console with following settings:

http://localhost:8080/apex
workspace: INTERNAL
user: ADMIN
password: oracle

镜像详情:<https://hub.docker.com/r/sath89/oracle-xe-11g/>,利用 daocloud.io 可加速拉取镜像。


安装 Oracle Instant Client

Install RPMs

  1. Download the Oracle Instantclient RPM files from http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html. Everyone needs either "Basic" or "Basic lite", and most users will want "SQL*Plus" and the "SDK".

  2. Convert these .rpm files into .deb packages and install using "alien" ("sudo apt-get install alien" if you don’t have it).

  3. For example, for version 12.1.0.2.0-1 for Linux x86_64 (64-bit):

alien -i oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm
alien -i oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.x86_64.rpm
alien -i oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm
  1. Test your Instantclient install by using "sqlplus" or "sqlplus64" to connect to your database:
sqlplus system/oracle@//localhost:1521/xe

If you execute sqlplus and get "sqlplus: command not found", see the section below about adding the ORACLE_HOME variable.

If sqlplus complains of a missing libsqlplus.so file, follow the steps in the section "Integrate Oracle Libraries" below.

If sqlplus complains of a missing libaio.so.1 file, run

sudo apt-get install libaio1

or, if you’re installing the 32 bit instant client on 64 bit,

sudo apt-get install libaio1:i386

Integrate Oracle Libraries

If oracle applications, such as sqlplus, are complaining about missing libraries, you can add it to the system library list create a new file as follows:

sudo vi /etc/ld.so.conf.d/oracle.conf && sudo chmod o+r /etc/ld.so.conf.d/oracle.conf

and add the oracle library path as the first line. For example,

/usr/lib/oracle/12.1/client64/lib/

Then run ldconfig:

sudo ldconfig

ORACLE_HOME

Many Oracle database applications look for Oracle software in the location specified in the environment variable ‘ORACLE_HOME’.

Typical workstations will only have one Oracle install, and will want to define this variable in a system-wide location.

sudo vi /etc/profile.d/oracle.sh && sudo chmod o+r /etc/profile.d/oracle.sh

Add the following:

export ORACLE_HOME=/usr/lib/oracle/12.1/client64

Alternatively, each user can define this in their ~/.bash_profile

Note: From Ubuntu 11.04 (confirmed in 11.04 and 14.04) sqlplus was not recognized as a command unless the following line was also included in the oracle.sh file:

export PATH=$PATH:$ORACLE_HOME/bin

更多详情:<https://help.ubuntu.com/community/Oracle%20Instant%20Client>


安装 php 扩展

详见链接