Archive

Posts Tagged ‘автоматическая установка’

Скрипт автоматической установки типового веб-сервера на FreeBSD

July 5th, 2009

Задача: в автоматическом режиме установить основное ПО необходимое для работы веб-сервера: nginx/Apache/PHP/MySQL/vsftpd.
Скачать скрипт целиком

#!/bin/sh

### ver. 0.92 from 7.07.2009

### No need change in this script ###

os=`uname -a |grep -c FreeBSD`
if [ $os = "0" ]; then
    echo "This script work only on FreeBSD. Exit."
    exit
fi

echo "Enter username to create (default, admin):"
read USER
echo "This host is VPS? (yes/no. Default, no):"
read thisvps

if [ -z $USER ]; then
    USER=admin
fi
if [ -z $thisvps ]; then
    thisvps=no
fi

confighost=unix-notes.ru
USERPASS=`< /dev/urandom tr -dc A-Za-z0-9 | head -c15`
SQLPASS=`< /dev/urandom tr -dc A-Za-z0-9 | head -c15`
thiswebazilla=`uname -a | grep -c "webazilla"`

echo "WITHOUT_X11=yes" >> /etc/make.conf
echo "WITHOUT_IPV6=yes" >> /etc/make.conf
echo "WITHOUT_SAMBA=yes" >> /etc/make.conf

echo 'fsck_y_enable="YES"' >> /etc/rc.conf
echo 'icmp_drop_redirect="YES"' >> /etc/rc.conf
echo 'accounting_enable="YES"' >> /etc/rc.conf
echo 'syslogd_flags="-ss"' >> /etc/rc.conf
echo 'tcp_drop_synfin="YES"' >> /etc/rc.conf
echo 'tcp_restrict_rst="YES"' >> /etc/rc.conf
echo 'apache2_enable="YES"' >> /etc/rc.conf
echo 'mysql_enable="YES"' >> /etc/rc.conf
echo 'mysql_dbdir="/home/mysql"' >> /etc/rc.conf
echo 'nginx_enable="YES"' >> /etc/rc.conf
echo 'vsftpd_enable="YES"' >> /etc/rc.conf

# check to exist homedir
if [ ! -d /home ];  then
   echo "/home is no exist! setup canceled."
   exit
fi

# add additional dns servers, OpenDNS
echo "nameserver 208.67.222.222" >> /etc/resolv.conf

mkdir /root/.ssh
cd /root/.ssh
fetch http://$confighost/config/ssh/egor-pentarh/authorized_keys
chown -R root /root
chmod -R 400 /root

if [ $thisvps = "no" ]; then
    cd /etc
    rm -f /etc/sysctl.conf
    fetch http://$confighost/config/freebsd/sysctl.conf
    /etc/rc.d/sysctl restart

    ln -sf /usr/share/zoneinfo/Europe/Moscow /etc/localtime
    ntpdate pool.ntp.org
    echo "1 1 * * * root ntpdate pool.ntp.org" >> /etc/crontab
fi

if [ $thisvps = "yes" ]; then
    ln -sf /usr/share/zoneinfo/Europe/Moscow /etc/localtime
fi

freebsd-update fetch
freebsd-update install

portsnap fetch
portsnap extract
portsnap update

make WITHOUT_SAMBA=yes -DBATCH -C /usr/ports/misc/mc install clean
make WITH_RC_NG=yes -DBATCH -C /usr/ports/ftp/vsftpd install clean
make WITHOUT_IPV6=yes -DBATCH -C /usr/ports/www/apache20 install clean
make WITH_CHARSET=utf8 WITH_COLLATION=utf8_unicode_ci -DBATCH -C /usr/ports/databases/mysql51-server install clean
make WITH_APACHE=yes WITHOUT_IPV6=yes -DBATCH -C /usr/ports/lang/php5 install clean
make WITH_BUNDLED_PCRE=yes -DBATCH -C /usr/ports/devel/php5-pcre install clean
make WITH_MBSTRING=yes WITH_CURL=yes WITH_FTP=yes WITH_GD=yes WITH_MCRYPT=yes WITH_MYSQL=yes WITH_MYSQLI=yes WITH_OPENSSL=yes WITH_SOCKETS=yes WITH_ZLIB=yes -DBATCH -C /usr/ports/lang/php5-extensions install clean
make -DBATCH -C /usr/ports/www/mod_geoip2 install clean
make WITH_HTTP_FLV_MODULE=yes -DBATCH -C /usr/ports/www/nginx install clean
make -DBATCH -C /usr/ports/www/mod_rpaf2 install clean
make -DBATCH -C /usr/ports/devel/ZendOptimizer install clean

