script_centos_isp.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. #!/bin/bash
  2. clear
  3. echo " ___ _ ___ ___ ____ __ _ ___ "
  4. echo " / __|___ _ _| |_ / _ \/ __|__ | _ __ ___ _ _ / _|___ __| |_/ __| ___ _ ___ __"
  5. echo " | (__/ -_) ' \ _| (_) \__ \ / / | '_ \/ -_) '_| _/ -_) _| _\__ \/ -_) '_\ V /"
  6. echo " \___\___|_||_\__|\___/|___//_/ | .__/\___|_| |_| \___\__|\__|___/\___|_| \_/ "
  7. echo " |_| V0.2 for auto hosting simply & easily "
  8. echo "To view details: \"tail -f log_script.log\""
  9. echo ""
  10. echo -e "\033[31mThis script will modify your server's configuration.\033[0m"
  11. echo -e "\033[31mNO guarantees are implied\033[0m"
  12. echo -e "\033[31mDo you want to continue? (type yes in UPPERCASE)\033[0m"
  13. read areyousure
  14. if [ $areyousure != "YES" ]
  15. then exit 1
  16. else echo -e "\033[31mStarting script `basename $0`\033[0m"
  17. fi
  18. LOG=/root/log_script.log
  19. echo "NOZEROCONF=yes" >> /etc/sysconfig/network
  20. # Configuration of repository for CentOS
  21. configure_repo() {
  22. yum -y install wget >> $LOG 2>&1
  23. echo -e "[\033[33m*\033[0m] Installing & configuring epel, rpmforge repos..."
  24. rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt >> $LOG 2>&1 || echo -e "[\033[31mX\033[0m] Error importing key /etc/pki/rpm-gpg/RPM-GPG-KEY.dag.txt"
  25. cd /tmp
  26. wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm >> $LOG 2>&1 || echo -e "[\033[31mX\033[0m] Error downloading rpmforge rpm"
  27. rpm -ivh rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm >> $LOG 2>&1 || echo -e "[\033[31mX\033[0m] Error installing rpmforge rpm"
  28. rpm --import https://fedoraproject.org/static/0608B895.txt >> $LOG 2>&1 || echo -e "[\033[31mX\033[0m] Error importing epel key"
  29. wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-2.noarch.rpm >> $LOG 2>&1 || echo -e "[\033[31mX\033[0m] Error downloading epel repo rpm"
  30. rpm -ivh epel-release-7-2.noarch.rpm >> $LOG 2>&1 || echo -e "[\033[31mX\033[0m] Error installing epel repo rpm"
  31. yum install yum-priorities -y >> $LOG 2>&1 echo -e "[\033[31mX\033[0m] Error installing yum-priorites"
  32. awk 'NR== 2 { print "priority=10" } { print }' /etc/yum.repos.d/epel.repo > /tmp/epel.repo
  33. rm /etc/yum.repos.d/epel.repo -f
  34. mv /tmp/epel.repo /etc/yum.repos.d
  35. }
  36. update_system() {
  37. echo -e "[\033[33m*\033[0m] Updating full system (it can take some minutes...)"
  38. yum update -y >> $LOG 2>&1 || echo -e "[\033[31mX\033[0m] Error in yum update"
  39. }
  40. install_required_packages() {
  41. echo -e "[\033[33m*\033[0m] Installing required packages"
  42. yum install -y vim htop iftop iotop net-tools nmap screen git expect openssl >> $LOG 2>&1 || echo -e "[\033[31mX\033[0m] Error installing base packages"
  43. echo -e "[\033[33m*\033[0m] Installing Development Tools"
  44. yum groupinstall -y 'Development Tools' >> $LOG 2>&1 || echo -e "[\033[31mX\033[0m] Error installing Dev Tools metapackage"
  45. }
  46. install_ntpd() {
  47. echo -e "[\033[33m*\033[0m] Installing and configure NTPD"
  48. yum install -y ntp >> $LOG 2>&1
  49. systemctl enable ntpd >> $LOG 2>&1
  50. systemctl start ntpd >> $LOG 2>&1
  51. }
  52. disable_fw() {
  53. echo -e "[\033[33m*\033[0m] Disabling Firewall (for installation time)"
  54. systemctl stop firewalld >> $LOG 2>&1
  55. systemctl disable firewalld >> $LOG 2>&1
  56. }
  57. disable_selinux() {
  58. echo -e "[\033[33m*\033[0m] Disabling SELinux"
  59. sed -i -e 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config >> $LOG 2>&1
  60. setenforce 0 >> $LOG 2>&1
  61. }
  62. install_mariadb() {
  63. echo -e "[\033[33m*\033[0m] Installing MariaDB SQL Server"
  64. yum install mariadb-server mariadb-client -y >> $LOG 2>&1
  65. chkconfig --levels 235 mariadb on >> $LOG 2>&1
  66. systemctl start mariadb >> $LOG 2>&1
  67. /usr/bin/mysql_secure_installation
  68. }
  69. install_dovecot() {
  70. echo -e "[\033[33m*\033[0m] Installing DOVECOT Server"
  71. yum install dovecot dovecot-mysql -y >> $LOG 2>&1
  72. systemctl enable dovecot >> $LOG 2>&1
  73. systemctl start dovecot >> $LOG 2>&1
  74. }
  75. install_postfix() {
  76. echo -e "[\033[33m*\033[0m] Installing Postfix Server"
  77. yum install postfix -y >> $LOG 2>&1
  78. systemctl start postfix >> $LOG 2>&1
  79. systemctl start postfix >> $LOG 2>&1
  80. echo -e "[\033[33m*\033[0m] Installing getmail"
  81. yum install getmail -y >> $LOG 2>&1
  82. }
  83. install_clamav() {
  84. echo -e "[\033[33m*\033[0m] Installing Antivirus/Antispam Layer (it can take some times downloading AV databases)"
  85. yum install -y amavisd-new spamassassin clamav clamd unzip bzip2 unrar perl-DBD-mysql --disablerepo=epel >> $LOG 2>&1
  86. sa-update >> $LOG 2>&1
  87. systemctl start clamd >> $LOG 2>&1
  88. /usr/bin/freshclam >> $LOG 2>&1
  89. }
  90. install_nginx() {
  91. echo -e "[\033[33m*\033[0m] Installing & Configuring NGINX Webserver"
  92. yum install nginx --enablerepo=epel -y >> $LOG 2>&1
  93. # awk 'NR== 21 { print "map $scheme $https {" ; print "default off;" ; print "https on;"; print "}"} { print }' /etc/nginx/nginx.conf > /tmp/nginx.conf
  94. # rm -f /etc/nginx/nginx.conf
  95. # mv /tmp/nginx.conf /etc/nginx
  96. systemctl disable httpd >> $LOG 2>&1
  97. systemctl enable nginx >> $LOG 2>&1
  98. systemctl start nginx >> $LOG 2>&1
  99. yum install php php-fpm php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-pecl-apc php-magickwand php-magpierss php-mbstring php-mcrypt php-mssql php-shout php-snmp php-soap php-tidy -y >> $LOG 2>&1
  100. sed -i -e 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/' /etc/php.ini >> $LOG 2>&1
  101. systemctl enable php-fpm >> $LOG 2>&1
  102. systemctl start php-fpm >> $LOG 2>&1
  103. yum install -y fcgi-devel >> $LOG 2>&1
  104. echo -e " [\033[33m*\033[0m] Compil fcgiwrap (cause it don't exist in rpm for CentOS)"
  105. cd /usr/local/src/
  106. git clone git://github.com/gnosek/fcgiwrap.git >> $LOG 2>&1
  107. echo -e " [\033[32m*\033[0m] Gitting sources done"
  108. cd fcgiwrap
  109. autoreconf -i >> $LOG 2>&1
  110. ./configure >> $LOG 2>&1
  111. make >> $LOG 2>&1
  112. make install >> $LOG 2>&1
  113. echo -e " [\033[32m*\033[0m] fcgiwrap done"
  114. yum install spawn-fcgi -y >> $LOG 2>&1
  115. echo -e "[\033[33m*\033[0m] Setting /etc/sysconfig/spawn-fcgi configuration file"
  116. cat <<EOF > /etc/sysconfig/spawn-fcgi
  117. # You must set some working options before the "spawn-fcgi" service will work.
  118. # If SOCKET points to a file, then this file is cleaned up by the init script.
  119. #
  120. # See spawn-fcgi(1) for all possible options.
  121. #
  122. # Example :
  123. #SOCKET=/var/run/php-fcgi.sock
  124. #OPTIONS="-u apache -g apache -s $SOCKET -S -M 0600 -C 32 -F 1 -P /var/run/spawn-fcgi.pid -- /usr/bin/php-cgi"
  125. FCGI_SOCKET=/var/run/fcgiwrap.socket
  126. FCGI_PROGRAM=/usr/local/sbin/fcgiwrap
  127. FCGI_USER=apache
  128. FCGI_GROUP=apache
  129. FCGI_EXTRA_OPTIONS="-M 0770"
  130. OPTIONS="-u $FCGI_USER -g $FCGI_GROUP -s $FCGI_SOCKET -S $FCGI_EXTRA_OPTIONS -F 1 -P /var/run/spawn-fcgi.pid -- $FCGI_PROGRAM"
  131. EOF
  132. usermod -a -G apache nginx >> $LOG 2>&1
  133. systemctl enable spawn-fcgi >> $LOG 2>&1
  134. systemctl start spawn-fcgi >> $LOG 2>&1
  135. }
  136. install_pma() {
  137. echo -e "[\033[33m*\033[0m] Setting PHPmyAdmin"
  138. yum install phpmyadmin -y >> $LOG 2>&1
  139. sed -i -e "s/'cookie'/'http'/" /etc/phpMyAdmin/config.inc.php 2>&1
  140. # sed -i -e "s/'blowfish_secret'] = '1199196662700621640'/'blowfish_secret'] = '$(echo MONNOMBRE)'/" /etc/phpMyAdmin/config.inc.php 2>&1
  141. }
  142. install_mailman() {
  143. echo -e "[\033[33m*\033[0m] Setting Mailman"
  144. yum install mailman -y >> $LOG 2>&1
  145. /usr/lib/mailman/bin/newlist mailman
  146. cat <<EOF >> /etc/aliases
  147. mailman: "|/usr/lib/mailman/mail/mailman post mailman"
  148. mailman-admin: "|/usr/lib/mailman/mail/mailman admin mailman"
  149. mailman-bounces: "|/usr/lib/mailman/mail/mailman bounces mailman"
  150. mailman-confirm: "|/usr/lib/mailman/mail/mailman confirm mailman"
  151. mailman-join: "|/usr/lib/mailman/mail/mailman join mailman"
  152. mailman-leave: "|/usr/lib/mailman/mail/mailman leave mailman"
  153. mailman-owner: "|/usr/lib/mailman/mail/mailman owner mailman"
  154. mailman-request: "|/usr/lib/mailman/mail/mailman request mailman"
  155. mailman-subscribe: "|/usr/lib/mailman/mail/mailman subscribe mailman"
  156. mailman-unsubscribe: "|/usr/lib/mailman/mail/mailman unsubscribe mailman"
  157. EOF
  158. newaliases >> $LOG
  159. systemctl restart postfix >> $LOG 2>&1
  160. systemctl enable mailman >> $LOG 2>&1
  161. systemctl start mailman >> $LOG 2>&1
  162. cd /usr/lib/mailman/cgi-bin/
  163. ln -s ./ mailman
  164. }
  165. install_ftpd() {
  166. echo -e "[\033[33m*\033[0m] Setting PureFTPD"
  167. yum install pure-ftpd -y >> $LOG 2>&1
  168. systemctl start pure-ftpd >> $LOG 2>&1
  169. systemctl enable pure-ftpd >> $LOG 2>&1
  170. }
  171. install_bind() {
  172. echo -e "[\033[33m*\033[0m] Setting Bind"
  173. yum install bind bind-utils -y >> $LOG 2>&1
  174. cp /etc/named.conf /etc/named.conf_bak
  175. cat <<EOF > /etc/named.conf
  176. //
  177. // named.conf
  178. //
  179. // Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
  180. // server as a caching only nameserver (as a localhost DNS resolver only).
  181. //
  182. // See /usr/share/doc/bind*/sample/ for example named configuration files.
  183. //
  184. options {
  185. listen-on port 53 { any; };
  186. listen-on-v6 port 53 { any; };
  187. directory "/var/named";
  188. dump-file "/var/named/data/cache_dump.db";
  189. statistics-file "/var/named/data/named_stats.txt";
  190. memstatistics-file "/var/named/data/named_mem_stats.txt";
  191. allow-query { any; };
  192. recursion yes;
  193. };
  194. logging {
  195. channel default_debug {
  196. file "data/named.run";
  197. severity dynamic;
  198. };
  199. };
  200. zone "." IN {
  201. type hint;
  202. file "named.ca";
  203. };
  204. include "/etc/named.conf.local";
  205. EOF
  206. touch /etc/named.conf.local
  207. systemctl start named >> $LOG 2>&1
  208. systemctl enable named >> $LOG 2>&1
  209. }
  210. install_awstat() {
  211. echo -e "[\033[33m*\033[0m] Setting statistics stuffs"
  212. yum install webalizer awstats perl-DateTime-Format-HTTP perl-DateTime-Format-Builder -y >> $LOG 2>&1
  213. }
  214. install_jailkit() {
  215. echo -e "[\033[33m*\033[0m] Setting Jailkit"
  216. #Jailkit
  217. cd /usr/local/src
  218. wget http://olivier.sessink.nl/jailkit/jailkit-2.17.tar.gz >> $LOG 2>&1
  219. tar xvfz jailkit-2.17.tar.gz >> $LOG 2>&1
  220. cd jailkit-2.17
  221. ./configure >> $LOG 2>&1
  222. make >> $LOG 2>&1
  223. make install >> $LOG 2>&1
  224. }
  225. install_fail2ban() {
  226. echo -e "[\033[33m*\033[0m] Setting fail2ban & RootkitHunter"
  227. yum install fail2ban -y >> $LOG 2>&1
  228. systemctl start fail2ban >> $LOG 2>&1
  229. systemctl enable fail2ban >> $LOG 2>&1
  230. }
  231. install_rkhunter() {
  232. yum install rkhunter -y >> $LOG 2>&1
  233. }
  234. configure_repo
  235. update_system
  236. install_required_packages
  237. install_ntpd
  238. disable_fw
  239. disable_selinux
  240. install_mariadb
  241. install_dovecot
  242. install_postfix
  243. install_clamav
  244. install_nginx
  245. install_pma
  246. install_mailman
  247. install_ftpd
  248. install_bind
  249. install_awstat
  250. install_jailkit
  251. install_fail2ban
  252. install_rkhunter
  253. echo -e "[\033[33m*\033[0m] Installing ISPConfig Stable version"
  254. #ISPConfig
  255. cd /tmp
  256. wget http://www.ispconfig.org/downloads/ISPConfig-3-stable.tar.gz >> $LOG 2>&1
  257. tar xfz ISPConfig-3-stable.tar.gz >> $LOG 2>&1
  258. cd ispconfig3_install/install/
  259. php install.php