script_centos_isp.sh 12 KB

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