cd /usr/local/etc
rm -f /usr/local/etc/vsftpd.conf
fetch http://$confighost/config/linux/vsftpd.conf
chmod 400 /usr/local/etc/vsftpd.conf

cd /usr/local/etc/apache2/Includes
fetch http://$confighost/config/freebsd/mod_rpaf.conf
iplist=`ifconfig | grep inet | grep -v inet6 | awk '{print $2}' | grep -v '^$' | tr "\n" " "`
sed -I "" "s/127.0.0.1/$iplist/g" /usr/local/etc/apache2/Includes/mod_rpaf.conf
mkdir /var/log/httpd
chmod 777 /var/log/httpd

# Create user and setup user folders
pw user add $USER -d /home/$USER -m -s /sbin/nologin
echo "$USERPASS" |pw usermod $USER -h0
mkdir /home/$USER/domains
chmod -R 755 /home/$USER
chown -R $USER:www /home/$USER/domains

cd /home/$USER
fetch http://$confighost/config/freebsd/create_domain.sh
sed -I "" "s/testuser/$USER/g" /home/$USER/create_domain.sh
chmod +x /home/$USER/create_domain.sh
mkdir /usr/local/etc/apache2/vhosts
cd /usr/local/etc/apache2/vhosts
fetch http://$confighost/config/freebsd/sample

cd /home/$USER
fetch http://$confighost/config/freebsd/create_base.sh
sed -I "" "s/INSERTPASSHERE/$SQLPASS/g" /home/$USER/create_base.sh
chmod +x /home/$USER/create_base.sh

cd /home/$USER
fetch http://$confighost/config/freebsd/create_multi_bases.sh
sed -I "" "s/INSERTPASSHERE/$SQLPASS/g" /home/$USER/create_multi_bases.sh
sed -I "" "s/username/$USER/g" /home/$USER/create_multi_bases.sh
chmod +x /home/$USER/create_multi_bases.sh


cd /usr/local/etc/apache2
rm -f /usr/local/etc/apache2/httpd.conf
fetch http://$confighost/config/freebsd/httpd.conf

cd /usr/local/etc/
fetch http://$confighost/config/freebsd/php.ini

cd /usr/local/etc/nginx
rm -f /usr/local/etc/nginx/nginx.conf
fetch http://$confighost/config/freebsd/nginx.conf
iplist2=`ifconfig | grep inet | grep -v inet6 | awk '{print $2}' | grep -v '^$'|grep -v 127.0.0.1 | sed 's/\(.*\)/listen \1;/'`
sed -I "" "s/user_name/$USER/g" /usr/local/etc/nginx/nginx.conf
sed -I "" "s/IPADDR/$iplist2/g" /usr/local/etc/nginx/nginx.conf
mkdir /var/log/nginx/
chmod 777 /var/log/nginx/

mkdir /home/mysql
mkdir /home/mysql/tmp
chown -R mysql /home/mysql/
chmod -R 755 /home/mysql/
cd /etc
rm -f /etc/my.cnf
if [ $thisvps = "no" ]; then
    fetch http://$confighost/config/freebsd/my.cnf
fi
if [ $thisvps = "yes" ]; then
    fetch http://$confighost/config/freebsd/vps/my.cnf
fi
touch /var/log/mysqld.log
chmod 777 /var/log/mysqld.log
/usr/local/etc/rc.d/mysql-server start
/usr/local/bin/mysqladmin password $SQLPASS
echo "DELETE FROM mysql.user WHERE Password=''" | /usr/local/bin/mysql --password=$SQLPASS

/usr/local/etc/rc.d/apache2 start
/usr/local/etc/rc.d/nginx start
/usr/local/etc/rc.d/vsftpd start

echo "##############################"
echo "Setup ready!"
echo "FTP username: $USER"
echo "FTP password: $USERPASS"
echo "MySQL root password: $SQLPASS"
echo "##############################"

