Скрипт инсталляции для Debian 6 LNMP (Nginx, MySql, PHP-FPM, Memcache)

# aptitude install nano
# nano ~/install-server.sh
# sh ~/install-server.sh
#!/bin/sh
echo -e "## Automatic installation servers apps ##"
 
distrib="squeeze"
 
echo "
deb http://ftp.pl.debian.org/debian stable main contrib
deb-src http://ftp.pl.debian.org/debian stable main contrib
 
deb http://ftp.debian.org/debian/ squeeze-updates main contrib
deb-src http://ftp.debian.org/debian/ squeeze-updates main contrib
 
deb http://security.debian.org/ squeeze/updates main contrib
deb-src http://security.debian.org/ squeeze/updates main contrib
 
# erlyvideo.org
#deb http://debian.erlyvideo.org binary/
 
# php-fpm dotdeb
deb http://packages.dotdeb.org ${distrib} all
deb-src http://packages.dotdeb.org ${distrib} all
 
# nginx
deb http://nginx.org/packages/debian ${distrib} nginx
deb-src http://nginx.org/packages/debian ${distrib} nginx
" > /etc/apt/sources.list
 
wget -q http://www.dotdeb.org/dotdeb.gpg -O- | apt-key add -
wget -q http://nginx.org/keys/nginx_signing.key -O- | apt-key add -
 
echo -e "## Update OS ##"
sleep 1
aptitude update && aptitude upgrade -y
 
echo -e "## Install my app list ##"
sleep 1
aptitude install apt apt-utils chkconfig mc htop git mercurial checkinstall iptraf jnettop iftop -y
aptitude install nano -y
 
echo -e "## Install PHP-FPM ##"
sleep 1
aptitude install php5 php5-dev php5-sqlite php5-mcrypt php5-xsl php5-cli php5-common php5-mysql php5-suhosin php5-gd php5-fpm \
        php5-cgi php-pear php5-apc php5-memcached php5-memcache php5-curl -y
echo "cgi.fix_pathinfo = 0" >> /etc/php5/fpm/php.ini
 
echo -e "## Install Nginx ##"
sleep 1
aptitude install nginx -y
 
echo -e "## Install MySQL ##"
sleep 1
aptitude install mysql-server mysql-client mysql-common -y
chkconfig --levels 235 mysql on
 
echo -e "## Install Memcqached ##"
sleep 1
aptitude install libmysqlclient18 memcached -y
 
echo -e "## Configure Multiple instances of memcached server ##"
echo '#! /bin/bash
### BEGIN INIT INFO
# Provides:  	memcached
# Required-Start:	$remote_fs $syslog
# Required-Stop:	$remote_fs $syslog
# Should-Start:		$local_fs
# Should-Stop:		$local_fs
# Default-Start:	2 3 4 5
# Default-Stop:		0 1 6
# Short-Description:	Start memcached daemon
# Description:		Start up memcached, a high-performance memory caching daemon
### END INIT INFO
 
 
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/memcached
DAEMONNAME=memcached
DAEMONBOOTSTRAP=/usr/share/memcached/scripts/start-memcached
DESC=memcached
 
test -x $DAEMON || exit 0
test -x $DAEMONBOOTSTRAP || exit 0
 
set -e
 
. /lib/lsb/init-functions
 
# Edit /etc/default/memcached to change this.
ENABLE_MEMCACHED=no
test -r /etc/default/memcached && . /etc/default/memcached
 
