script_centos_isp.sh 13 KB

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