歡迎您光臨本站 註冊首頁

模塊化的安裝lnmp腳本

←手機掃碼閱讀     火星人 @ 2014-03-08 , reply:0

最近公司的項目很多,研發那裡需要的測試環境很多,而且基本都是lnmp的測試環境(也有apache與tomcat,但非常少),測試沒有問題之後還需要上線,所以最近我很忙,而且都是重複性的工作,本來我用虛擬機安裝一個lnmp的環境,但研發說必須用真實機器進行測試,所以為了偷懶,我只能用lnmp的自動安裝腳本了,剛開始使用還可以,但很多的腳本里都不能設置安裝路徑、軟體也是老版本的,所以我又根據我自己的實際需要編寫了一份模塊化的安裝lnmp腳本.

此腳本可以需要單獨的安裝mysql、nginx、php,還可以選擇自動的安裝lnmp,並且安裝的目錄都可以自己設定,很簡單與智能化,其中我編寫腳本的時候,參考了linuxeye的 LNMP源碼安裝腳本(http://linuxeye.blog.51cto.com/4371937/773362),也參考了張宴的博客(http://blog.s135.com/nginx_php_v6).感謝他們的分享精神.

本腳本我已經在rhel 5.4 32與64位系統都進行了測試,沒有發現問題,並且我在生產環境里也使用了這個腳本,也沒有發現問題.

一、準備工作

1、把install_lnmp.tar.gz上傳的到伺服器(我傳輸的目錄是tmp) 解壓
  1. [root@localhost tmp]# tar zxf install_lnmp.tar.gz
查看install_lnmp.sh與soft是否解壓
  1. [root@localhost tmp]# ll
  2. total 64480
  3. -rwxr-xr-x 1 root root 13726 Mar 25 02:17 install_lnmp.sh
  4. -rw-r--r-- 1 root root 65911213 Mar 25 02:17 install_lnmp.tar.gz
  5. srwxr-xr-x 1 root root 0 Mar 23 14:19 mapping-root
  6. drwxr-xr-x 5 root root 4096 Mar 23 11:54 soft

  7. drwx------ 2 root root 4096 Mar 23 14:19 ssh-IMPTGZ3620
運行install_lnmp.sh
  1. [root@localhost tmp]# sh install_lnmp.sh
  2. Usage:install_lnmp.sh {install_yum|init|install_mysql|install_nginx|install_php|install_lnmp|install_check}
從輸出可以看出,可以使用install_yum、init、install_mysql等命令進行,下面介紹這些命令的含義 install_yum 如果本機的yum不能使用的時候,可以使用此命令 init 進行安裝所需的庫 install_mysql 進行mysql的安裝 install_nginx 進行nginx的安裝 install_php 進行php的安裝 install_lnmp 進行nginx、mysql、php與所需庫文件的安裝 install_check 進行檢查是否安裝nginx、mysql、php,並輸出安裝目錄 現在我們先進行檢查本機是否安裝了nginx、mysql、php,這裡使用install_check
  1. [root@localhost tmp]# sh install_lnmp.sh install_check
  2. Sun Mar 25 02:26:32 EDT 2012 Start install!
  3. ========================== Check install ================================
  4. Error: /usr/local/nginx not found!!!
  5. Error: /usr/local/php not found!!!
  6. Error: /usr/local/mysql not found!!!
  7. ========================== Check install ================================
  8. Sorry,Failed to install LNMP!
  9. Please check errors and logs.

  10. Sun Mar 25 02:26:32 EDT 2012 Finish install!
  11. Total runtime: 0 Seconds
從輸出可以看出,nginx、mysql、php都沒有安裝 在進行安裝的時候,可以使用nohup來進行後台的安裝,並且還有nohup.out目錄可以查看安裝的情況 二、腳本介紹 1、下載方法
  1. wget http://202.96.42.117/soft/ install_lnmp.tar.gz
  2. tar zxf install_lnmp.tar.gz

2、腳本中軟體的版本信息

  1. cmake-2.8.4.tar.gz
  2. mysql-5.5.10.tar.gz
  3. libiconv-1.13.1.tar.gz
  4. libmcrypt-2.5.8.tar.gz
  5. mhash-0.9.9.9.tar.gz
  6. mcrypt-2.6.8.tar.gz
  7. php-5.3.10.tar.gz
  8. memcache-2.2.5.tgz
  9. eaccelerator-0.9.6.1.tar.bz2
  10. PDO_MYSQL-1.0.2.tgz
  11. ImageMagick-6.6.7-10.tar.gz
  12. imagick-2.3.0.tgz
  13. pcre-8.12.tar.gz
  14. nginx-1.0.12.tar.gz
  15. ngx_cache_purge-1.3.tar.gz

3、腳本介紹

  1. #!/bin/bash
  2. #author dl528888
  3. #blog http://dl528888.blog.51cto.com
  4. LANG=C
  5. installhere="/data/software" #腳本與軟體包存放的地方

  6. nginx_dir="/usr/local/nginx" #nginx的安裝目錄
  7. php_dir="/usr/local/php" #php的安裝目錄
  8. mysql_dir="/usr/local/mysql" #mysql的安裝目錄
  9. mysql_datadir="/data/mysql/data" #mysql的數據存放目錄
  10. mysql_logdir="/data/mysql" #mysql的日誌目錄
  11. mysql_passwd="admin" #mysql的登陸密碼
  12. # Check if user is root #腳本需要在root用戶下運行,所以先進行用戶監測
  13. if [ $(id -u) != "0" ]; then
  14. echo "Error: You must be root to run this script, please use root to install soft"
  15. exit 1
  16. fi
  17. #Disable SeLinux #關閉selinux
  18. if [ -s /etc/selinux/config ]; then
  19. sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
  20. fi
  21. if [ ! -d "$installhere" ];then #如果腳本存放的目錄不存在,就自動的創建

  22. mkdir -p $installhere
  23. fi
  24. if [ ! -d "$installhere/soft" ];then #如果腳本不在那個存放的目錄里,則複製過去
  25. cp -a soft $installhere
  26. fi
  27. #set up runtime #進行運行時間的統計
  28. function start_time()
  29. {
  30. start_time="$(date %s)"
  31. echo "$(date) Start install!"
  32. echo "$start_time" > /tmp/Install_lnmp_runtime
  33. }
  34. function end_time()
  35. {
  36. end_time="$(date %s)"
  37. total_s=$(($end_time - $start_time))
  38. total_m=$(($total_s / 60))
  39. if [ $total_s -lt 60 ]; then
  40. time_en="${total_s} Seconds"
  41. else
  42. time_en="${total_m} Minutes"
  43. fi
  44. echo "$(date) Finish install!"
  45. echo "Install_lnmp.sh runtime: ${time_en} "> /tmp/Install_lnmp_runtime
  46. echo "Total runtime: ${time_en}"
  47. }
  48. #if yum fail,please use install_yum to solve. 如果yum不可用,可以使用此模塊來進行安裝yum
  49. function install_yum()
  50. {
  51. wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.1-1.el5.rf.i386.rpm
  52. wget http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
  53. rpm -Uvh rpmforge-release-0.5.1-1.el5.rf.i386.rpm
  54. rpm --import RPM-GPG-KEY.dag.txt
  55. yum -y install yum-fastestmirror yum-presto
  56. }
  57. #init set up Library 安裝lnmp需要的庫
  58. function init()
  59. {
  60. yum -y install yum-fastestmirror yum-presto
  61. yum -y install gcc gcc-c autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel openssl openssl-devel nss_ldap openldap openldap-devel openldap-clients openldap-servers libxslt-devel libevent-devel ntp libtool-ltdl bison libtool vim-enhanced
  62. }
  63. #install mysql 安裝mysql的模塊
  64. function install_mysql()
  65. {
  66. cd $installhere/soft/mysql/
  67. useradd -M -s /sbin/nologin mysql
  68. mkdir -p $mysql_datadir;
  69. chown mysql.mysql -R $mysql_datadir
  70. tar xzf cmake-2.8.4.tar.gz
  71. cd cmake-2.8.4

  72. ./configure
  73. make && make install
  74. cd ..
  75. tar zxf mysql-5.5.10.tar.gz
  76. cd mysql-5.5.10
  77. cmake . -DCMAKE_INSTALL_PREFIX=$mysql_dir/ \
  78. -DMYSQL_DATADIR=$mysql_datadir \
  79. -DMYSQL_UNIX_ADDR=$mysql_logdir/mysqld.sock \
  80. -DWITH_INNOBASE_STORAGE_ENGINE=1 \
  81. -DENABLED_LOCAL_INFILE=1 \
  82. -DMYSQL_TCP_PORT=3306 \
  83. -DCMAKE_THREAD_PREFER_PTHREAD=1 \
  84. -DEXTRA_CHARSETS=all \
  85. -DDEFAULT_CHARSET=utf8 \
  86. -DDEFAULT_COLLATION=utf8_general_ci \
  87. -DMYSQL_UNIX_ADDR=$mysql_logdir/mysql.sock \
  88. -DWITH_DEBUG=0
  89. make && make install
  90. rm -rf /etc/my.cnf
  91. rm -rf /etc/init.d/mysqld
  92. mkdir $mysql_logdir/relaylog
  93. mkdir $mysql_logdir/binlog
  94. cp $installhere/soft/mysql/my.cnf /etc/my.cnf
  95. cp support-files/mysql.server /etc/init.d/mysqld
  96. chmod 755 /etc/init.d/mysqld
  97. chkconfig --add mysqld
  98. chkconfig mysqld on
  99. chown mysql.mysql -R $mysql_logdir
  100. chown mysql.mysql -R $mysql_datadir
  101. $mysql_dir/scripts/mysql_install_db --user=mysql --basedir=$mysql_dir --datadir=$mysql_datadir
  102. /sbin/service mysqld start
  103. echo 'export PATH=$PATH:'$mysql_dir'/bin' >> /etc/profile
  104. $mysql_dir/bin/mysql -e "grant all privileges on *.* to root@'%' identified by '$mysql_passwd' with grant option;"
  105. $mysql_dir/bin/mysql -e "flush privileges;"
  106. $mysql_dir/bin/mysql -e "delete from mysql.user where password='';"
  107. source /etc/profile
  108. /sbin/service mysqld restart
  109. echo "mysql install success!"
  110. }
  111. #install php 安裝php的模塊
  112. function install_php()
  113. {
  114. cd $installhere/soft/php

  115. tar xzf libiconv-1.13.1.tar.gz
  116. cd libiconv-1.13.1
  117. ./configure --prefix=/usr/local
  118. make && make install
  119. cd ../
  120. tar xzf libmcrypt-2.5.8.tar.gz
  121. cd libmcrypt-2.5.8
  122. ./configure
  123. make && make install
  124. /sbin/ldconfig
  125. cd libltdl/
  126. ./configure --enable-ltdl-install
  127. make && make install
  128. cd ../../
  129. tar xzf mhash-0.9.9.9.tar.gz
  130. cd mhash-0.9.9.9
  131. ./configure
  132. make && make install
  133. cd ../
  134. if [ -e "/lib64" ];then
  135. ln -s /usr/local/lib/libmcrypt.la /usr/lib64/libmcrypt.la
  136. ln -s /usr/local/lib/libmcrypt.so /usr/lib64/libmcrypt.so
  137. ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib64/libmcrypt.so.4
  138. ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib64/libmcrypt.so.4.4.8
  139. ln -s /usr/local/lib/libmhash.a /usr/lib64/libmhash.a
  140. ln -s /usr/local/lib/libmhash.la /usr/lib64/libmhash.la
  141. ln -s /usr/local/lib/libmhash.so /usr/lib64/libmhash.so
  142. ln -s /usr/local/lib/libmhash.so.2 /usr/lib64/libmhash.so.2
  143. ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib64/libmhash.so.2.0.1
  144. ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config

  145. ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /lib64/libmysqlclient.so.18
  146. else
  147. ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
  148. ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
  149. ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
  150. ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
  151. ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
  152. ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
  153. ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
  154. ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
  155. ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
  156. ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
  157. ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /lib/libmysqlclient.so.18
  158. fi
  159. tar xzf mcrypt-2.6.8.tar.gz
  160. cd mcrypt-2.6.8
  161. /sbin/ldconfig
  162. ./configure
  163. make && make install
  164. cd ../
  165. ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib
  166. if [ `getconf WORD_BIT` = '32' ] && [ `getconf LONG_BIT` = '64' ] ; then
  167. ln -s /usr/lib64/libpng.* /usr/lib/
  168. ln -s /usr/lib64/libjpeg.* /usr/lib/
  169. fi
  170. if [ ! `grep -l "/lib" '/etc/ld.so.conf'` ]; then

  171. echo "/lib" >> /etc/ld.so.conf
  172. fi
  173. if [ ! `grep -l '/usr/lib' '/etc/ld.so.conf'` ]; then
  174. echo "/usr/lib" >> /etc/ld.so.conf
  175. fi
  176. if [ -d "/usr/lib64" ] && [ ! `grep -l '/usr/lib64' '/etc/ld.so.conf'` ]; then
  177. echo "/usr/lib64" >> /etc/ld.so.conf
  178. fi
  179. if [ ! `grep -l '/usr/local/lib' '/etc/ld.so.conf'` ]; then
  180. echo "/usr/local/lib" >> /etc/ld.so.conf
  181. fi
  182. /sbin/ldconfig
  183. tar xzf php-5.3.10.tar.gz
  184. useradd -M -s /sbin/nologin www
  185. cd php-5.3.10
  186. ./configure --prefix=$php_dir --with-mysql=$mysql_dir --with-mysqli=$mysql_dir/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-ftp --enable-zip --enable-soap --disable-debug

  187. make ZEND_EXTRA_LIBS='-liconv'
  188. make install
  189. cp php.ini-production $php_dir/lib/php.ini
  190. cd ../
  191. tar xzf memcache-2.2.5.tgz
  192. cd memcache-2.2.5
  193. $php_dir/bin/phpize
  194. ./configure --with-php-config=$php_dir/bin/php-config
  195. make && make install
  196. cd ../
  197. tar xjf eaccelerator-0.9.6.1.tar.bz2
  198. cd eaccelerator-0.9.6.1
  199. /usr/local/php/bin/phpize
  200. ./configure --enable-eaccelerator=shared --with-php-config=$php_dir/bin/php-config
  201. make && make install
  202. cd ../
  203. tar xzf PDO_MYSQL-1.0.2.tgz
  204. cd PDO_MYSQL-1.0.2
  205. $php_dir/bin/phpize
  206. ./configure --with-php-config=$php_dir/bin/php-config --with-pdo-mysql=$mysql_dir
  207. make && make install
  208. cd ../
  209. tar xzf ImageMagick-6.6.7-10.tar.gz
  210. cd ImageMagick-6.6.7-10
  211. ./configure
  212. make && make install
  213. cd ../
  214. tar xzf imagick-2.3.0.tgz

  215. cd imagick-2.3.0
  216. /usr/local/php/bin/phpize
  217. ./configure --with-php-config=$php_dir/bin/php-config
  218. make && make install
  219. cd ../
  220. #Modiry php.ini
  221. mkdir /tmp/eaccelerator
  222. /bin/chown -R www.www /tmp/eaccelerator/
  223. sed -i '808a extension_dir = "'$php_dir'/lib/php/extensions/no-debug-non-zts-20090626/"' $php_dir/lib/php.ini
  224. sed -i '809a extension = "memcache.so"' $php_dir/lib/php.ini
  225. sed -i '810a extension = "pdo_mysql.so"' $php_dir/lib/php.ini
  226. sed -i '811a extension = "imagick.so"' $php_dir/lib/php.ini
  227. sed -i '134a output_buffering = On' $php_dir/lib/php.ini
  228. sed -i '847a cgi.fix_pathinfo=0' $php_dir/lib/php.ini
  229. sed -i 's@;date.timezone =@date.timezone = Asia/Shanghai@g' $php_dir/lib/php.ini
  230. echo '[eaccelerator]

  231. zend_extension="'$php_dir'/lib/php/extensions/no-debug-non-zts-20090626/eaccelerator.so"
  232. eaccelerator.shm_size="64"
  233. eaccelerator.cache_dir="/tmp/eaccelerator"
  234. eaccelerator.enable="1"
  235. eaccelerator.optimizer="1"
  236. eaccelerator.check_mtime="1"
  237. eaccelerator.debug="0"
  238. eaccelerator.filter=""
  239. eaccelerator.shm_max="0"
  240. eaccelerator.shm_ttl="0"
  241. eaccelerator.shm_prune_period="0"
  242. eaccelerator.shm_only="0"
  243. eaccelerator.compress="0"

  244. eaccelerator.compress_level="9"
  245. eaccelerator.keys = "disk_only"
  246. eaccelerator.sessions = "disk_only"
  247. eaccelerator.content = "disk_only"' >> $php_dir/lib/php.ini
  248. echo ';;;;;;;;;;;;;;;;;;;;;
  249. ; FPM Configuration ;
  250. ;;;;;;;;;;;;;;;;;;;;;
  251. ;;;;;;;;;;;;;;;;;;
  252. ; Global Options ;
  253. ;;;;;;;;;;;;;;;;;;
  254. [global]
  255. pid = run/php-fpm.pid
  256. error_log = log/php-fpm.log
  257. log_level = notice
  258. emergency_restart_threshold = 30
  259. emergency_restart_interval = 1m
  260. process_control_timeout = 5s

  261. daemonize = yes
  262. ;;;;;;;;;;;;;;;;;;;;
  263. ; Pool Definitions ;
  264. ;;;;;;;;;;;;;;;;;;;;
  265. [www]
  266. listen = 127.0.0.1:9000
  267. listen.backlog = -1
  268. listen.allowed_clients = 127.0.0.1
  269. listen.owner = www
  270. listen.group = www
  271. listen.mode = 0666
  272. user = www
  273. group = www
  274. pm = dynamic
  275. pm.max_children = 32
  276. pm.start_servers = 4
  277. pm.min_spare_servers = 4

  278. pm.max_spare_servers = 16
  279. pm.max_requests = 512
  280. request_terminate_timeout = 0
  281. request_slowlog_timeout = 0
  282. slowlog = log/$pool.log.slow
  283. rlimit_files = 51200
  284. rlimit_core = 0
  285. catch_workers_output = yes
  286. env[HOSTNAME] = $HOSTNAME
  287. env[PATH] = /usr/local/bin:/usr/bin:/bin
  288. env[TMP] = /tmp
  289. env[TMPDIR] = /tmp
  290. env[TEMP] = /tmp ' >> $php_dir/etc/php-fpm.conf
  291. echo "$php_dir/sbin/php-fpm" >> /etc/rc.local
  292. $php_dir/sbin/php-fpm
  293. echo '<?
  294. phpinfo();
  295. ?>' >$nginx_dir/html/phpinfo.php

  296. echo "php install success!"
  297. }
  298. #install nginx 安裝nginx的模塊
  299. function install_nginx()
  300. {
  301. cd $installhere/soft/nginx
  302. tar xzf pcre-8.12.tar.gz
  303. cd pcre-8.12
  304. ./configure
  305. make && make install
  306. cd ../
  307. tar xzf ngx_cache_purge-1.3.tar.gz
  308. tar xzf nginx-1.0.12.tar.gz
  309. cd nginx-1.0.12
  310. #Modify nginx Edition information
  311. sed -i 's@#define NGINX_VERSION.*$@#define NGINX_VERSION "1.0"@g' src/core/nginx.h
  312. sed -i 's@#define NGINX_VER.*NGINX_VERSION$@#define NGINX_VER "YWS/" NGINX_VERSION@g' src/core/nginx.h
  313. ./configure --prefix=$nginx_dir --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --add-module=../ngx_cache_purge-1.3
  314. make && make install
  315. cd $installhere/soft/nginx/
  316. cp nginx.sh /etc/init.d/nginx
  317. chmod 755 /etc/init.d/nginx
  318. chkconfig --add nginx
  319. chkconfig nginx on
  320. rm -rf $nginx_dir/conf/nginx.conf
  321. cp nginx.conf $nginx_dir/conf/nginx.conf
  322. echo "ulimit -SHn 65535" >>/etc/rc.local
  323. echo "$nginx_dir/sbin/nginx" >> /etc/rc.local
  324. echo '#ADD
  325. net.ipv4.tcp_max_syn_backlog = 65536
  326. net.core.netdev_max_backlog = 32768
  327. net.core.somaxconn = 32768
  328. net.core.wmem_default = 8388608
  329. net.core.rmem_default = 8388608
  330. net.core.rmem_max = 16777216
  331. net.core.wmem_max = 16777216
  332. net.ipv4.tcp_timestamps = 0
  333. net.ipv4.tcp_synack_retries = 2
  334. net.ipv4.tcp_syn_retries = 2
  335. net.ipv4.tcp_tw_recycle = 1

  336. #net.ipv4.tcp_tw_len = 1
  337. net.ipv4.tcp_tw_reuse = 1
  338. net.ipv4.tcp_mem = 94500000 915000000 927000000
  339. net.ipv4.tcp_max_orphans = 3276800
  340. #net.ipv4.tcp_fin_timeout = 30
  341. #net.ipv4.tcp_keepalive_time = 120
  342. net.ipv4.ip_local_port_range = 1024 65535' >>/etc/sysctl.conf
  343. /sbin/sysctl -p
  344. echo '#!/bin/bash
  345. # This script run at 00:00
  346. # The Nginx logs path
  347. logs_path="'$nginx_dir'/logs/"
  348. mkdir -p ${logs_path}$(date -d "yesterday" "%Y")/$(date -d "yesterday" "%m")/
  349. mv ${logs_path}access.log ${logs_path}$(date -d "yesterday" "%Y")/$(date -d "yesterday" "%m")/access_$(date -d "yesterday" "%Y%m%d").log

  350. kill -USR1 `cat '$nginx_dir'/nginx.pid` '>>$nginx_dir/sbin/cut_nginx_log.sh
  351. chmod 755 $nginx_dir/sbin/cut_nginx_log.sh
  352. echo "00 00 * * * /bin/bash $nginx_dir/sbin/cut_nginx_log.sh" >> /var/spool/cron/root
  353. $nginx_dir/sbin/nginx
  354. echo "nginx install success!"
  355. }
  356. #check install 檢測模塊
  357. function install_check()
  358. {
  359. echo "========================== Check install ================================"
  360. clear
  361. if [ -s $nginx_dir ]; then
  362. echo "$nginx_dir [found]"
  363. else
  364. echo "Error: $nginx_dir not found!!!"
  365. fi
  366. if [ -s $php_dir ]; then
  367. echo "$php_dir [found]"
  368. else
  369. echo "Error: $php_dir not found!!!"
  370. fi
  371. if [ -s $mysql_dir ]; then
  372. echo "$mysql_dir [found]"
  373. else
  374. echo "Error: $mysql_dir not found!!!"
  375. fi
  376. echo "========================== Check install ================================"

  377. if [ -s $nginx_dir ] && [ -s $php_dir ] && [ -s $mysql_dir ]; then
  378. echo "LNMP is completed! "
  379. echo "default mysql root password:$mysql_passwd"
  380. echo "The path of some dirs:"
  381. echo "mysql dir: $mysql_dir"
  382. echo "php dir: $php_dir"
  383. echo "php info: $nginx_dir/html/phpinfo.php"
  384. echo "nginx dir: $nginx_dir"
  385. echo "web dir : $nginx_dir/html"
  386. echo "=========================================================================="
  387. else
  388. echo "Sorry,Failed to install LNMP!"
  389. echo "Please check errors and logs."
  390. fi
  391. }
  392. case $1 in
  393. install_yum)
  394. install_yum
  395. ;;
  396. init)
  397. start_time
  398. init
  399. end_time
  400. ;;
  401. install_mysql)
  402. start_time
  403. install_mysql
  404. end_time
  405. ;;
  406. install_nginx)
  407. start_time
  408. install_nginx
  409. end_time
  410. ;;
  411. install_php)
  412. start_time

  413. install_php
  414. end_time
  415. ;;
  416. install_lnmp)
  417. start_time
  418. init
  419. install_mysql
  420. install_nginx
  421. install_php
  422. end_time
  423. ;;
  424. install_check)
  425. start_time
  426. install_check
  427. end_time
  428. ;;
  429. *)
  430. echo "Usage:`basename $0` {install_yum|init|install_mysql|install_nginx|install_php|install_lnmp|install_check}"
  431. ;;
  432. esac