FILES=(/etc/memcached_*.conf);
# check for alternative config schema
if [ -r "${FILES[0]}" ]; then
    CONFIGS=();
    for FILE in "${FILES[@]}";
    do
	# remove prefix and sufix
	NAME=$(basename "${FILE}" .conf);
 
	# check optional second param
	if [ $# -ne 2 ];
	then
	    # add to config array
	    CONFIGS+=($NAME);
	elif [ "memcached_$2" == "$NAME" ];
	then
	    # use only one memcached
	    CONFIGS=($NAME);
	    break;
	fi;
    done;
 
    if [ ${#CONFIGS[@]} == 0 ];
    then
	echo "Config not exist for: $2" >&2;
	exit 1;
    fi;
else
    CONFIGS=(memcached);
fi;
 
CONFIG_NUM=${#CONFIGS[@]};
for ((i=0; i < $CONFIG_NUM; i++)); do
    NAME=${CONFIGS[${i}]};
    PIDFILE="/var/run/${NAME}.pid";
    case "$1" in
	start)
	    echo -n "Starting $DESC: "
	    if [ $ENABLE_MEMCACHED = yes ]; then
		start-stop-daemon --start --quiet --exec "$DAEMONBOOTSTRAP" -- /etc/${NAME}.conf $PIDFILE
		echo "$NAME."
	    else
		echo "$NAME disabled in /etc/default/memcached."
	    fi
	    ;;
	stop)
	    echo -n "Stopping $DESC: "
	    start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE --exec $DAEMON
	    echo "$NAME."
	    rm -f $PIDFILE
	    ;;
 
	restart|force-reload)
	#
	#	If the "reload" option is implemented, move the "force-reload"
	#	option to the "reload" entry above. If not, "force-reload" is
	#	just the same as "restart".
	#
	    echo -n "Restarting $DESC: "
	    start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
	    rm -f $PIDFILE
	    sleep 1
	    start-stop-daemon --start --quiet --exec "$DAEMONBOOTSTRAP" -- /etc/${NAME}.conf $PIDFILE
	    echo "$NAME."
	    ;;
	status)
	    status_of_proc $DAEMON $NAME
	    ;;
	*)
	    N=/etc/init.d/$DAEMONNAME
	    echo "Usage: $N {start|stop|restart|force-reload|status}" >&2
	    exit 1
	    ;;
    esac
done;
 
exit 0
' > /etc/init.d/memcached
 
echo '#!/usr/bin/perl -w
 
# start-memcached
# 2003/2004 - Jay Bonci <jaybonci@debian.org>
# This script handles the parsing of the /etc/memcached.conf file
# and was originally created for the Debian distribution.
# Anyone may use this little script under the same terms as
# memcached itself.
 
use strict;
 
if($> != 0 and $< != 0)
{
    print STDERR "Only root wants to run start-memcached.\n";
    exit;
}
 
my $params; my $etchandle; my $etcfile = "/etc/memcached.conf";
 
# This script assumes that memcached is located at /usr/bin/memcached, and
# that the pidfile is writable at /var/run/memcached.pid
 
my $memcached = "/usr/bin/memcached";
my $pidfile = "/var/run/memcached.pid";
 
if (scalar(@ARGV) == 2) {
    $etcfile = shift(@ARGV);
    $pidfile = shift(@ARGV);
}
 
# If we don't get a valid logfile parameter in the /etc/memcached.conf file,
# we'll just throw away all of our in-daemon output. We need to re-tie it so
# that non-bash shells will not hang on logout. Thanks to Michael Renner for
# the tip
my $fd_reopened = "/dev/null";
 
sub handle_logfile
{
    my ($logfile) = @_;
    $fd_reopened = $logfile;
}
 
sub reopen_logfile
{
    my ($logfile) = @_;
 
    open *STDERR, ">>$logfile";
    open *STDOUT, ">>$logfile";
    open *STDIN, ">>/dev/null";
    $fd_reopened = $logfile;
}
 
# This is set up in place here to support other non -[a-z] directives
 
my $conf_directives = {
    "logfile" => \&handle_logfile,
};
 
