Chinaunix首页 | 论坛 | 博客
  • 博客访问: 271913
  • 博文数量: 188
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: -30
  • 用 户 组: 普通用户
  • 注册时间: 2017-03-29 11:17
文章分类
文章存档

2013年(8)

2012年(5)

2011年(13)

2010年(26)

2009年(63)

2008年(20)

2007年(32)

2006年(21)

分类: Python/Ruby

2011-07-26 08:59:20

  1. #!/bin/bash
  2. #######################################################################
  3. # File: Autoconfig.sh #
  4. # Description: Linux Security Configuration Tool #
  5. # Language: GNU Bourne-Again Shell #
  6. # Version: 2.0 #
  7. # Date: 2011-7-21 #
  8. # Corp.: #
  9. # Author: changyuzeng #
  10. ### END INIT INFO #
  11. #######################################################################
  12. #change yum source
  13. if [ ! -f /etc/yum.repos.d/CentOS-Base-163.repo ] && [ ! -f /etc/yum.repos.d/CentOS-Base-sohu.repo ];then
  14. cd /etc/yum.repos.d/
  15. wget
  16. wget
  17. yum makecache > /dev/null 2>&1
  18. fi
  19. ############### Install dialog###############
  20. echo "Dialog now instaling,please wait..."
  21. yum -y install dialog > /dev/null 2>&1
  22. #Ntp server
  23. yum install -y ntp > /dev/null 2>&1
  24. echo '0 23 * * * /usr/sbin/ntpdate 210.72.145.44' > /tmp/crontab2.tmp
  25. crontab /tmp/crontab2.tmp
  26. #timezone
  27. rm -rf /etc/localtime
  28. ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime > /dev/null 2>&1
  29. #Disable SeLinux
  30. if [ -s /etc/selinux/config ]; then
  31. sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
  32. fi
  33. INSTALL_SRC=/usr/local/src
  34. lamp_log=/root/lamp_install.log
  35. sed -i '6c ulimit -SHn 65535' /etc/rc.local
  36. ###path###
  37. stat=`grep -n '/usr/local/apache' /etc/profile`
  38. if [ $? = 1 ];then
  39. sed -i '/export PATH/i PATH=$PATH:/usr/local/mysql/bin:/usr/local/apache/sbin:/usr/local/php/bin:/usr/local/php/sbin:/usr/local/bin' /etc/profile
  40. source /etc/profile
  41. fi
  42. stat=`grep -n '/usr/local/mysql/lib' /etc/ld.so.conf`
  43. if [ $? = 1 ];then
  44. sed -i '/include/a /lib\n/usr/lib\n/usr/local/lib\n/usr/local/mysql/lib/\n/usr/local/php/lib' /etc/ld.so.conf
  45. ldconfig
  46. fi
  47. #######################################################################
  48. V_DELUSER="adm lp sync shutdown halt news uucp operator games gopher ftp"
  49. V_DELGROUP="adm lp news uucp games gopher floppy dip pppusers slipusers"
  50. V_PASSMINLEN=8
  51. V_HISTSIZE=50
  52. V_TMOUT=600
  53. V_GROUPNAME=wheel
  54. V_SERVICE="bluetooth cups firstboot hidd ip6tables kudzu nfslock portmap"
  55. V_TTY="5|6"
  56. V_SUID=(
  57. '/usr/bin/chage'
  58. '/usr/bin/gpasswd'
  59. '/usr/bin/wall'
  60. '/usr/bin/chfn'
  61. '/usr/bin/chsh'
  62. '/usr/bin/newgrp'
  63. '/usr/bin/write'
  64. '/usr/sbin/usernetctl'
  65. '/bin/traceroute'
  66. '/bin/mount'
  67. '/bin/umount'
  68. '/sbin/netreport'
  69. )
  70. ###########################################################################
  71. install_init() {
  72. clear
  73. echo "========================================================================="
  74. echo "A tool to auto-compile & install Nginx+MySQL+PHP on Linux "
  75. echo ""
  76. echo "For more information please Contact administrators"
  77. echo "========================================================================="
  78. set main domain name
  79. domain=""
  80. echo "Please input domain:"
  81. read -p "(Default domain: ):" domain
  82. if [ "$domain" = "" ]; then
  83. domain=""
  84. fi
  85. echo "==========================="
  86. echo domain="$domain"
  87. echo "==========================="
  88. #set webroot
  89. webroot=/data/webroot
  90. echo "Please input webroot:"
  91. read -p "(Default webroot: /data/weboot):" webroot
  92. if [ "$webroot" = "" ]; then
  93. webroot=/data/webroot
  94. fi
  95. echo "==========================="
  96. echo webroot=$webroot
  97. echo "==========================="
  98. #set mysql root password
  99. echo "==========================="
  100. mysqlrootpwd="bitauto123"
  101. echo "Please input the root password of mysql:"
  102. read -p "(Default password: bitauto123):" mysqlrootpwd
  103. if [ "$mysqlrootpwd" = "" ]; then
  104. mysqlrootpwd="bitauto123"
  105. fi
  106. echo "==========================="
  107. echo mysqlrootpwd="$mysqlrootpwd"
  108. echo "==========================="
  109. get_char()
  110. {
  111. SAVEDSTTY=`stty -g`
  112. stty -echo
  113. stty cbreak
  114. dd if=/dev/tty bs=1 count=1 2> /dev/null
  115. stty -raw
  116. stty echo
  117. stty $SAVEDSTTY
  118. }
  119. echo ""
  120. echo "Press any key to start..."
  121. char=`get_char`
  122. #webroot log
  123. if [ ! -d $webroot ];then
  124. mkdir $webroot
  125. chown $webroot -R
  126. fi
  127. if [ ! -d /var/logs ];then
  128. mkdir -p /var/logs
  129. chown -R www:www /var/logs
  130. fi
  131. #################uninstall php mysql httpd#############################
  132. echo "Uninstall system package 'php mysql httpd' "
  133. yum -y erase php* mysql* httpd* > /dev/null 2>&1
  134. #########################################################
  135. # #
  136. # Download and Uncompress lamp source packet #
  137. # #
  138. #####################Uncompress file#####################
  139. if [ ! -d /usr/local/src ];then
  140. mkdir /usr/local/src
  141. fi
  142. if [ ! -f /usr/local/src/software.tar ];then
  143. echo "Download Lamp && Lnmp source packet..."
  144. cd /usr/local/src
  145. wget
  146. tar zxvf software.tar.gz -C $INSTALL_SRC
  147. mv software.tar.gz software.tar > /dev/null 2>&1
  148. fi
  149. echo "Uncompress Lamp && Lnmp source packet..."
  150. sleep 5
  151. for i in $INSTALL_SRC/*gz
  152. do
  153. tar -xzf $i -C $INSTALL_SRC
  154. done
  155. for i in $INSTALL_SRC/*.tar.bz2
  156. do
  157. tar -xjf $i -C $INSTALL_SRC
  158. done
  159. for i in $INSTALL_SRC/*.zip
  160. do
  161. unzip -o $i
  162. done
  163. ##################create user and group############
  164. for a in www mysql;do
  165. id $a >/dev/null 2>&1
  166. if [ $? != 0 ];then
  167. groupadd $a && useradd $a -g $a -s /sbin/nologin -d /dev/null -M -c "for $a"
  168. echo "www and mysql user has been added to your system..."
  169. fi
  170. done
  171. ######################edit test.php################
  172. touch $webroot/test.php
  173. cat << EOF > $webroot/test.php
  174. phpinfo();
  175. ?>
  176. EOF
  177. ################Base develop Environment###########
  178. yum -y install zlib zlib-devel libxml2-devel curl curl-devel libidn-devel e2fsprogs-devel keyutils-libs-devel libselinux-devel libsepol-devel krb5-devel openssl-devel curl*
  179. yum -y install gcc gcc-c++ flex bison autoconf automake bzip2-devel zlib-devel ncurses-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel pam-devel expat-devel openssl-devel gettext-devel libtool* flex aspell-devel gmp-devel freetype-devel
  180. }
  181. install_apache() {
  182. echo "+------------------------------------------------------+"
  183. echo "+ We will install apache service on the local computer +"
  184. echo "+------------------------------------------------------+"
  185. if [ -s "$INSTALL_SRC/httpd-2.2.19.tar.gz" ] && [ -d "$INSTALL_SRC/httpd-2.2.19" ];then
  186. echo "httpd-2.2.19.tar.gz [found]"
  187. cd $INSTALL_SRC/httpd-2.2.19
  188. cd srclib/apr
  189. ./configure --prefix=/usr/local/apr --enable-threads --enable-other-child --enable-static
  190. make && make install
  191. cd ../apr-util
  192. ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
  193. make && make install
  194. cd ../..
  195. ./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-rewrite --enable-mods-shared=all --enable-rewrite --enable-static --enable-cache --enable-threads --disable-version
  196. make &&make install
  197. if [ $? = 0 ];then
  198. \cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
  199. chmod 755 /etc/init.d/httpd
  200. sed -i '2 a # chkconfig: 2345 50 90' /etc/init.d/httpd
  201. sed -i '3 a\# description: Activates/Deactivates Apache Web Server' /etc/init.d/httpd
  202. chkconfig --add httpd
  203. chkconfig httpd on
  204. sed -i 's#User daemon#User www#' /usr/local/apache/conf/httpd.conf
  205. sed -i 's#Group daemon#Group www#' /usr/local/apache/conf/httpd.conf
  206. sed -i '$ a\ServerTokens Prod' /usr/local/apache/conf/httpd.conf
  207. sed -i 's#ErrorLog "logs/error_log"#ErrorLog "/var/logs/error_log"#' /usr/local/apache/conf/httpd.conf
  208. sed -i 's#CustomLog "logs/access_log" common#CustomLog "/var/logs/access_log" common#' /usr/local/apache/conf/httpd.conf
  209. sed -i 's/#ServerName '$domain':80/g' /usr/local/apache/conf/httpd.conf
  210. sed -i 's#DocumentRoot "/usr/local/apache/htdocs"# DocumentRoot "'$webroot'"#' /usr/local/apache/conf/httpd.conf
  211. sed -i 's###' /usr/local/apache/conf/httpd.conf
  212. echo "test apache running!" >> $lamp_log
  213. /usr/local/apache/bin/apachectl -t >> $lamp_log
  214. /usr/local/apache/bin/apachectl start >> $lamp_log
  215. fi
  216. fi
  217. echo "=============================="
  218. echo " apache install finished "
  219. echo "=============================="
  220. }
  221. install_mysql() {
  222. ##################################################install && configure mysql#############################################
  223. echo "+------------------------------------------------------+"
  224. echo "+ We will install mysql service on the local computer +"
  225. echo "+------------------------------------------------------+"
  226. if [ -s "$INSTALL_SRC/mysql-5.5.14.tar.gz" ] && [ -d "$INSTALL_SRC/mysql-5.5.14" ];then
  227. echo " Mysql installing now..." >> $lamp_log
  228. cd $INSTALL_SRC/libiconv-1.13.1
  229. ./configure --prefix=/usr/local
  230. make && make install >> $lamp_log
  231. cd ../
  232. cd libmcrypt-2.5.8/
  233. ./configure
  234. make && make install >> $lamp_log
  235. /sbin/ldconfig
  236. cd libltdl/
  237. ./configure --enable-ltdl-install
  238. make&&make install >> $lamp_log
  239. cd ../../
  240. cd mhash-0.9.9.9/
  241. ./configure
  242. make&&make install >> $lamp_log
  243. cd ../
  244. ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
  245. ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
  246. ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
  247. ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
  248. ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
  249. ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
  250. ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
  251. ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
  252. ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
  253. ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
  254. cd mcrypt-2.6.8/
  255. /sbin/ldconfig
  256. ./configure
  257. make&&make install >> $lamp_log
  258. cd ../
  259. mkdir -p /data/mysql
  260. chown -R mysql.mysql /data/mysql
  261. cd cmake-2.8.4/
  262. ./bootstrap
  263. gmake && gmake install >> $lamp_log
  264. cd ../
  265. cd mysql-5.5.14/
  266. cmake . \
  267. -DSYSCONFDIR=/etc \
  268. -DCMAKE_INSTALL_PREFIX:PATH=/usr/local/mysql \
  269. -DCOMMUNITY_BUILD:BOOL=ON \
  270. -DENABLED_PROFILING:BOOL=ON \
  271. -DENABLE_DEBUG_SYNC:BOOL=OFF \
  272. -DMYSQL_DATADIR:PATH=/data/mysql \
  273. -DWITH_MYISAM_STORAGE_ENGINE=1
  274. -DWITH_INNOBASE_STORAGE_ENGINE=1
  275. -DWITH_ARCHIVE_STORAGE_ENGINE=1
  276. -DWITH_BLACKHOLE_STORAGE_ENGINE=1
  277. -DDEFAULT_CHARSET=utf8
  278. -DDEFAULT_COLLATION=utf8_general_ci
  279. -DWITH_EXTRA_CHARSETS:STRING=all \
  280. -DWITH_SSL:STRING=bundled \
  281. -DWITH_UNIT_TESTS:BOOL=OFF \
  282. -DWITH_ZLIB:STRING=bundled \
  283. -LH
  284. make
  285. make install >> $lamp_log
  286. if [ $? = 0 ];then
  287. \cp support-files/my-huge.cnf /etc/my.cnf
  288. sed -i '30 a \open_files_limit = 10240\nmax_connections = 5000' /etc/my.cnf
  289. chown -R root.mysql /usr/local/mysql/
  290. /usr/local/mysql/scripts/mysql_install_db \
  291. --defaults-file=/etc/my.cnf \
  292. --basedir=/usr/local/mysql \
  293. --datadir=/data/mysql \
  294. --user=mysql
  295. chown -R mysql.mysql /data/mysql
  296. \cp support-files/mysql.server /etc/init.d/mysqld
  297. chmod 755 /etc/init.d/mysqld
  298. chkconfig --add mysqld
  299. echo "test mysql running!" >> $lamp_log
  300. /etc/init.d/mysqld start
  301. /etc/init.d/mysqld status >> $lamp_log
  302. mysqladmin -u root password $mysqlrootpwd
  303. #./bin/mysql_secure_installation
  304. fi
  305. else
  306. echo" mysql install failed"
  307. fi
  308. echo "=============================="
  309. echo " mysql install finished "
  310. echo "=============================="
  311. }
  312. install_apache-php() {
  313. echo "+------------------------------------------------------------+"
  314. echo "+ We will install "apache php" service on the local computer +"
  315. echo "+------------------------------------------------------------+"
  316. if [ -s "$INSTALL_SRC/php-5.3.6.tar.gz" ] && [ -d "$INSTALL_SRC/php-5.3.6" ];then
  317. echo "php will installing..." >> $lamp_log
  318. cd $INSTALL_SRC/php-5.3.6
  319. ./configure --prefix=/usr/local/php --with-config-file-path=/etc --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir=/usr/lib --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-openssl --enable-zend-multibyte --with-bz2 --enable-exif --without-pear
  320. make ZEND_EXTRA_LIBS='-liconv' >> $lamp_log
  321. make install >> $lamp_log
  322. if [ $? = 0 ];then
  323. \cp php.ini-production /etc/php.ini
  324. ln -s /usr/local/php/etc/php.ini /etc/php.ini
  325. cd ../
  326. cd memcache-3.0.6
  327. /usr/local/php/bin/phpize
  328. ./configure --with-php-config=/usr/local/php/bin/php-config
  329. make && make install >> $lamp_log
  330. cd ../
  331. cd eaccelerator-0.9.6.1/
  332. /usr/local/php/bin/phpize
  333. ./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
  334. make && make install >> $lamp_log
  335. cd ../
  336. cd PDO_MYSQL-1.0.2/
  337. /usr/local/php/bin/phpize
  338. ./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
  339. make && make install >> $lamp_log
  340. cd ../
  341. cd ImageMagick-6.6.9
  342. ./configure
  343. make && make install >> $lamp_log
  344. cd ../
  345. cd imagick-3.1.0b1/
  346. /usr/local/php/bin/phpize
  347. ./configure --with-php-config=/usr/local/php/bin/php-config
  348. make && make install >> $lamp_log
  349. ###zend configure#######
  350. bit=`uname -m`
  351. echo $bit
  352. if [ $bit == i686 ]
  353. then
  354. \cp /usr/local/src/ZendGuardLoader-php-5.3-linux-glibc23-i386/php-5.3.x/ZendGuardLoader.so /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/
  355. else
  356. cp /usr/local/src/ZendGuardLoader-php-5.3-linux-glibc23-x86_64/php-5.3.x/ZendGuardLoader.so /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/
  357. fi
  358. sed -i 's#; extension_dir = "./"#extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/"\nextension = "memcache.so"\nextension = "pdo_mysql.so"\nextension = "imagick.so"\n#' /etc/php.ini
  359. sed -i 's#output_buffering = Off#output_buffering = On#' /etc/php.ini
  360. sed -i "s#; always_populate_raw_post_data = On#always_populate_raw_post_data = On#g" /etc/php.ini
  361. sed -i "s#; cgi.fix_pathinfo=0#cgi.fix_pathinfo=0#g" /etc/php.ini
  362. sed -i '/;date.timezone/c date.timezone = Asia/Shanghai' /etc/php.ini
  363. sed -i "s#magic_quotes_gpc = Off#magic_quotes_gpc = On#g" /etc/php.ini
  364. mkdir /usr/local/eaccelerator_cache > /dev/null 2>&1
  365. sed -i '$ c ; End:\n\[eaccelerator]\nzend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/eaccelerator.so"\neaccelerator.shm_size="64"\neaccelerator.cache_dir="/usr/local/eaccelerator_cache"\neaccelerator.enable="1"\neaccelerator.optimizer="1"\neaccelerator.check_mtime="1"\neaccelerator.debug="0"\neaccelerator.filter=""\neaccelerator.shm_max="0"\neaccelerator.shm_ttl="3600"\neaccelerator.shm_prune_period="3600"\neaccelerator.shm_only="0"\neaccelerator.compress="1"\neaccelerator.compress_level="9"\n\[Zend Optimizer]\nzend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/ZendGuardLoader.so"\nzend_optimizer.optimization_level=1\nzend_optimizer.encoder_loader=0' /etc/php.ini
  366. sed -i 's#DirectoryIndex index.html#& index.php#' /usr/local/apache/conf/httpd.conf
  367. sed -i '356 c\ AddType application/x-httpd-php-source .php' /usr/local/apache/conf/httpd.conf
  368. sed -i '357 c\ AddType application/x-httpd-php .php' /usr/local/apache/conf/httpd.conf
  369. #sed -i '53 c LoadModule php5_module modules/libphp5.so' /usr/local/apache/conf/httpd.conf
  370. ldconfig
  371. /etc/init.d/httpd restart
  372. echo "---test "apache-php" status----" >> $lamp_log
  373. /usr/local/php/bin/php -v >> $lamp_log
  374. fi
  375. fi
  376. echo "========================== Check install ================================"
  377. echo "CentOS/RadHat auto configure "
  378. echo "========================================================================="
  379. echo ""
  380. echo "For more information please visit http:///"
  381. echo ""
  382. echo "Lamp status manage:"
  383. echo " /etc/init.d/httpd {start|stop|reload|restart|kill|status}"
  384. echo " /etc/init.d/mysqld {start|stop|reload|restart|kill|status}"
  385. echo ""
  386. echo "phpinfo : "
  387. echo "default mysql root password:$mysqlrootpwd"
  388. echo "mysql security configure: mysql_secure_installation"
  389. echo "The path of some dirs:"
  390. echo "mysql dir: /usr/local/mysqld"
  391. echo "php dir: /usr/local/php"
  392. echo "apache dir: /usr/local/apache"
  393. echo "web dir : $webroot"
  394. echo "log dir : /var/logs"
  395. echo ""
  396. echo "========================================================================="
  397. }
  398. install_nginx-php() {
  399. echo "+-----------------------------------------------------------+"
  400. echo "+ We will install "nginx php" service on the local computer +"
  401. echo "+-----------------------------------------------------------+"
  402. if [ -s "$INSTALL_SRC/php-5.3.6.tar.gz" ] && [ -d "$INSTALL_SRC/php-5.3.6" ];then
  403. echo " php-5.3.6.tar.gz [found]"
  404. cd $INSTALL_SRC/php-5.3.6
  405. ./configure --prefix=/usr/local/php --with-config-file-path=/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir=/usr/lib --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-openssl --enable-zend-multibyte --with-bz2 --enable-exif --without-pear --enable-fpm --with-fpm-user=www --with-fpm-group=www
  406. make ZEND_EXTRA_LIBS='-liconv' >> $lamp_log
  407. make install >> $lamp_log
  408. if [ $? = 0 ];then
  409. \cp php.ini-production /etc/php.ini
  410. ln -s /usr/local/php/etc/php.ini /etc/php.ini
  411. \cp /usr/local/src/php-fpm.conf /usr/local/php/etc/php-fpm.conf
  412. \cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
  413. chmod 755 /etc/init.d/php-fpm
  414. chkconfig --add php-fpm
  415. chkconfig php-fpm on
  416. /etc/init.d/php-fpm start >> $lamp_log
  417. cd ../
  418. cd memcache-3.0.6
  419. /usr/local/php/bin/phpize
  420. ./configure --with-php-config=/usr/local/php/bin/php-config
  421. make && make install >> $lamp_log
  422. cd ../
  423. cd eaccelerator-0.9.6.1/
  424. /usr/local/php/bin/phpize
  425. ./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
  426. make && make install >> $lamp_log
  427. cd ../
  428. cd PDO_MYSQL-1.0.2/
  429. /usr/local/php/bin/phpize
  430. ./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
  431. make && make install >> $lamp_log
  432. cd ../
  433. cd ImageMagick-6.6.9
  434. ./configure
  435. make && make install >> $lamp_log
  436. cd ../
  437. cd imagick-3.1.0b1/
  438. /usr/local/php/bin/phpize
  439. ./configure --with-php-config=/usr/local/php/bin/php-config
  440. make && make install >> $lamp_log
  441. ###zend configure#######
  442. bit=`uname -m`
  443. echo $bit
  444. if [ $bit == i686 ]
  445. then
  446. \cp /usr/local/src/ZendGuardLoader-php-5.3-linux-glibc23-i386/php-5.3.x/ZendGuardLoader.so /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/
  447. else
  448. \cp /usr/local/src/ZendGuardLoader-php-5.3-linux-glibc23-x86_64/php-5.3.x/ZendGuardLoader.so /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/
  449. fi
  450. sed -i 's#; extension_dir = "./"#extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/"\nextension = "memcache.so"\nextension = "pdo_mysql.so"\nextension = "imagick.so"\n#' /etc/php.ini
  451. sed -i 's#output_buffering = Off#output_buffering = On#' /etc/php.ini
  452. sed -i "s#; always_populate_raw_post_data = On#always_populate_raw_post_data = On#g" /etc/php.ini
  453. sed -i "s#; cgi.fix_pathinfo=0#cgi.fix_pathinfo=0#g" /etc/php.ini
  454. sed -i '/;date.timezone/c date.timezone = Asia/Shanghai' /etc/php.ini
  455. sed -i "s#magic_quotes_gpc = Off#magic_quotes_gpc = On#g" /etc/php.ini
  456. mkdir /usr/local/eaccelerator_cache > /dev/null 2>&1
  457. #############zend && eaccelerator opimization################
  458. cat >>/etc/php.ini<
  459. [eaccelerator]
  460. zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/eaccelerator.so"
  461. eaccelerator.shm_size="64"
  462. eaccelerator.cache_dir="/usr/local/eaccelerator_cache"
  463. eaccelerator.enable="1"
  464. eaccelerator.optimizer="1"
  465. eaccelerator.check_mtime="1"
  466. eaccelerator.debug="0"
  467. eaccelerator.filter=""
  468. eaccelerator.shm_max="0"
  469. eaccelerator.shm_ttl="3600"
  470. eaccelerator.shm_prune_period="3600"
  471. eaccelerator.shm_only="0"
  472. eaccelerator.compress="1"
  473. eaccelerator.compress_level="9"
  474. [Zend Optimizer]
  475. zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/ZendGuardLoader.so"
  476. zend_optimizer.optimization_level=1
  477. zend_optimizer.encoder_loader=0
  478. EOF
  479. echo "---test "nginx-php" status----" >> $lamp_log
  480. /usr/local/php/bin/php -v >> $lamp_log
  481. fi
  482. fi
  483. echo "CentOS/RadHat auto configure "
  484. echo "========================================================================="
  485. echo ""
  486. echo "For more information please visit http:///"
  487. echo ""
  488. echo "lnmp status manage:"
  489. echo " /etc/init.d/nginx {start|stop|reload|restart|kill|status}"
  490. echo " /etc/init.d/mysqld {start|stop|reload|restart|kill|status}"
  491. echo "phpinfo : "
  492. echo "default mysql root password:$mysqlrootpwd"
  493. echo "mysql security configure: mysql_secure_installation"
  494. echo "The path of some dirs:"
  495. echo "mysql dir: /usr/local/mysql"
  496. echo "php dir: /usr/local/php"
  497. echo "nginx dir: /usr/local/apache"
  498. echo "web dir : $webroot"
  499. echo "log dir : /var/logs"
  500. echo ""
  501. echo "========================================================================="
  502. }
  503. install_nginx() {
  504. echo "+------------------------------------------------------+"
  505. echo "+ We will install nginx service on the local computer +"
  506. echo "+------------------------------------------------------+"
  507. if [ -s "$INSTALL_SRC/nginx-1.0.4.tar.gz" ] && [ -d "$INSTALL_SRC/nginx-1.0.4" ];then
  508. echo " nginx-1.0.4.tar.gz [found]"
  509. cd $INSTALL_SRC/pcre-8.12
  510. ./configure
  511. make && make install >> $lamp_log
  512. cd ../
  513. cd nginx-1.0.4/
  514. #disable version
  515. sed -i 's/#define NGINX_VERSION "1.0.8"/#define NGINX_VERSION "1.8"/' src/core/nginx.h
  516. sed -i 's#nginx/#bitautotech/#' src/core/nginx.h
  517. sed -i 's#Server: nginx#Server: bitautotech#' src/http/ngx_http_header_filter_module.c
  518. sed -i '28s/nginx/bitautech/' src/http/ngx_http_special_response.c
  519. sed -i '21a \"
    http://
    " CRLF\' src/http/ngx_http_special_response.c
  520. ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
  521. make && make install >> $lamp_log
  522. if [ $? = 0 ];then
  523. mkdir -p /var/logs
  524. chown -R www:www /var/logs
  525. \cp /usr/local/src/nginx.conf /usr/local/nginx/conf/nginx.conf
  526. sed -i 's#root /data/webroot/bitauto#root '$webroot'#' /usr/local/nginx/conf/nginx.conf
  527. sed -i 's#server_name ;#server_name '$domain';#' /usr/local/nginx/conf/nginx.conf
  528. \cp /usr/local/src/nginx /etc/init.d/nginx
  529. chmod +x /etc/init.d/nginx
  530. chkconfig -add nginx
  531. chkconfig nginx on
  532. /etc/init.d/nginx start
  533. echo "---test nginx status----" >> $lamp_log
  534. /usr/local/nginx/sbin/nginx -t >> $lamp_log
  535. fi
  536. fi
  537. echo ""
  538. echo "=============================="
  539. echo " nginx install finished "
  540. echo "=============================="
  541. echo ""
  542. }
  543. #################################################################################
  544. #make the dialog menu
  545. dialog \
  546. --separate-output \
  547. --checklist " Linux auto configuration tool" \
  548. 20 60 15 \
  549. \
  550. 0 "Delete unwanted user and group" on \
  551. 1 "Change password limit(PASS_MIN_LEN=8)" on \
  552. 2 "Set auto loginout time(10min)" on \
  553. 3 "Remove Linux version infomation" on \
  554. 4 "Refused root ssh,Use SU" off \
  555. 5 "Stop Unnecessary Services" on \
  556. 6 "Optimize Kernel parameters" on \
  557. 7 "Change history limit(HISTSIZE=50)" on \
  558. 8 "Change ssh port(port 10001)" on \
  559. 9 "Lock Account file(passwd,shadow,group,gshadow...)" on \
  560. 10 "Chmod init.d rights(Permissions:700)" on \
  561. 11 "Remove SUID " on \
  562. 12 "Other Security Configure" on \
  563. 13 "Install and configure LAMP" off \
  564. 14 "Install and configure LNMP" off \
  565. 2>output
  566. in=$(
  567. echo $in
  568. #the function of confirm
  569. function Confirm()
  570. {
  571. #text height witdh
  572. dialog --yesno "Are you sure to configure ...?" 6 36
  573. if [ $? -eq 0 ]
  574. then
  575. isConfirmed=0
  576. return 0
  577. else
  578. isConfirmed=1
  579. return 1
  580. fi
  581. }
  582. #whether confirm of not
  583. if [ -n "$in" ]
  584. then
  585. Confirm
  586. if [ $? -eq 1 ]
  587. then
  588. clear
  589. exit 1
  590. fi
  591. fi
  592. #configure
  593. for i in $in
  594. do
  595. case $i in
  596. "0")
  597. echo "**********delete unwanted user and group...***********"
  598. for i in $V_DELUSER ;do
  599. echo "deleting $i";
  600. userdel $i ;
  601. done
  602. for i in $V_DELGROUP ;do
  603. echo "deleting $i";
  604. groupdel $i;
  605. done
  606. ;;
  607. "1")
  608. echo "**************change password limit ...***************"
  609. echo "/etc/login.defs"
  610. echo "PASS_MIN_LEN $V_PASSMINLEN"
  611. sed -i "/^PASS_MIN_LEN/s/5/$V_PASSMINLEN/" /etc/login.defs
  612. ;;
  613. "2")
  614. echo "**************change login timeout ...****************"
  615. echo "/etc/profile"
  616. echo "TMOUT=$V_TMOUT"
  617. sed -i "/^HISTSIZE/a\TMOUT=$V_TMOUT" /etc/profile
  618. ;;
  619. "3")
  620. echo "**************remove system version...****************"
  621. \cp /etc/issue /etc/issue.bak
  622. \cp /etc/issue.net /etc/issue.net.bak
  623. rm -f /etc/issue /etc/issue.net
  624. touch /etc/issue /etc/issue.net
  625. echo "cat /etc/issue"
  626. cat /etc/issue
  627. echo "cat /etc/issue.net"
  628. cat /etc/issue.net
  629. ;;
  630. "4")
  631. echo "*****************denied root login,use SU ...*****************"
  632. echo "/etc/ssh/sshd_config"
  633. echo "PermitRootLogin no"
  634. sed -i '/^#PermitRootLogin/s/#PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config
  635. ###set wheel group env#########
  636. sed -i '23c#if [ "$EUID" = "0" ]; then' /etc/profile
  637. sed -i '23agid=`/usr/bin/id -g`\nif [ $gid -eq 10 ];then' /etc/profile
  638. source /etc/profile
  639. chmod +w /etc/sudoers
  640. sed -i '93a %wheel ALL=(ALL) NOPASSWD: ALL' /etc/sudoers
  641. chmod -w /etc/sudoers
  642. ####create su user###
  643. useradd -g 10 bitnms
  644. echo bitauto123 |passwd --stdin "bitnms"
  645. /etc/init.d/sshd reload
  646. echo "permit $V_GROUPNAME use su ..."
  647. echo "/etc/pam.d/su"
  648. echo "auth sufficient /lib/security/pam_rootok.so debug"
  649. echo "auth required /lib/security/pam_wheel.so group=$V_GROUPNAME"
  650. if egrep "auth sufficient /lib/security/pam_rootok.so debug" /etc/pam.d/su > /dev/null
  651. then
  652. echo 'warning:existed'
  653. else
  654. echo 'auth sufficient /lib/security/pam_rootok.so debug' >> /etc/pam.d/su
  655. echo "auth required /lib/security/pam_wheel.so group=${V_GROUPNAME}" >> /etc/pam.d/su
  656. fi
  657. ;;
  658. "5")
  659. echo "**************close services autostart ...*************"
  660. for i in $V_SERVICE ;do
  661. chkconfig $i off;
  662. done
  663. ;;
  664. "6")
  665. echo "***************change kernel parameters****************"
  666. \cp /etc/sysctl.conf /etc/sysctl.conf.bak
  667. echo "net.ipv4.ip_local_port_range = 1024 65535" >> /etc/sysctl.conf
  668. echo "net.ipv4.tcp_fin_timeout = 30" >> /etc/sysctl.conf
  669. echo "net.ipv4.tcp_keepalive_time = 600" >> /etc/sysctl.conf
  670. echo "net.ipv4.tcp_tw_recycle = 1" >> /etc/sysctl.conf
  671. echo "net.ipv4.tcp_tw_reuse = 1" >> /etc/sysctl.conf
  672. cho "net.core.netdev_max_backlog = 30000" >> /etc/syscte.conf
  673. echo "net.ipv4.tcp_no_metrics_save = 1" >> /etc/sysctl.conf
  674. echo "net.core.somaxconn = 262144" >> /etc/sysctl.conf
  675. echo "net.ipv4.tcp_max_orphans = 8000" >> /etc/sysctl.conf
  676. echo "net.ipv4.tcp_max_syn_backlog = 10240" >> /etc/sysctl.conf
  677. echo "net.ipv4.tcp_synack_retries = 2" >> /etc/sysctl.conf
  678. echo "net.ipv4.tcp_syn_retries = 2" >> /etc/sysctl.conf
  679. echo "fs.file-max = 65535" >> /etc/sysctl.conf
  680. echo "modprobe ip_conntrack" >> /etc/rc.local
  681. modprobe ip_conntrack
  682. echo "nepv4.conf.all.send_redirectst.ipv4.netfilter.ip_conntrack_max = 655360" >> /etc/sysctl.conf
  683. echo "net.ipv4.netfilter.ip_conntrack_tcp_timeout_established = 600" >> /etc/sysctl.conf
  684. sysctl -p
  685. ;;
  686. "7")
  687. echo "************change history limit ...******************"
  688. echo "/etc/profile"
  689. echo "HISTSIZE $V_HISTSIZE"
  690. sed -i "/^HISTSIZE/s/1000/$V_HISTSIZE/" /etc/profile
  691. ;;
  692. "8")
  693. echo "*****************Change ssh port.*****************"
  694. echo "/etc/ssh/sshd_config"
  695. echo "Port 10001" >> /etc/ssh/sshd_config
  696. /etc/init.d/sshd reload
  697. ;;
  698. "9")
  699. echo "*****************lock user&services ...***************"
  700. echo "chattr +i /etc/passwd /etc/shadow /etc/group /etc/gshadow /etc/services"
  701. chattr +i /etc/passwd /etc/shadow /etc/group /etc/gshadow /etc/services
  702. ;;
  703. "10")
  704. echo "***********init script only for root ...**************"
  705. echo "chmod -R 700 /etc/init.d/*"
  706. echo "chmod 600 /etc/grub.conf"
  707. echo "chattr +i /etc/grub.conf"
  708. chmod -R 700 /etc/init.d/*
  709. chmod 600 /etc/grub.conf
  710. chattr +i /etc/grub.conf
  711. ;;
  712. "11")
  713. echo "******************remove SUID ...*********************"
  714. echo "/usr/bin/chage /usr/bin/gpasswd ..."
  715. for i in ${V_SUID[@]};
  716. do
  717. chmod a-s $i
  718. done
  719. ;;
  720. "12")
  721. echo "********************Other security set******************"
  722. echo "change tty in /etc/inittab"
  723. echo "#5:2345:respawn:/sbin/mingetty tty5"
  724. echo "#6:2345:respawn:/sbin/mingetty tty6"
  725. sed -i '/^[$V_TTY]:2345/s/^/#/' /etc/inittab
  726. echo "change /etc/host.conf"
  727. echo "order bind,hosts" > /etc/host.conf
  728. echo "multi on" >> /etc/host.conf
  729. echo "nospoof on" >> /etc/host.conf
  730. echo "close ctrl+alt+del to restart server ..."
  731. echo "/etc/inittab"
  732. echo "#ca::ctrlaltdel:/sbin/shutdown -t3 -r now"
  733. sed -i '/^ca::/s/^/#/' /etc/inittab
  734. ;;
  735. "13")
  736. echo "*******************LAMP******************"
  737. install_init
  738. install_mysql
  739. for soft in apache php ;do
  740. case $soft in
  741. apache)
  742. install_apache;;
  743. php)
  744. install_apache-php;;
  745. esac
  746. done
  747. ;;
  748. "14")
  749. echo "********************LNMP******************"
  750. install_init
  751. for soft in mysql nginx php;do
  752. case $soft in
  753. mysql)
  754. install_mysql;;
  755. nginx)
  756. install_nginx;;
  757. php)
  758. install_nginx-php;;
  759. esac
  760. done
  761. ;;
  762. esac
  763. done
阅读(1307) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~