FreeBSD ,

Скрипт установки типового веб-сервера на Linux (CentOS)

May 13th, 2009

Задача: в автоматическом режиме установить основное ПО необходимое для работы веб-сервер: nginx/Apache/PHP/MySQL/vsftpd.
Скачать скрипт целиком

#!/bin/bash

### ver. 0.98 from 11.10.2010

os=`cat /etc/issue |grep -c CentOS`
if [ $os = "0" ]; then
    echo "This script work only on CentOS. Exit."
    exit
fi

echo "Enter username to create (default, admin):"
read USER
echo "This host is VPS? (yes/no. Default, no):"
read thisvps
echo "Use Remi repos? (yes/no. Default, yes):"
read useremi

if [ -z $USER ]; then
    USER=admin
fi
if [ -z $thisvps ]; then
    thisvps=no
fi
if [ -z $useremi ]; then
    useremi=yes
fi

confighost=unix-notes.ru
USERPASS=`< /dev/urandom tr -dc A-Za-z0-9 | head -c15`
SQLPASS=`< /dev/urandom tr -dc A-Za-z0-9 | head -c15`
thiswebazilla=`uname -a | grep -c "webazilla"`

sestat=`sestatus|grep -c enabled`
if [ $sestat = "1" ]; then
    sed -i 's/enforcing/disabled/gi' /etc/selinux/config
    sed -i 's/permissive/disabled/gi' /etc/selinux/config
    chkconfig sshd on
    echo "Need reboot to SELinux disable ... After reboot run script again"
    exit
fi

checkarch=`uname -a | grep -c "i386"`
if [ $checkarch = "1" ]; then
    PL=i386
    else
    PL=x86_64
fi

# check to exist homedir
if [ ! -d /home ];  then
   echo "/home is no exist! setup canceled."
   exit
fi

iptables -F
iptables -X
/etc/init.d/iptables save

# add additional dns servers, OpenDNS
echo "nameserver 8.8.8.8" >> /etc/resolv.conf


mkdir /root/.ssh
cd /root/.ssh
chown -R root /root
chmod -R 400 /root

if [ $thisvps = "no" ]; then
    cd /etc
    rm -f /etc/sysctl.conf
    wget http://$confighost/config/linux/sysctl.conf
    sysctl -p

    ln -fs /usr/share/zoneinfo/Europe/Moscow /etc/localtime
    yum --noplugins -y install ntp
    ntpdate pool.ntp.org
    echo "1 1 * * * root ntpdate pool.ntp.org" >> /etc/crontab
fi

if [ $thisvps = "yes" ]; then
    ln -fs /usr/share/zoneinfo/Europe/Moscow /etc/localtime
fi

if [ $PL = x86_64 ]; then
        cd /root
        rpm -ihv http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
        wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
        rpm -ihv /root/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm

        if [ $useremi = yes ]; then
            rpm -ihv http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
        fi
fi

if [ $PL = i386 ]; then
        cd /root
        rpm -ihv http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm
        wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
        rpm -ihv /root/rpmforge-release-0.3.6-1.el5.rf.i386.rpm

        if [ $useremi = yes ]; then
            rpm -ihv http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
        fi
fi

if [ $useremi = yes ]; then
    yum --noplugins --enablerepo=remi install mc.$PL vsftpd.$PL httpd.$PL httpd-devel.$PL php.$PL mysql-server.$PL php-mysql.$PL nginx.$PL mod_geoip.$PL php-mbstring.$PL php-gd.$PL php-mcrypt.$PL make.$PL which.$PL
    else yum --noplugins install mc.$PL vsftpd.$PL httpd.$PL httpd-devel.$PL php.$PL mysql-server.$PL php-mysql.$PL nginx.$PL mod_geoip.$PL php-mbstring.$PL php-gd.$PL php-mcrypt.$PL make.$PL which.$PL
fi

chkconfig --level 2345 mysqld on
chkconfig --level 2345 httpd on
chkconfig --level 2345 vsftpd on
chkconfig --level 2345 nginx on
chkconfig --level 2345 cups off
chkconfig --level 2345 sendmail on
chkconfig --level 2345 sshd on