if(open $etchandle, $etcfile)
{
    foreach my $line (<$etchandle>)
    {
        $line ||= "";
        $line =~ s/\#.*//g;
        $line =~ s/\s+$//g;
        $line =~ s/^\s+//g;
        next unless $line;
        next if $line =~ /^\-[dh]/;
 
        if($line =~ /^[^\-]/)
        {
            my ($directive, $arg) = $line =~ /^(.*?)\s+(.*)/;
            $conf_directives->{$directive}->($arg);
            next;
        }
 
        push @$params, $line;
    }
 
}else{
    $params = [];
}
 
push @$params, "-u root" unless(grep "-u", @$params);
$params = join " ", @$params;
 
if(-e $pidfile)
{
    open PIDHANDLE, "$pidfile";
    my $localpid = <PIDHANDLE>;
    close PIDHANDLE;
 
    chomp $localpid;
    if(-d "/proc/$localpid")
    {
        print STDERR "memcached is already running.\n";
        exit;
    }else{
        `rm -f $localpid`;
    }
 
}
 
my $pid = fork();
 
if($pid == 0)
{
    reopen_logfile($fd_reopened);
    exec "$memcached $params";
    exit(0);
 
}else{
    if(open PIDHANDLE,">$pidfile")
    {
        print PIDHANDLE $pid;
        close PIDHANDLE;
    }else{
 
        print STDERR "Can't write pidfile to $pidfile.\n";
    }
}
' > /usr/share/memcached/scripts/start-memcached
 
echo -e "## Install development soft ##"
aptitude install gcc build-essential g++ libboost-dev libboost-program-options-dev libboost-all-dev libevent-dev uuid-dev -y
 
service php5-fpm restart
 
echo -e "## Install DNS Server ##"
# aptitude install bind9 bind9utils bind9-libs -y
aptitude install pdns-server pdns-backend-mysql pdns-recursor -y
 
echo -e "## Install SMTP Server ##"
aptitude install exim4
dpkg-reconfigure exim4-config
 
echo -e  "## Start APPs ##"
service nginx restart
service php5-fpm restart
service mysql restart
service memcached restart
 
#echo " *Clearing downloaded packages after install!*"
#rm /var/cache/apt/archives/*.deb -f
 
echo -e "## Base system configure ##"
echo '
 
#
# My config
#
alias nano="nano -u -w "
alias ls="ls --color=always"
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
HISTSIZE=50000
HISTFILESIZE=50000
export HISTCONTROL=ignoreboth
shopt -s cmdhist
shopt -s histappend
shopt -s checkwinsize
shopt -s extglob
ulimit -c 0
 
#
# Functions
#
 
#-----------------------------------
# Функции работы с историей комманд
#-----------------------------------
 
function h(){
        history| grep "$@";
}
 
#-----------------------------------
# Функции для работы с файлами и строками:
#-----------------------------------
 
# Поиск файла по шаблону:
function ff() { find . -type f -iname '*'$*'*' -ls ; }
# Поиск файла по шаблону в $1 и запуск команды в $2 с ним:
function fe() { find . -type f -iname '*'$1'*' -exec "${2:-file}" {} \;  ; }
# поиск строки по файлам:
function fstr()
{
    OPTIND=1
    local case=""
    local usage="fstr: поиск строки в файлах.
        Порядок использования: fstr [-i] \"шаблон\" [\"шаблон_имени_файла\"] "
    while getopts :it opt
    do
        case "$opt" in
        i) case="-i " ;;
        *) echo "$usage"; return;;
        esac
    done
    shift $(( $OPTIND - 1 ))
    if [ "$#" -lt 1 ]; then
        echo "$usage"
        return;
    fi
    local SMSO=$(tput smso)
    local RMSO=$(tput rmso)
    find . -type f -name "${2:-*}" -print0 | xargs -0 grep -sn ${case} "$1" 2>&- | \
        sed "s/$1/${SMSO}\0${RMSO}/gI" | more
}
 
' >> ~/.bashrc
source ~/.bashrc
 
echo '
set tabsize "2"
' >> ~/.nanorc
  • debian/server-install.sh.txt
  • Последнее изменение: 2016/02/15 12:08
  • mirocow