FreeBSD: Автоматическая установка web сервера

На просторах интернета был найден скрипт автоматической установки web-сервера на FreeBSD.

С помощью скрипта будет установлен следующий набор ПО:

nginx/Apache22/PHP5.2/MySQL/vsftpd

Вот сам скрипт:

-----------------------------------------------------------------------------------------------------------------------------

#!/bin/sh

### Web server FreeBSD ver. 0.92 from 28.02.2011

### 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=rg74.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 /usr/home ]; then
echo «/home is no exist! setup canceled.»
exit
fi

# add additional dns servers, OpenDNS
echo «nameserver 8.8.8.8″ >> /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/apache22 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/php52 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 « » » «`
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 «##############################»


-------------------------------------------------------------------------------------------------------------------------------------
Создаем файл с содержимым и запускаем.

# cd /usr/home/
#ee web-server.sh

Вносим в него содержимое из цитаты

Ставим права:

#chmod +x web-server.sh

Запускаем:

# sh web-server.sh

Начинается установка, ждем.

http://rg74.ru

Обновлено: 12.03.2015