三、安裝 現在進行lnmp的安裝(使用nohup)
  1. [root@localhost tmp]# nohup sh install_lnmp.sh install_lnmp &
  2. [1] 6861
  3. [root@localhost tmp]# nohup: appending output to `nohup.out'
可以看到安裝已經在後台進行,並且安裝情況都輸出到nohup.out里了 現在就是漫長的等待了......
  1. [root@localhost tmp]#
  2. [1] Done nohup sh install_lnmp.sh install_lnmp

結果可以看到腳本運行完成

現在可以看出腳本運行完成,我們查看一下日誌
  1. [root@localhost tmp]# tail -f nohup.out
  2. net.ipv4.tcp_synack_retries = 2
  3. net.ipv4.tcp_syn_retries

    = 2
  4. net.ipv4.tcp_tw_recycle = 1
  5. net.ipv4.tcp_tw_reuse = 1
  6. net.ipv4.tcp_mem = 94500000 915000000 927000000
  7. net.ipv4.tcp_max_orphans = 3276800
  8. net.ipv4.ip_local_port_range = 1024 65535
  9. nginx install success!
  10. Sun Mar 25 03:47:26 EDT 2012 Finish install!
  11. Total runtime: 68 Minutes
可以看到安裝運行了68分鐘(我在腳本里設置了運行時間,所以可以幫助我們觀察腳本運行的時間). 四、檢測 分別查看msyql、 nginx、php是否啟動
  1. [root@localhost tmp]# ps -ef|grep mysql
  2. root 9337 3848 0 03:49 pts/2 00:00:00 grep mysql
  3. root 25402 1 0 03:09 pts/2 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql/data --pid-file=/data/mysql/mysql.pid
  4. mysql 26280 25402 0 03:09 pts/2 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin

    --user=mysql --log-error=/data/mysql/mysql_error.log --open-files-limit=10240 --pid-file=/data/mysql/mysql.pid --socket=/tmp/mysql.sock --port=3306
  5. [root@localhost tmp]# ps -ef|grep nginx
  6. root 9321 1 0 03:47 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
  7. www 9322 9321 0 03:47 ? 00:00:00 nginx: worker process
  8. www 9325 9321 0 03:47 ? 00:00:00 nginx: worker process
  9. www 9326 9321 0 03:47 ? 00:00:00 nginx: worker process
  10. www 9327 9321 0 03:47 ? 00:00:00 nginx: worker process
  11. www 9328 9321 0 03:47 ? 00:00:00 nginx: worker process
  12. www 9329 9321 0 03:47 ? 00:00:00 nginx: worker process
  13. www 9330 9321 0 03:47 ? 00:00:00 nginx: worker process
  14. www 9331 9321 0 03:47 ? 00:00:00 nginx: worker process
  15. root 9339 3848 0 03:49 pts/2 00:00:00 grep nginx
  16. [root@localhost tmp]# ps -ef|grep php
  17. root 3431 1 0 03:45 ? 00:00:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
  18. www 3432 3431 0 03:45 ? 00:00:00 php-fpm: pool www

  19. www 3433 3431 0 03:45 ? 00:00:00 php-fpm: pool www
  20. www 3434 3431 0 03:45 ? 00:00:00 php-fpm: pool www
  21. www 3435 3431 0 03:45 ? 00:00:00 php-fpm: pool www
  22. root 9341 3848 0 03:49 pts/2 00:00:00 grep php