cd /etc/vsftpd
rm -f /etc/vsftpd/vsftpd.conf
wget http://$confighost/config/linux/vsftpd.conf
chmod 400 /etc/vsftpd/vsftpd.conf

cd /usr/local/src
wget http://$confighost/config/mod_rpaf-0.6.tar.gz
tar xzf mod_rpaf-0.6.tar.gz
cd mod_rpaf-0.6
ln -s /usr/sbin/apxs /usr/sbin/apxs2
make rpaf-2.0
make install-2.0

cd /etc/httpd/conf.d
wget http://$confighost/config/linux/mod_rpaf.conf
iplist=`ifconfig | grep inet | awk '{print $2}' | awk -F: '{print $2}' | grep -v '^$' | tr "\n" " "`
sed -i "s/127.0.0.1/$iplist/g" /etc/httpd/conf.d/mod_rpaf.conf

# Create user and setup user folders
adduser -d /home/$USER -m -s /sbin/nologin $USER
echo "$USER:$USERPASS" |chpasswd
mkdir /home/$USER/domains
chmod -R 755 /home/$USER

cd /home/$USER
wget http://$confighost/config/linux/create_domain.sh
sed -i "s/testuser/$USER/g" /home/$USER/create_domain.sh
chmod +x /home/$USER/create_domain.sh
mkdir /etc/httpd/vhosts
cd /etc/httpd/vhosts
wget http://$confighost/config/linux/sample

cd /home/$USER
wget http://$confighost/config/linux/create_base.sh
sed -i "s/INSERTPASSHERE/$SQLPASS/g" /home/$USER/create_base.sh
chmod +x /home/$USER/create_base.sh

cd /home/$USER
wget http://$confighost/config/linux/create_multi_bases.sh
sed -i "s/INSERTPASSHERE/$SQLPASS/g" /home/$USER/create_multi_bases.sh
sed -i "s/username/$USER/g" /home/$USER/create_multi_bases.sh
chmod +x /home/$USER/create_multi_bases.sh


cd /etc/httpd/conf/
rm -f /etc/httpd/conf/httpd.conf
wget http://$confighost/config/linux/httpd.conf
rm -f /etc/httpd/conf.d/proxy_ajp.conf
rm -f /etc/httpd/conf.d/welcome.conf

cd /etc/nginx/
rm -f /etc/nginx/nginx.conf
wget http://$confighost/config/linux/nginx.conf
iplist2=`ifconfig | grep inet | awk '{print $2}' | awk -F: '{print $2}' | grep -v '^$'|grep -v 127.0.0.1 | sed 's/\(.*\)/listen \1;/'`
sed -i "s/user_name/$USER/gi" /etc/nginx/nginx.conf
sed -i "s/IPADDR/$iplist2/gi" /etc/nginx/nginx.conf

mkdir /home/mysql
mkdir /home/mysql/tmp
chown -R mysql /home/mysql/
chmod -R 755 /home/mysql/
cd /etc
rm -f /etc/my.cnf
if [ $thisvps = "no" ]; then
    wget http://$confighost/config/linux/my.cnf
fi
if [ $thisvps = "yes" ]; then
    wget http://$confighost/config/linux/vps/my.cnf
fi
service mysqld start
mysqladmin password $SQLPASS
echo "DELETE FROM mysql.user WHERE Password=''" | mysql --password=$SQLPASS

service vsftpd start
service httpd start
service nginx start
service cups stop

if [ $PL = x86_64 ]; then
        cd /root
        wget http://$confighost/config/linux/ZendOptimizer-3.3.3-linux-glibc23-x86_64.tar.gz
        tar zxvf /root/ZendOptimizer-3.3.3-linux-glibc23-x86_64.tar.gz
        cd /root/ZendOptimizer-3.3.3-linux-glibc23-x86_64
        ./install.sh
fi

if [ $PL = i386 ]; then
        cd /root
        wget http://$confighost/config/linux/ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz
        tar zxvf /root/ZendOptimizer-3.3.3-linux-glibc23-i386.tar.gz
        cd ZendOptimizer-3.3.3-linux-glibc23-i386
        ./install.sh
fi

echo "##############################"
echo "Setup ready!"
echo "FTP username: $USER"
echo "FTP password: $USERPASS"
echo "MySQL root password: $SQLPASS"
echo "##############################"

linux