找回密码
 用户注册

QQ登录

只需一步,快速开始

查看: 3700|回复: 0

LNMP源码安装脚本 - 一键安装

[复制链接]
发表于 2012-2-7 10:28:57 | 显示全部楼层 |阅读模式
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://linuxeye.blog.51cto.com/4371937/773362
脚本中开源软件版本:

  • cmake-2.8.4.tar.gz
  • mysql-5.5.10.tar.gz
  • libiconv-1.13.1.tar.gz
  • libmcrypt-2.5.8.tar.gz
  • mhash-0.9.9.9.tar.gz
  • mcrypt-2.6.8.tar.gz
  • php-5.3.8.tar.gz
  • memcache-2.2.5.tgz
  • eaccelerator-0.9.6.1.tar.bz2
  • PDO_MYSQL-1.0.2.tgz
  • ImageMagick-6.6.7-10.tar.gz
  • imagick-2.3.0.tgz
  • pcre-8.12.tar.gz
  • nginx-1.0.11.tar.gz(最新稳定版)
  • ngx_cache_purge-1.3.tar.gz
使用方法:
说明:
参考张宴博客(http://blog.s135.com/nginx_php_v6),本人在CentOS 5(32位或者64位)上测试通过,并且在线上使用这个脚本。
脚本内容:

  1. #!/bin/bash
  2. #by LinuxEye
  3. #BLOG: http://blog.linuxeye.com
  4. 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
  5. #安装mysql-5.5.10
  6. if [ -e "/root/lnmp" ];then
  7. echo -e "\e[0;34m start install\e[0m"
  8. cd /root/lnmp/mysql/
  9. else
  10. echo -e "\e[1;31mPlease send lnmp directory moved to /root\e[0m"
  11. exit 1
  12. fi
  13.   
  14. useradd -M -s /sbin/nologin mysql
  15. mkdir -p /data/mysql;chown mysql.mysql -R /data/mysql
  16. tar xzf cmake-2.8.4.tar.gz
  17. cd cmake-2.8.4
  18. ./configure
  19. make &&  make install
  20. cd ..
  21. tar zxf mysql-5.5.10.tar.gz
  22. cd mysql-5.5.10
  23. cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ \
  24. -DMYSQL_DATADIR=/data/mysql  \
  25. -DMYSQL_UNIX_ADDR=/data/mysql/mysqld.sock \
  26. -DWITH_INNOBASE_STORAGE_ENGINE=1 \
  27. -DENABLED_LOCAL_INFILE=1 \
  28. -DMYSQL_TCP_PORT=3306 \
  29. -DCMAKE_THREAD_PREFER_PTHREAD=1 \
  30. -DEXTRA_CHARSETS=all \
  31. -DDEFAULT_CHARSET=utf8 \
  32. -DDEFAULT_COLLATION=utf8_general_ci \
  33. -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \
  34. -DWITH_DEBUG=0
  35. make && make install
  36.   
  37. cp support-files/my-medium.cnf /etc/my.cnf
  38. cp support-files/mysql.server /etc/init.d/mysqld
  39. chmod 755 /etc/init.d/mysqld
  40. chkconfig --add mysqld
  41. chkconfig mysqld on
  42. #修改配置文件
  43. sed -i '38a ##############' /etc/my.cnf
  44. sed -i '39a skip-name-resolve' /etc/my.cnf
  45. sed -i '40a basedir=/usr/local/mysql' /etc/my.cnf
  46. sed -i '41a datadir=/data/mysql' /etc/my.cnf
  47. sed -i '42a user=mysql' /etc/my.cnf
  48. sed -i '43a #lower_case_table_names = 1' /etc/my.cnf
  49. sed -i '44a max_connections=1000' /etc/my.cnf
  50. sed -i '45a ft_min_word_len=1' /etc/my.cnf
  51. sed -i '46a expire_logs_days = 7' /etc/my.cnf
  52. sed -i '47a query_cache_size=64M' /etc/my.cnf
  53. sed -i '48a query_cache_type=1' /etc/my.cnf
  54. sed -i '49a ##############' /etc/my.cnf
  55.   
  56. /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql
  57.   
  58. chown mysql.mysql -R /data/mysql
  59. /sbin/service mysqld start
  60. echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile
  61. source /etc/profile
  62.   
  63. /usr/local/mysql/bin/mysql -e "grant all privileges on *.* to root@'%' identified by 'admin' with grant option;"
  64. /usr/local/mysql/bin/mysql -e "flush privileges;"
  65. /usr/local/mysql/bin/mysql -e "delete from mysql.user where password='';"
  66.   
  67. #php安装
  68. cd /root/lnmp/php
  69. tar xzf libiconv-1.13.1.tar.gz
  70. cd libiconv-1.13.1
  71. ./configure --prefix=/usr/local
  72. make && make install
  73.   
  74. cd ../
  75. tar xzf libmcrypt-2.5.8.tar.gz
  76. cd libmcrypt-2.5.8
  77. ./configure
  78. make && make install
  79. /sbin/ldconfig
  80. cd libltdl/
  81. ./configure --enable-ltdl-install
  82. make && make install
  83. cd ../../
  84.   
  85. tar xzf mhash-0.9.9.9.tar.gz
  86. cd mhash-0.9.9.9
  87. ./configure
  88. make && make install
  89. cd ../
  90.   
  91. if [ -e "/lib64" ];then
  92. ln -s /usr/local/lib/libmcrypt.la /usr/lib64/libmcrypt.la
  93. ln -s /usr/local/lib/libmcrypt.so /usr/lib64/libmcrypt.so
  94. ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib64/libmcrypt.so.4
  95. ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib64/libmcrypt.so.4.4.8
  96. ln -s /usr/local/lib/libmhash.a /usr/lib64/libmhash.a
  97. ln -s /usr/local/lib/libmhash.la /usr/lib64/libmhash.la
  98. ln -s /usr/local/lib/libmhash.so /usr/lib64/libmhash.so
  99. ln -s /usr/local/lib/libmhash.so.2 /usr/lib64/libmhash.so.2
  100. ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib64/libmhash.so.2.0.1
  101. ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
  102. ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /lib64/libmysqlclient.so.18
  103. else
  104. ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
  105. ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
  106. ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
  107. ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
  108. ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
  109. ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
  110. ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
  111. ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
  112. ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
  113. ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
  114. ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /lib/libmysqlclient.so.18
  115. fi
  116.   
  117. tar xzf mcrypt-2.6.8.tar.gz
  118. cd mcrypt-2.6.8
  119. /sbin/ldconfig
  120. ./configure
  121. make && make install
  122. cd ../
  123.   
  124. tar xzf php-5.3.8.tar.gz
  125. useradd -M -s /sbin/nologin www
  126. cd php-5.3.8
  127. ./configure  --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --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 --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --enable-fpm
  128.   
  129. make ZEND_EXTRA_LIBS='-liconv'
  130. make install
  131. cp php.ini-production /usr/local/php/lib/php.ini
  132. cd ../
  133.   
  134. tar xzf memcache-2.2.5.tgz
  135. cd memcache-2.2.5
  136. /usr/local/php/bin/phpize
  137. ./configure --with-php-config=/usr/local/php/bin/php-config
  138. make && make install
  139. cd ../
  140.   
  141. tar xjf eaccelerator-0.9.6.1.tar.bz2
  142. cd eaccelerator-0.9.6.1
  143. /usr/local/php/bin/phpize
  144. ./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
  145. make && make install
  146. cd ../
  147.   
  148. tar xzf PDO_MYSQL-1.0.2.tgz
  149. cd PDO_MYSQL-1.0.2
  150. /usr/local/php/bin/phpize
  151. ./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
  152. make && make install
  153. cd ../
  154.   
  155. tar xzf ImageMagick-6.6.7-10.tar.gz
  156. cd ImageMagick-6.6.7-10
  157. ./configure
  158. make && make install
  159. cd ../
  160.   
  161. tar xzf imagick-2.3.0.tgz
  162. cd imagick-2.3.0
  163. /usr/local/php/bin/phpize
  164. ./configure --with-php-config=/usr/local/php/bin/php-config
  165. make && make install
  166. cd ../
  167. #修改php.ini
  168. mkdir /tmp/eaccelerator
  169. /bin/chown -R www.www /tmp/eaccelerator/
  170. sed -i '808a extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/"' /usr/local/php/lib/php.ini
  171. sed -i '809a extension = "memcache.so"' /usr/local/php/lib/php.ini
  172. sed -i '810a ;extension = "pdo_mysql.so"' /usr/local/php/lib/php.ini
  173. sed -i '811a extension = "imagick.so"' /usr/local/php/lib/php.ini
  174. sed -i '134a output_buffering = On' /usr/local/php/lib/php.ini
  175. sed -i '847a cgi.fix_pathinfo=0' /usr/local/php/lib/php.ini
  176. sed -i '999a date.timezone = Asia/Shanghai' /usr/local/php/lib/php.ini
  177. echo '[eaccelerator]
  178. zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/eaccelerator.so"
  179. eaccelerator.shm_size="64"
  180. eaccelerator.cache_dir="/tmp/eaccelerator"
  181. eaccelerator.enable="1"
  182. eaccelerator.optimizer="1"
  183. eaccelerator.check_mtime="1"
  184. eaccelerator.debug="0"
  185. eaccelerator.filter=""
  186. eaccelerator.shm_max="0"
  187. eaccelerator.shm_ttl="0"
  188. eaccelerator.shm_prune_period="0"
  189. eaccelerator.shm_only="0"
  190. eaccelerator.compress="0"
  191. eaccelerator.compress_level="9"
  192. eaccelerator.keys = "disk_only"
  193. eaccelerator.sessions = "disk_only"
  194. eaccelerator.content = "disk_only"' >> /usr/local/php/lib/php.ini
  195.   
  196. cat > /usr/local/php/etc/php-fpm.conf <<EOF
  197. ;;;;;;;;;;;;;;;;;;;;;
  198. ; FPM Configuration ;
  199. ;;;;;;;;;;;;;;;;;;;;;
  200.   
  201. ;;;;;;;;;;;;;;;;;;
  202. ; Global Options ;
  203. ;;;;;;;;;;;;;;;;;;
  204.   
  205. [global]
  206. pid = run/php-fpm.pid
  207. error_log = log/php-fpm.log
  208. log_level = notice
  209.   
  210. emergency_restart_threshold = 30
  211. emergency_restart_interval = 1m
  212. process_control_timeout = 5s
  213. daemonize = yes
  214.   
  215. ;;;;;;;;;;;;;;;;;;;;
  216. ; Pool Definitions ;
  217. ;;;;;;;;;;;;;;;;;;;;
  218.   
  219. [www]
  220.   
  221. listen = 127.0.0.1:9000
  222. listen.backlog = -1
  223. listen.allowed_clients = 127.0.0.1
  224. listen.owner = www
  225. listen.group = www
  226. listen.mode = 0666
  227. user = www
  228. group = www
  229.   
  230. pm = dynamic
  231. pm.max_children = 32
  232. pm.start_servers = 4
  233. pm.min_spare_servers = 4
  234. pm.max_spare_servers = 16
  235. pm.max_requests = 512
  236.   
  237. request_terminate_timeout = 0
  238. request_slowlog_timeout = 0
  239.   
  240. slowlog = log/$pool.log.slow
  241. rlimit_files = 51200
  242. rlimit_core = 0
  243.   
  244. catch_workers_output = yes
  245. env[HOSTNAME] = $HOSTNAME
  246. env[PATH] = /usr/local/bin:/usr/bin:/bin
  247. env[TMP] = /tmp
  248. env[TMPDIR] = /tmp
  249. env[TEMP] = /tmp
  250. EOF
  251.   
  252. echo '/usr/local/php/sbin/php-fpm' >> /etc/rc.local
  253. /usr/local/php/sbin/php-fpm
  254.   
  255. #安装nginx
  256. mkdir /root/lnmp/nginx
  257. cd /root/lnmp/nginx
  258. tar xzf pcre-8.12.tar.gz
  259. cd pcre-8.12
  260. ./configure
  261. make && make install
  262. cd ../
  263. tar xzf ngx_cache_purge-1.3.tar.gz
  264. tar xzf nginx-1.0.11.tar.gz
  265. cd nginx-1.0.11
  266. #修改版本信息
  267. sed -i 's@#define NGINX_VERSION.*$@#define NGINX_VERSION      "1.0"@g' src/core/nginx.h
  268. sed -i 's@#define NGINX_VER.*NGINX_VERSION$@#define NGINX_VER          "YWS/" NGINX_VERSION@g' src/core/nginx.h
  269. ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --add-module=../ngx_cache_purge-1.3
  270. make && make install
  271. cd /root/lnmp/nginx/
  272. cp nginx.sh /etc/init.d/nginx
  273. chmod 755 /etc/init.d/nginx
  274. chkconfig --add nginx
  275. chkconfig nginx on
  276. rm -rf /usr/local/nginx/conf/nginx.conf
  277. cp nginx.conf /usr/local/nginx.conf
  278. echo "LNMP安装成功"
  279. echo "请按实际需求nginx.conf文件"
复制代码

本文出自 “linux运维笔记” 博客,请务必保留此出处http://linuxeye.blog.51cto.com/4371937/773362

您需要登录后才可以回帖 登录 | 用户注册

本版积分规则

Archiver|手机版|小黑屋|ACE Developer ( 京ICP备06055248号 )

GMT+8, 2024-4-30 14:28 , Processed in 0.012838 second(s), 5 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表