從輸出可以看到,mysql、php、nginx都已經啟動了,我們在網頁里查看一下nginx與phpinfo.php 網頁能打開,證明nginx安裝成功

可以看到php也已經安裝完成

下面我們在來通過install_check來檢查lnmp是否安裝完成

  1. [root@localhost tmp]# sh install_lnmp.sh install_check
  2. Sun Mar 25 04:04:24 EDT 2012 Start install!
  3. ========================== Check install ================================
  4. /usr/local/nginx [found]
  5. /usr/local/php [found]
  6. /usr/local/mysql [found]
  7. ========================== Check install ================================
  8. LNMP is completed!
  9. default mysql root password:admin
  10. The path of some dirs:
  11. mysql dir: /usr/local/mysql
  12. php dir: /usr/local/php
  13. php info: /usr/local/nginx/html/phpinfo.php
  14. nginx dir: /usr/local/nginx
  15. web dir : /usr/local/nginx/html
  16. ==========================================================================

  17. Sun Mar 25 04:04:24 EDT 2012 Finish install!
  18. Total runtime: 0 Seconds

可以看到,lnmp已經安裝完成.

希望大家能在使用本腳本過程中幫我進行糾錯與建議,謝謝!

BTW:感謝9樓小愚的建議,我經過測試發現是有他所說的問題出現,現在我已經把腳本修改了一下,修改內容為cp php.ini到$php_dir/lib目錄下.

希望能與小愚及各位同好一起交流、學習!

本文出自 「吟—技術交流」 博客,請務必保留此出處http://dl528888.blog.51cto.com/2382721/816542


[火星人 ] 模塊化的安裝lnmp腳本已經有617次圍觀

http://coctec.com/docs/linux/show-post-46308.html