标签归档:linux

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 安装 gnome3

安装之前先添加库并更新,已保证后面的安装顺利。

建议在服务器版安装。utility版可以不安装gdm。

sudo add-apt-repository ppa:gnome3-team/gnome3
sudo add-apt-repository ppa:gnome3-team/gnome3-staging
sudo apt-get update
sudo apt-get dist-upgrade -y
sudo apt-get install gdm gnome-shell gnome-shell-extensions gnome-tweak-tool ubuntu-gnome-desktop

继续阅读

怎么解决linux解压zip出现的乱码

在windows上压缩的文件,是以系统默认编码中文来压缩文件。由于zip文件中没有声明其编码,所以linux上的unzip一般以默认编码解压,中文文件名会出现乱码。
虽然2005年就有人把这报告为bug,但是info-zip的官方网站没有把自动识别编码列入计划,可能他们不认为这是个问题。Sun对java中存在N年的zip编码问题,采用了同样的处理方式。

有2种方式解决问题:

1、 通过unzip行命令解压,指定字符集

unzip -O CP936 xxx.zip //用GBK, GB18030也可以

有趣的是unzip的manual中并无这个选项的说明, unzip –help对这个参数有一行简单的说明。

2、 在环境变量中,指定unzip参数,总是以指定的字符集显示和解压文件
/etc/environment 中加入2行

UNZIP="-O CP936"
ZIPINFO="-O CP936"

或者使用 unar ,例如:

unar xxx.zip

使用 anyexec 在 linux 上运行.NET程序

这是一种不使用 mono-runtime 的特殊方法,ubuntu 控制台程序测试通过,理论上 linux 控制台程序都可以运行,但 GUI 未测试。

1、下载 anyexec(不支持32位)anyexec-1.2-linux_x64.tar
2、解压得到一个目录,改成自己想要的名字,例如叫:myanyexec
3、运行 myanyexec/any ,如果看到如下信息,说明 anyexec 能正常工作:

4、将编译好的 .net 程序整体移动到 myanyexec/app/ 目录下
5、将 myanyexec/any 改名为 .net 主程序名,注意不要含 .exe 后缀
6、运行改名后的最终程序,测试是否可以运行
7、压缩,交付!

继续阅读

linux 安装 mono 开发环境

1 Add the Mono repository to your system

The package repository hosts the packages you need, add it with the following commands.

Ubuntu 18.04

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb https://download.mono-project.com/repo/ubuntu stable-bionic main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list
sudo apt update

Ubuntu 16.04

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb http://download.mono-project.com/repo/ubuntu xenial main" | sudo tee /etc/apt/sources.list.d/mono-official.list
sudo apt-get update

继续阅读

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 扩展

详见链接

linux下安装markdown编辑器Typora

# or run:
# sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys BA300B7755AFCFAE
wget -qO - https://typora.io/linux/public-key.asc | sudo apt-key add -
# add Typora's repository
sudo add-apt-repository 'deb https://typora.io/linux ./'
sudo apt-get update
# install typora
sudo apt-get install typora

继续阅读

RAID5的配置方法

RAID有 0 1 10 5 6 等级别,RAID0 的性能很强,但是万一有一块盘坏了,整个阵列就废了,肯定不能用。RAID1 的安全性最好,读取速度也不错,但浪费空间,四块盘只相当于两块盘的空间。

RAID5 是这么个原理:交替在各个盘上写数据,这么看类似于RAID0,但是每写n-1个盘的数据,剩下的那个盘写的就不是数据,而是校验数据(parity)。这样一来,如果有一块盘坏掉,那么就可以用剩下的盘上的数据来恢复数据。即便你临时无法找到另一块盘来替换坏盘,阵列也能进入降级模式,重要的数据也可以直接读取备份出来。
继续阅读