资讯专栏INFORMATION COLUMN

LTMP手动编译安装以及全自动化部署实践

HelKyle / 2096人阅读

摘要:我自己是从商业化环境走出来的,对于开源的部署方案也是在一点一点摸索,我相信其中也必然包含某些坑爹的配置。设置为表示当经常出现错误时可以尝试更改此选项。设置环境变量添加服务设置开机自动启动服务配置其它扩展都可以动态添加,没事的

前言

现在很多朋友都了解或者已经在使用LNMP架构,一般可以理解为Linux Shell为CentOS/RadHat/Fedora/Debian/Ubuntu/等平台安装LNMP(Nginx/MySQL/PHP),LNMPA(Nginx/MySQL/PHP/Apache),LAMP(Apache/MySQL/PHP)等类似的开发或生产环境。我自己是从SuSE/Oracle商业化环境走出来的,对于开源的部署方案也是在一点一点摸索,我相信其中也必然包含某些坑爹的配置。这篇文章较为详细的描述了基于LTMP架构的部署过程,之后会再考虑独立各个模块分享细节和技巧,如果大家有更合适的配置实践手册欢迎一起分享,文章中的错误和改进点也请帮忙指点下哈。

</>复制代码

  1. LTMP(CentOS/Tengine/MySQL/PHP)


更新历史

2015年08月04日 - 初稿

阅读原文 - http://wsgzao.github.io/post/ltmp/

扩展阅读

CentOS - http://www.centos.org/
Tengine - http://tengine.taobao.org/
Nginx - http://nginx.org/en/docs/
MySQL - http://www.mysql.com/
PHP - http://php.net/


LTMP版本

CentOS_6.5_64

Tengine-2.1.0

MySQL_5.6.25

PHP_5.5.27

Apache_2.2.31(酱油)

准备工作

</>复制代码

  1. 如果允许公网访问会方便很多

</>复制代码

  1. bash#优化History历史记录
  2. vi /etc/bashrc
  3. #设置保存历史命令的文件大小
  4. export HISTFILESIZE=1000000000
  5. #保存历史命令条数
  6. export HISTSIZE=1000000
  7. #实时记录历史命令,默认只有在用户退出之后才会统一记录,很容易造成多个用户间的相互覆盖。
  8. export PROMPT_COMMAND="history -a"
  9. #记录每条历史命令的执行时间
  10. export HISTTIMEFORMAT="%Y-%m-%d_%H:%M:%S "
  11. #设置时区(可选)
  12. rm -rf /etc/localtime
  13. ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
  14. #禁用NetworkManager(可选)
  15. /etc/init.d/NetworkManager stop
  16. chkconfig NetworkManager off
  17. /etc/init.d/network restart
  18. #关闭iptables(可选)
  19. /etc/init.d/iptables stop
  20. chkconfig iptables off
  21. #设置dns(可选)
  22. echo "nameserver 114.114.114.114" > /etc/resolv.conf
  23. #关闭maildrop
  24. #cd /var/spool/postfix/maildrop;ls | xargs rm -rf;
  25. sed "s/MAILTO=root/MAILTO=""/g" /etc/crontab
  26. service crond restart
  27. #关闭selinux
  28. setenforce 0
  29. sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config
  30. #文件打开数量,
  31. echo ulimit -SHn 65535 >> /etc/profile
  32. source /etc/profile
  33. #修改最大进程和最大文件打开数限制
  34. vi /etc/security/limits.conf
  35. * soft nproc 11000
  36. * hard nproc 11000
  37. * soft nofile 655350
  38. * hard nofile 655350
  39. sed -i -e "/# End of file/i* soft nofile 65535
  40. * hard nofile 65535" /etc/security/limits.conf
  41. #优化TCP
  42. vi /etc/sysctl.conf
  43. net.ipv4.ip_forward = 0
  44. net.ipv4.conf.default.rp_filter = 1
  45. net.ipv4.conf.default.accept_source_route = 0
  46. kernel.sysrq = 0
  47. kernel.core_uses_pid = 1
  48. #开启SYN Cookies,当出现SYN等待队列溢出时,启用cookies来处理
  49. net.ipv4.tcp_syncookies = 1
  50. kernel.msgmnb = 65536
  51. kernel.msgmax = 65536
  52. kernel.shmmax = 68719476736
  53. kernel.shmall = 4294967296
  54. #timewait的数量,默认是180000
  55. net.ipv4.tcp_max_tw_buckets = 6000
  56. net.ipv4.tcp_sack = 1
  57. net.ipv4.tcp_window_scaling = 1
  58. net.ipv4.tcp_rmem = 4096 87380 4194304
  59. net.ipv4.tcp_wmem = 4096 16384 4194304
  60. net.core.wmem_default = 8388608
  61. net.core.rmem_default = 8388608
  62. net.core.rmem_max = 16777216
  63. net.core.wmem_max = 16777216
  64. #每个网络接口接收数据包的速率比内核处理这些包的速率快时,允许送到队列的数据包的最大数目
  65. net.core.netdev_max_backlog = 262144
  66. #web应用中listen函数的backlog默认会给我们内核参数的net.core.somaxconn限制到128,而nginx定义的NGX_LISTEN_BACKLOG默认为511,所以有必要调整这个值
  67. net.core.somaxconn = 262144
  68. #系统中最多有多少个TCP套接字不被关联到任何一个用户文件句柄上。如果超过这个数字,孤儿连接将即刻被复位并打印出警告信息。这个限制仅仅是为了防止简单的DoS攻击,不能过分依靠它或者人为地减小这个值,更应该增加这个值(如果增加了内存之后)
  69. net.ipv4.tcp_max_orphans = 3276800
  70. #记录的那些尚未收到客户端确认信息的连接请求的最大值。对于有128M内存的系统而言,缺省值是1024,小内存的系统则是128
  71. net.ipv4.tcp_max_syn_backlog = 262144
  72. #时间戳可以避免序列号的卷绕。一个1Gbps的链路肯定会遇到以前用过的序列号。时间戳能够让内核接受这种“异常”的数据包。这里需要将其关掉
  73. net.ipv4.tcp_timestamps = 0
  74. #为了打开对端的连接,内核需要发送一个SYN并附带一个回应前面一个SYN的ACK。也就是所谓三次握手中的第二次握手。这个设置决定了内核放弃连接之前发送SYN+ACK包的数量
  75. net.ipv4.tcp_synack_retries = 1
  76. #在内核放弃建立连接之前发送SYN包的数量
  77. net.ipv4.tcp_syn_retries = 1
  78. #启用timewait快速回收
  79. net.ipv4.tcp_tw_recycle = 1
  80. #开启重用,允许将TIME-WAIT sockets重新用于新的TCP连接
  81. net.ipv4.tcp_tw_reuse = 1
  82. net.ipv4.tcp_mem = 94500000 915000000 927000000
  83. #如果套接字由本端要求关闭,这个参数决定了它保持在FIN-WAIT-2状态的时间。对端可以出错并永远不关闭连接,甚至意外当机。缺省值是60 秒。2.2 内核的通常值是180秒,你可以按这个设置,但要记住的是,即使你的机器是一个轻载的WEB服务器,也有因为大量的死套接字而内存溢出的风险,FIN- WAIT-2的危险性比FIN-WAIT-1要小,因为它最多只能吃掉1.5K内存,但是它们的生存期长些。
  84. net.ipv4.tcp_fin_timeout = 1
  85. #当keepalive起用的时候,TCP发送keepalive消息的频度。缺省是2小时。
  86. net.ipv4.tcp_keepalive_time = 30
  87. #允许系统打开的端口范围
  88. net.ipv4.ip_local_port_range = 1024 65000
  89. #表示文件句柄的最大数量
  90. fs.file-max = 102400
  91. #云主机上的优化
  92. # Kernel sysctl configuration file for Red Hat Linux
  93. #
  94. # For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and
  95. # sysctl.conf(5) for more details.
  96. # Controls IP packet forwarding
  97. net.ipv4.ip_forward = 0
  98. # Controls source route verification
  99. net.ipv4.conf.default.rp_filter = 1
  100. # Do not accept source routing
  101. net.ipv4.conf.default.accept_source_route = 0
  102. # Controls the System Request debugging functionality of the kernel
  103. # Controls whether core dumps will append the PID to the core filename.
  104. # Useful for debugging multi-threaded applications.
  105. kernel.core_uses_pid = 1
  106. # Controls the use of TCP syncookies
  107. net.ipv4.tcp_syncookies = 1
  108. # Disable netfilter on bridges.
  109. net.bridge.bridge-nf-call-ip6tables = 0
  110. net.bridge.bridge-nf-call-iptables = 0
  111. net.bridge.bridge-nf-call-arptables = 0
  112. # Controls the default maxmimum size of a mesage queue
  113. kernel.msgmnb = 65536
  114. # Controls the maximum size of a message, in bytes
  115. kernel.msgmax = 65536
  116. # Controls the maximum shared segment size, in bytes
  117. kernel.shmmax = 68719476736
  118. # Controls the maximum number of shared memory segments, in pages
  119. kernel.shmall = 4294967296
  120. net.ipv4.conf.all.send_redirects = 0
  121. net.ipv4.conf.default.send_redirects = 0
  122. net.ipv4.conf.all.secure_redirects = 0
  123. net.ipv4.conf.default.secure_redirects = 0
  124. net.ipv4.conf.all.accept_redirects = 0
  125. net.ipv4.conf.default.accept_redirects = 0
  126. net.ipv4.conf.all.send_redirects = 0
  127. net.ipv4.conf.default.send_redirects = 0
  128. net.ipv4.conf.all.secure_redirects = 0
  129. net.ipv4.conf.default.secure_redirects = 0
  130. net.ipv4.conf.all.accept_redirects = 0
  131. net.ipv4.conf.default.accept_redirects = 0
  132. net.netfilter.nf_conntrack_max = 1000000
  133. kernel.unknown_nmi_panic = 0
  134. kernel.sysrq = 0
  135. fs.file-max = 1000000
  136. vm.swappiness = 10
  137. fs.inotify.max_user_watches = 10000000
  138. net.core.wmem_max = 327679
  139. net.core.rmem_max = 327679
  140. net.ipv4.conf.all.send_redirects = 0
  141. net.ipv4.conf.default.send_redirects = 0
  142. net.ipv4.conf.all.secure_redirects = 0
  143. net.ipv4.conf.default.secure_redirects = 0
  144. net.ipv4.conf.all.accept_redirects = 0
  145. net.ipv4.conf.default.accept_redirects = 0
  146. /sbin/sysctl -p
  147. #自动选择最快的yum源
  148. yum -y install yum-fastestmirror
  149. #移除系统自带的rpm包的http mysql php
  150. #yum remove httpd* php*
  151. yum remove httpd mysql mysql-server php php-cli php-common php-devel php-gd -y
  152. #升级基础库
  153. yum install -y wget gcc gcc-c++ openssl* curl curl-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel gd gd2 gd-devel gd2-devel libaio autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel
  154. #yum安装基础必备环境包,可以先将yum源更换为阿里云的源
  155. 阿里:http://mirrors.aliyun.com/
  156. 搜狐:http://mirrors.sohu.com/
  157. 网易:http://mirrors.163.com/
  158. #备份原先的yum源信息
  159. mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
  160. #从阿里云镜像站下载centos6的repo
  161. wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
  162. #最后yum重新生成缓存
  163. yum makecache
  164. #yum安装软件包(可选)
  165. yum -y install tar zip unzip openssl* gd gd-devel 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 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel openldap-clients openldap-servers make libmcrypt libmcrypt-devel fontconfig fontconfig-devel libXpm* libtool* libxml2 libxml2-devel t1lib t1lib-devel
  166. #定义目录结构,下载安装包
  167. mkdir -p /app/{local,data}
  168. cd /app/local
  169. #PCRE - Perl Compatible Regular Expressions
  170. wget "ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.gz"
  171. #Tengine
  172. wget "http://tengine.taobao.org/download/tengine-2.1.0.tar.gz"
  173. #MySQL
  174. wget "https://downloads.mariadb.com/archives/mysql-5.6/mysql-5.6.25-linux-glibc2.5-x86_64.tar.gz"
  175. #PHP
  176. wget "http://cn2.php.net/distributions/php-5.6.11.tar.gz"
  177. #Mhash
  178. wget "http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz"
  179. #libmcrypt
  180. wget "http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz"
  181. #Mcrypt
  182. wget "http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz"
配置Tengine 安装PCRE

</>复制代码

  1. bashtar zxvf pcre-8.37.tar.gz
  2. cd pcre-8.37
  3. ./configure
  4. make && make install
  5. cd ../
安装Tengine

</>复制代码

  1. bash#添加www用户和组
  2. groupadd www
  3. useradd -g www www
  4. #安装Tengine
  5. tar zxvf tengine-2.1.0.tar.gz
  6. cd tengine-2.1.0
  7. ./configure --user=www --group=www
  8. --prefix=/app/local/nginx
  9. --with-http_stub_status_module
  10. --with-http_ssl_module
  11. --with-pcre=/app/local/pcre-8.37
  12. make && make install
  13. cd ../
配置Nginx

</>复制代码

  1. Nginx配置文件的优化很重要,理解每一步的意义

</>复制代码

  1. bash#修改nginx.conf
  2. vi /app/local/nginx/conf/nginx.conf
  3. #用户和用户组
  4. user www www;
  5. #工作进程,一般可以按CPU核数设定
  6. worker_processes auto;
  7. worker_cpu_affinity auto;
  8. #全局错误日志级别
  9. # [ debug | info | notice | warn | error | crit ]
  10. error_log logs/error.log error;
  11. #PID文件位置
  12. pid logs/nginx.pid;
  13. #更改worker进程的最大打开文件数限制,避免"too many open files"
  14. worker_rlimit_nofile 65535;
  15. #events事件指令是设定Nginx的工作模式及连接数上限
  16. events{
  17. #epoll是Linux首选的高效工作模式
  18. use epoll;
  19. #告诉nginx收到一个新连接通知后接受尽可能多的连接
  20. multi_accept on;
  21. #用于定义Nginx每个进程的最大连接数
  22. worker_connections 65536;
  23. }
  24. #HTTP模块控制着nginx http处理的所有核心特性
  25. http {
  26. include mime.types;
  27. #设置文件使用的默认的MIME-type
  28. default_type application/octet-stream;
  29. #对日志格式的设定,main为日志格式别名
  30. log_format main "$remote_addr - $remote_user [$time_local] "$request" "
  31. "$status $body_bytes_sent "$http_referer" "
  32. ""$http_user_agent" "$http_x_forwarded_for"";
  33. #设置nginx是否将存储访问日志。关闭这个选项可以让读取磁盘IO操作更快
  34. access_log off;
  35. # access_log logs/access.log main buffer=16k;
  36. #开启gzip压缩,实时压缩输出数据流
  37. gzip on;
  38. #设置IE6或者更低版本禁用gzip功能
  39. gzip_disable "MSIE [1-6].";
  40. #前端的缓存服务器缓存经过gzip压缩的页面
  41. gzip_vary on;
  42. #允许压缩基于请求和响应的响应流
  43. gzip_proxied any;
  44. #设置数据的压缩等级
  45. gzip_comp_level 4;
  46. #设置对数据启用压缩的最少字节数
  47. gzip_min_length 1k;
  48. #表示申请16个单位为64K的内存作为压缩结果流缓存
  49. gzip_buffers 16 64k;
  50. #用于设置识别HTTP协议版本
  51. gzip_http_version 1.1;
  52. #用来指定压缩的类型
  53. gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
  54. #打开缓存的同时也指定了缓存最大数目,以及缓存的时间
  55. open_file_cache max=200000 inactive=20s;
  56. #在open_file_cache中指定检测正确信息的间隔时间
  57. open_file_cache_valid 30s;
  58. #定义了open_file_cache中指令参数不活动时间期间里最小的文件数
  59. open_file_cache_min_uses 2;
  60. #指定了当搜索一个文件时是否缓存错误信息,也包括再次给配置中添加文件
  61. open_file_cache_errors on;
  62. #设置允许客户端请求的最大的单个文件字节数
  63. client_max_body_size 30M;
  64. #设置客户端请求主体读取超时时间
  65. client_body_timeout 10;
  66. #设置客户端请求头读取超时时间
  67. client_header_timeout 10;
  68. #指定来自客户端请求头的headerbuffer大小
  69. client_header_buffer_size 32k;
  70. #设置客户端连接保持活动的超时时间
  71. keepalive_timeout 60;
  72. #关闭不响应的客户端连接
  73. reset_timedout_connection on;
  74. #设置响应客户端的超时时间
  75. send_timeout 10;
  76. #开启高效文件传输模式
  77. sendfile on;
  78. #告诉nginx在一个数据包里发送所有头文件,而不一个接一个的发送
  79. tcp_nopush on;
  80. #告诉nginx不要缓存数据,而是一段一段的发送
  81. tcp_nodelay on;
  82. #设置用于保存各种key(比如当前连接数)的共享内存的参数
  83. limit_conn_zone $binary_remote_addr zone=addr:5m;
  84. #给定的key设置最大连接数,允许每一个IP地址最多同时打开有100个连接
  85. limit_conn addr 100;
  86. #FastCGI相关参数是为了改善网站的性能:减少资源占用,提高访问速度
  87. fastcgi_buffers 256 16k;
  88. fastcgi_buffer_size 128k;
  89. fastcgi_connect_timeout 3s;
  90. fastcgi_send_timeout 120s;
  91. fastcgi_read_timeout 120s;
  92. server_names_hash_bucket_size 128;
  93. #不在error_log中记录不存在的错误
  94. log_not_found off;
  95. #关闭在错误页面中的nginx版本数字,提高安全性
  96. #server_tag Apache;
  97. server_tokens off;
  98. #tengine
  99. server_tag off;
  100. server_info off;
  101. #添加虚拟主机的配置文件
  102. include vhosts/*.conf;
  103. #负载均衡配置(暂时略过)
  104. #upstream test.com
  105. #设定虚拟主机配置
  106. server {
  107. #侦听80端口
  108. listen 80;
  109. #定义使用localhost访问
  110. server_name localhost;
  111. #定义首页索引文件的名称
  112. index index.html index.htm index.php;
  113. #定义服务器的默认网站根目录位置
  114. root /app/data/localhost/;
  115. #定义错误提示页面
  116. error_page 404 /404.html;
  117. error_page 500 502 503 504 /50x.html;
  118. location = /50x.html {
  119. root html;
  120. }
  121. #PHP 脚本请求全部转发到 FastCGI处理. 使用FastCGI默认配置.
  122. location ~ .*.(php|php5)?$ {
  123. fastcgi_pass 127.0.0.1:9000;
  124. fastcgi_index index.php;
  125. include fastcgi.conf;
  126. }
  127. #静态文件
  128. location ~ .*.(gif|jpg|jpeg|png|bmp|swf|ico)$
  129. {
  130. #过期30天,频繁更新可设置小一点
  131. expires 30d;
  132. }
  133. location ~ .*.(js|css)?$
  134. {
  135. #过期1小时,不更新可设置大一些
  136. expires 1h;
  137. }
  138. #禁止访问
  139. location ~ /. {
  140. deny all;
  141. }
  142. }
  143. }

</>复制代码

  1. 简化配置文件

  2. vi /app/local/nginx/conf/nginx.conf

</>复制代码

  1. bash
    user www www;
  2. worker_processes auto;
  3. worker_cpu_affinity auto;
  4. error_log logs/error.log crit;
  5. pid logs/nginx.pid;
  6. worker_rlimit_nofile 51200;
  7. events
  8. {
  9. use epoll;
  10. multi_accept on;
  11. worker_connections 51200;
  12. }
  13. http
  14. {
  15. include mime.types;
  16. default_type application/octet-stream;
  17. log_format main "$remote_addr - $remote_user [$time_local] "$request" "
  18. "$status $body_bytes_sent "$http_referer" "
  19. ""$http_user_agent" "$http_x_forwarded_for"";
  20. access_log off;
  21. #access_log logs/access.log main buffer=16k;
  22. server_names_hash_bucket_size 128;
  23. client_header_buffer_size 32k;
  24. large_client_header_buffers 4 32k;
  25. client_max_body_size 50M;
  26. sendfile on;
  27. tcp_nopush on;
  28. tcp_nodelay on;
  29. keepalive_timeout 60;
  30. server_tokens off;
  31. server_tag off;
  32. server_info off;
  33. fastcgi_connect_timeout 300;
  34. fastcgi_send_timeout 300;
  35. fastcgi_read_timeout 300;
  36. fastcgi_buffer_size 64k;
  37. fastcgi_buffers 4 64k;
  38. fastcgi_busy_buffers_size 128k;
  39. fastcgi_temp_file_write_size 256k;
  40. #gzip on;
  41. #gzip_min_length 1k;
  42. #gzip_buffers 4 16k;
  43. #gzip_http_version 1.1;
  44. #gzip_comp_level 5;
  45. #gzip_types text/plain application/x-javascript text/css application/xml;
  46. #gzip_vary on;
  47. include vhosts/*.conf;
  48. }

</>复制代码

  1. 分离server写入vhosts

  2. mkdir -p /app/local/nginx/conf/vhosts/
  3. vi /app/local/nginx/conf/vhosts/localhost.conf

</>复制代码

  1. bashserver {
  2. listen 80;
  3. server_name localhost;
  4. index index.php index.html index.htm;
  5. access_log logs/localhost.log main;
  6. root /app/data/localhost/;
  7. location / {
  8. index index.php index.html index.htm;
  9. }
  10. #error_page 404 /404.html;
  11. #error_page 500 502 503 504 /50x.html;
  12. location = /50x.html {
  13. root html;
  14. }
  15. location ~ .*.(php|php5)?$ {
  16. fastcgi_pass 127.0.0.1:9000;
  17. fastcgi_index index.php;
  18. #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  19. include fastcgi.conf;
  20. }
  21. location ~ .*.(gif|jpg|jpeg|png|bmp|swf|ico)$
  22. {
  23. expires 30d;
  24. }
  25. location ~ .*.(js|css)?$
  26. {
  27. expires 1h;
  28. }
  29. location ~ /. {
  30. deny all;
  31. }
  32. }

</>复制代码

  1. bash#检查语法
  2. /app/local/nginx/sbin/nginx -t
  3. # ./nginx -t
  4. the configuration file /app/local/nginx/conf/nginx.conf syntax is ok
  5. configuration file /app/local/nginx/conf/nginx.conf test is successful
  6. #测试用例
  7. mkdir -p /app/data/localhost
  8. chmod +w /app/data/localhost
  9. echo "" > /app/data/localhost/phpinfo.php
  10. chown -R www:www /app/data/localhost
  11. #设置nginx系统变量
  12. echo "export PATH=$PATH:/app/local/nginx/sbin">>/etc/profile && source /etc/profile
  13. #测试访问
  14. curl -I http://localhost
  15. HTTP/1.1 200 OK
  16. Server: Tengine/2.1.0
  17. Date: Mon, 27 Jul 2015 06:42:25 GMT
  18. Content-Type: text/html; charset=UTF-8
  19. Connection: keep-alive
  20. X-Powered-By: PHP/5.6.11
添加Tengine到服务

</>复制代码

  1. 配置服务后便于统一管理

  2. vi /etc/rc.d/init.d/nginx

</>复制代码

  1. bash#!/bin/sh
  2. # Source function library.
  3. . /etc/rc.d/init.d/functions
  4. # Source networking configuration.
  5. . /etc/sysconfig/network
  6. # Check that networking is up.
  7. [ "$NETWORKING" = "no" ] && exit 0
  8. nginx="/app/local/nginx/sbin/nginx"
  9. prog=$(basename $nginx)
  10. NGINX_CONF_FILE="/app/local/nginx/conf/nginx.conf"
  11. [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
  12. lockfile=/var/lock/subsys/nginx
  13. make_dirs() {
  14. # make required directories
  15. user=`$nginx -V 2>&1 | grep "configure arguments:" | sed "s/[^*]*--user=([^ ]*).*/1/g" -`
  16. if [ -z "`grep $user /etc/passwd`" ]; then
  17. useradd -M -s /bin/nologin $user
  18. fi
  19. options=`$nginx -V 2>&1 | grep "configure arguments:"`
  20. for opt in $options; do
  21. if [ `echo $opt | grep ".*-temp-path"` ]; then
  22. value=`echo $opt | cut -d "=" -f 2`
  23. if [ ! -d "$value" ]; then
  24. # echo "creating" $value
  25. mkdir -p $value && chown -R $user $value
  26. fi
  27. fi
  28. done
  29. }
  30. start() {
  31. [ -x $nginx ] || exit 5
  32. [ -f $NGINX_CONF_FILE ] || exit 6
  33. make_dirs
  34. echo -n $"Starting $prog: "
  35. daemon $nginx -c $NGINX_CONF_FILE
  36. retval=$?
  37. echo
  38. [ $retval -eq 0 ] && touch $lockfile
  39. return $retval
  40. }
  41. stop() {
  42. echo -n $"Stopping $prog: "
  43. killproc $prog -QUIT
  44. retval=$?
  45. echo
  46. [ $retval -eq 0 ] && rm -f $lockfile
  47. return $retval
  48. }
  49. restart() {
  50. configtest || return $?
  51. stop
  52. sleep 1
  53. start
  54. }
  55. reload() {
  56. configtest || return $?
  57. echo -n $"Reloading $prog: "
  58. killproc $nginx -HUP
  59. RETVAL=$?
  60. echo
  61. }
  62. force_reload() {
  63. restart
  64. }
  65. configtest() {
  66. $nginx -t -c $NGINX_CONF_FILE
  67. }
  68. rh_status() {
  69. status $prog
  70. }
  71. rh_status_q() {
  72. rh_status >/dev/null 2>&1
  73. }
  74. case "$1" in
  75. start)
  76. rh_status_q && exit 0
  77. $1
  78. ;;
  79. stop)
  80. rh_status_q || exit 0
  81. $1
  82. ;;
  83. restart|configtest)
  84. $1
  85. ;;
  86. reload)
  87. rh_status_q || exit 7
  88. $1
  89. ;;
  90. force-reload)
  91. force_reload
  92. ;;
  93. status)
  94. rh_status
  95. ;;
  96. condrestart|try-restart)
  97. rh_status_q || exit 0
  98. ;;
  99. *)
  100. echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
  101. exit 2
  102. esac

</>复制代码

  1. bash#修改执行权限
  2. chmod +x /etc/init.d/nginx
  3. ulimit -SHn 65535
  4. service nginx start
安装MySQL

</>复制代码

  1. 注意目录和字符集等配置文件

</>复制代码

  1. bash#解压mysql
  2. mkdir -p /app/local/mysql
  3. tar zxvf mysql-5.6.25-linux-glibc2.5-x86_64.tar.gz
  4. mv mysql-5.6.25-linux-glibc2.5-x86_64/* /app/local/mysql
  5. #增加mysql用户组
  6. groupadd mysql
  7. useradd -g mysql mysql
  8. mkdir -p /app/data/mysql/data/
  9. mkdir -p /app/data/mysql/binlog/
  10. mkdir -p /app/data/mysql/relaylog/
  11. chown -R mysql:mysql /app/data/mysql/
  12. #安装mysql
  13. /app/local/mysql/scripts/mysql_install_db --basedir=/app/local/mysql --datadir=/app/data/mysql/data --user=mysql
  14. #修改mysqld_safe配置路径
  15. sed -i "s#/usr/local/mysql#/app/local/mysql#g" /app/local/mysql/bin/mysqld_safe

</>复制代码

  1. bash
    #修改my.cnf配置文件
  2. vi /app/local/mysql/my.cnf
  3. [client]
  4. character-set-server = utf8
  5. port = 3306
  6. socket = /tmp/mysql.sock
  7. [mysql]
  8. #prompt="(u:HOSTNAME:)[d]> "
  9. prompt="u@h R:m:s [d]> "
  10. no-auto-rehash
  11. [mysqld]
  12. server-id = 1
  13. port = 3306
  14. user = mysql
  15. basedir = /app/local/mysql
  16. datadir = /app/data/mysql/data
  17. socket = /tmp/mysql.sock
  18. log-error = /app/data/mysql/mysql_error.log
  19. pid-file = /app/data/mysql/mysql.pid
  20. sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
  21. default-storage-engine = InnoDB
  22. max_connections = 512
  23. max_connect_errors = 100000
  24. table_open_cache = 512
  25. external-locking = FALSE
  26. max_allowed_packet = 32M
  27. slow_query_log = 1
  28. slow_query_log_file = /app/data/mysql/slow.log
  29. open_files_limit = 10240
  30. back_log = 600
  31. join_buffer_size = 2M
  32. read_rnd_buffer_size = 16M
  33. sort_buffer_size = 2M
  34. thread_cache_size = 300
  35. query_cache_size = 128M
  36. query_cache_limit = 2M
  37. query_cache_min_res_unit = 2k
  38. thread_stack = 192K
  39. transaction_isolation = READ-COMMITTED
  40. tmp_table_size = 246M
  41. max_heap_table_size = 246M
  42. long_query_time = 3
  43. log-slave-updates
  44. log-bin = /app/data/mysql/binlog/binlog
  45. sync_binlog = 1
  46. binlog_cache_size = 4M
  47. binlog_format = MIXED
  48. max_binlog_cache_size = 8M
  49. max_binlog_size = 1G
  50. relay-log-index = /app/data/mysql/relaylog/relaylog
  51. relay-log-info-file = /app/data/mysql/relaylog/relaylog
  52. relay-log = /app/data/mysql/relaylog/relaylog
  53. expire_logs_days = 7
  54. key_buffer_size = 128M
  55. read_buffer_size = 1M
  56. read_rnd_buffer_size = 16M
  57. bulk_insert_buffer_size = 64M
  58. myisam_sort_buffer_size = 128M
  59. myisam_max_sort_file_size = 10G
  60. myisam_repair_threads = 1
  61. myisam_recover
  62. innodb_additional_mem_pool_size = 16M
  63. innodb_buffer_pool_size = 256M
  64. innodb_data_file_path = ibdata1:1024M:autoextend
  65. innodb_flush_log_at_trx_commit = 1
  66. innodb_log_buffer_size = 16M
  67. innodb_log_file_size = 256M
  68. innodb_log_files_in_group = 2
  69. innodb_max_dirty_pages_pct = 50
  70. innodb_file_per_table = 1
  71. innodb_locks_unsafe_for_binlog = 0
  72. interactive_timeout = 120
  73. wait_timeout = 120
  74. skip-name-resolve
  75. slave-skip-errors = 1032,1062,126,1114,1146,1048,1396
  76. [mysqldump]
  77. quick
  78. max_allowed_packet = 32M

</>复制代码

  1. bash
    #添加mysql到服务
  2. vi /etc/rc.d/init.d/mysqld
  3. #!/bin/sh
  4. basedir=/app/local/mysql
  5. datadir=/app/data/mysql/data
  6. service_startup_timeout=900
  7. lockdir="/var/lock/subsys"
  8. lock_file_path="$lockdir/mysql"
  9. mysqld_pid_file_path=/app/data/mysql/mysql.pid
  10. if test -z "$basedir"
  11. then
  12. basedir=/usr/local/mysql
  13. bindir=/usr/local/mysql/bin
  14. if test -z "$datadir"
  15. then
  16. datadir=/usr/local/mysql/data
  17. fi
  18. sbindir=/usr/local/mysql/bin
  19. libexecdir=/usr/local/mysql/bin
  20. else
  21. bindir="$basedir/bin"
  22. if test -z "$datadir"
  23. then
  24. datadir="$basedir/data"
  25. fi
  26. sbindir="$basedir/sbin"
  27. libexecdir="$basedir/libexec"
  28. fi
  29. datadir_set=
  30. lsb_functions="/lib/lsb/init-functions"
  31. if test -f $lsb_functions ; then
  32. . $lsb_functions
  33. else
  34. log_success_msg()
  35. {
  36. echo " SUCCESS! $@"
  37. }
  38. log_failure_msg()
  39. {
  40. echo " ERROR! $@"
  41. }
  42. fi
  43. PATH="/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin"
  44. export PATH
  45. mode=$1 # start or stop
  46. [ $# -ge 1 ] && shift
  47. other_args="$*" # uncommon, but needed when called from an RPM upgrade action
  48. # Expected: "--skip-networking --skip-grant-tables"
  49. # They are not checked here, intentionally, as it is the resposibility
  50. # of the "spec" file author to give correct arguments only.
  51. case `echo "testingc"`,`echo -n testing` in
  52. *c*,-n*) echo_n= echo_c= ;;
  53. *c*,*) echo_n=-n echo_c= ;;
  54. *) echo_n= echo_c="c" ;;
  55. esac
  56. parse_server_arguments() {
  57. for arg do
  58. case "$arg" in
  59. --basedir=*) basedir=`echo "$arg" | sed -e "s/^[^=]*=//"`
  60. bindir="$basedir/bin"
  61. if test -z "$datadir_set"; then
  62. datadir="$basedir/data"
  63. fi
  64. sbindir="$basedir/sbin"
  65. libexecdir="$basedir/libexec"
  66. ;;
  67. --datadir=*) datadir=`echo "$arg" | sed -e "s/^[^=]*=//"`
  68. datadir_set=1
  69. ;;
  70. --pid-file=*) mysqld_pid_file_path=`echo "$arg" | sed -e "s/^[^=]*=//"` ;;
  71. --service-startup-timeout=*) service_startup_timeout=`echo "$arg" | sed -e "s/^[^=]*=//"` ;;
  72. esac
  73. done
  74. }
  75. wait_for_pid () {
  76. verb="$1" # created | removed
  77. pid="$2" # process ID of the program operating on the pid-file
  78. pid_file_path="$3" # path to the PID file.
  79. i=0
  80. avoid_race_condition="by checking again"
  81. while test $i -ne $service_startup_timeout ; do
  82. case "$verb" in
  83. "created")
  84. # wait for a PID-file to pop into existence.
  85. test -s "$pid_file_path" && i="" && break
  86. ;;
  87. "removed")
  88. # wait for this PID-file to disappear
  89. test ! -s "$pid_file_path" && i="" && break
  90. ;;
  91. *)
  92. echo "wait_for_pid () usage: wait_for_pid created|removed pid pid_file_path"
  93. exit 1
  94. ;;
  95. esac
  96. # if server isn"t running, then pid-file will never be updated
  97. if test -n "$pid"; then
  98. if kill -0 "$pid" 2>/dev/null; then
  99. : # the server still runs
  100. else
  101. # The server may have exited between the last pid-file check and now.
  102. if test -n "$avoid_race_condition"; then
  103. avoid_race_condition=""
  104. continue # Check again.
  105. fi
  106. # there"s nothing that will affect the file.
  107. log_failure_msg "The server quit without updating PID file ($pid_file_path)."
  108. return 1 # not waiting any more.
  109. fi
  110. fi
  111. echo $echo_n ".$echo_c"
  112. i=`expr $i + 1`
  113. sleep 1
  114. done
  115. if test -z "$i" ; then
  116. log_success_msg
  117. return 0
  118. else
  119. log_failure_msg
  120. return 1
  121. fi
  122. }
  123. # Get arguments from the my.cnf file,
  124. # the only group, which is read from now on is [mysqld]
  125. if test -x ./bin/my_print_defaults
  126. then
  127. print_defaults="./bin/my_print_defaults"
  128. elif test -x $bindir/my_print_defaults
  129. then
  130. print_defaults="$bindir/my_print_defaults"
  131. elif test -x $bindir/mysql_print_defaults
  132. then
  133. print_defaults="$bindir/mysql_print_defaults"
  134. else
  135. # Try to find basedir in /etc/my.cnf
  136. conf=/etc/my.cnf
  137. print_defaults=
  138. if test -r $conf
  139. then
  140. subpat="^[^=]*basedir[^=]*=(.*)$"
  141. dirs=`sed -e "/$subpat/!d" -e "s//1/" $conf`
  142. for d in $dirs
  143. do
  144. d=`echo $d | sed -e "s/[ ]//g"`
  145. if test -x "$d/bin/my_print_defaults"
  146. then
  147. print_defaults="$d/bin/my_print_defaults"
  148. break
  149. fi
  150. if test -x "$d/bin/mysql_print_defaults"
  151. then
  152. print_defaults="$d/bin/mysql_print_defaults"
  153. break
  154. fi
  155. done
  156. fi
  157. # Hope it"s in the PATH ... but I doubt it
  158. test -z "$print_defaults" && print_defaults="my_print_defaults"
  159. fi
  160. #
  161. # Read defaults file from "basedir". If there is no defaults file there
  162. # check if it"s in the old (depricated) place (datadir) and read it from there
  163. #
  164. extra_args=""
  165. if test -r "$basedir/my.cnf"
  166. then
  167. extra_args="-e $basedir/my.cnf"
  168. else
  169. if test -r "$datadir/my.cnf"
  170. then
  171. extra_args="-e $datadir/my.cnf"
  172. fi
  173. fi
  174. parse_server_arguments `$print_defaults $extra_args mysqld server mysql_server mysql.server`
  175. #
  176. # Set pid file if not given
  177. #
  178. if test -z "$mysqld_pid_file_path"
  179. then
  180. mysqld_pid_file_path=$datadir/`hostname`.pid
  181. else
  182. case "$mysqld_pid_file_path" in
  183. /* ) ;;
  184. * ) mysqld_pid_file_path="$datadir/$mysqld_pid_file_path" ;;
  185. esac
  186. fi
  187. case "$mode" in
  188. "start")
  189. # Start daemon
  190. # Safeguard (relative paths, core dumps..)
  191. cd $basedir
  192. echo $echo_n "Starting MySQL"
  193. if test -x $bindir/mysqld_safe
  194. then
  195. # Give extra arguments to mysqld with the my.cnf file. This script
  196. # may be overwritten at next upgrade.
  197. $bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null 2>&1 &
  198. wait_for_pid created "$!" "$mysqld_pid_file_path"; return_value=$?
  199. # Make lock for RedHat / SuSE
  200. if test -w "$lockdir"
  201. then
  202. touch "$lock_file_path"
  203. fi
  204. exit $return_value
  205. else
  206. log_failure_msg "Couldn"t find MySQL server ($bindir/mysqld_safe)"
  207. fi
  208. ;;
  209. "stop")
  210. # Stop daemon. We use a signal here to avoid having to know the
  211. # root password.
  212. if test -s "$mysqld_pid_file_path"
  213. then
  214. mysqld_pid=`cat "$mysqld_pid_file_path"`
  215. if (kill -0 $mysqld_pid 2>/dev/null)
  216. then
  217. echo $echo_n "Shutting down MySQL"
  218. kill $mysqld_pid
  219. # mysqld should remove the pid file when it exits, so wait for it.
  220. wait_for_pid removed "$mysqld_pid" "$mysqld_pid_file_path"; return_value=$?
  221. else
  222. log_failure_msg "MySQL server process #$mysqld_pid is not running!"
  223. rm "$mysqld_pid_file_path"
  224. fi
  225. # Delete lock for RedHat / SuSE
  226. if test -f "$lock_file_path"
  227. then
  228. rm -f "$lock_file_path"
  229. fi
  230. exit $return_value
  231. else
  232. log_failure_msg "MySQL server PID file could not be found!"
  233. fi
  234. ;;
  235. "restart")
  236. # Stop the service and regardless of whether it was
  237. # running or not, start it again.
  238. if $0 stop $other_args; then
  239. $0 start $other_args
  240. else
  241. log_failure_msg "Failed to stop running server, so refusing to try to start."
  242. exit 1
  243. fi
  244. ;;
  245. "reload"|"force-reload")
  246. if test -s "$mysqld_pid_file_path" ; then
  247. read mysqld_pid < "$mysqld_pid_file_path"
  248. kill -HUP $mysqld_pid && log_success_msg "Reloading service MySQL"
  249. touch "$mysqld_pid_file_path"
  250. else
  251. log_failure_msg "MySQL PID file could not be found!"
  252. exit 1
  253. fi
  254. ;;
  255. "status")
  256. # First, check to see if pid file exists
  257. if test -s "$mysqld_pid_file_path" ; then
  258. read mysqld_pid < "$mysqld_pid_file_path"
  259. if kill -0 $mysqld_pid 2>/dev/null ; then
  260. log_success_msg "MySQL running ($mysqld_pid)"
  261. exit 0
  262. else
  263. log_failure_msg "MySQL is not running, but PID file exists"
  264. exit 1
  265. fi
  266. else
  267. # Try to find appropriate mysqld process
  268. mysqld_pid=`pidof $libexecdir/mysqld`
  269. # test if multiple pids exist
  270. pid_count=`echo $mysqld_pid | wc -w`
  271. if test $pid_count -gt 1 ; then
  272. log_failure_msg "Multiple MySQL running but PID file could not be found ($mysqld_pid)"
  273. exit 5
  274. elif test -z $mysqld_pid ; then
  275. if test -f "$lock_file_path" ; then
  276. log_failure_msg "MySQL is not running, but lock file ($lock_file_path) exists"
  277. exit 2
  278. fi
  279. log_failure_msg "MySQL is not running"
  280. exit 3
  281. else
  282. log_failure_msg "MySQL is running but PID file could not be found"
  283. exit 4
  284. fi
  285. fi
  286. ;;
  287. *)
  288. # usage
  289. basename=`basename "$0"`
  290. echo "Usage: $basename {start|stop|restart|reload|force-reload|status} [ MySQL server options ]"
  291. exit 1
  292. ;;
  293. esac
  294. exit 0

</>复制代码

  1. bash#修改权限
  2. chmod +x /etc/init.d/mysqld
  3. service mysqld start
  4. #增加MySQL系统环境变量
  5. echo "export PATH=$PATH:/app/local/mysql/bin">>/etc/profile && source /etc/profile
  6. #查看错误日志
  7. tail -f /var/log/mysqld.log
  8. #用root账户登录并作简单的安全设置
  9. /app/local/mysql/bin/mysql -uroot -p

</>复制代码

  1. sql#修改root密码
  2. UPDATE mysql.user SET Password=password("root") WHERE User="root";
  3. #删除无名用户
  4. DELETE FROM mysql.user WHERE User="";
  5. #删除root远程访问
  6. DELETE FROM mysql.user WHERE User="root" AND Host NOT IN ("localhost", "127.0.0.1", "::1");
  7. #删除“test”数据库
  8. DROP database test;
  9. #允许远程访问
  10. /app/local/mysql/bin/mysql -uroot -proot
  11. use mysql;
  12. update user set host="%" where user="root" AND host="localhost";
  13. FLUSH PRIVILEGES;
  14. select host, user from user;
  15. #立即生效并退出MYSQL命令窗体
  16. FLUSH PRIVILEGES;QUIT;
安装Apache

</>复制代码

  1. bashcd /app/local
  2. tar zxvf httpd-2.2.29.tar.gz
  3. cd httpd-2.2.29
  4. ./configure --prefix=/app/local/apache
  5. --enable-so
  6. --enable-rewrite
  7. --enable-modes-shared=most
  8. make && make install
  9. vi /app/local/apache/conf/httpd.conf
  10. #修改主机名
  11. ServerName localhost:80
  12. #查找AddType application/x-gzip .gz .tgz,在该行下面添加
  13. AddType application/x-httpd-php .php
  14. #查找DirectoryIndex index.html 把该行修改成
  15. DirectoryIndex index.html index.htm index.php
  16. /app/local/apache/bin/apachectl -t
  17. cp /app/local/apache/bin/apachectl /etc/init.d/httpd
安装PHP PHP基础环境

</>复制代码

  1. bash#yum安装或者使用下面源包编译安装
  2. yum install libmcrypt libmcrypt-devel mcrypt mhash
  3. #下载地址
  4. http://sourceforge.net/projects/mcrypt/files/Libmcrypt/
  5. http://sourceforge.net/projects/mcrypt/files/MCrypt/
  6. http://sourceforge.net/projects/mhash/files/mhash/
  7. #安装Libmcrypt
  8. tar -zxvf libmcrypt-2.5.8.tar.gz
  9. cd libmcrypt-2.5.8
  10. ./configure
  11. make && make install
  12. cd ../
  13. 3.安装mhash
  14. tar -zxvf mhash-0.9.9.9.tar.gz
  15. cd mhash-0.9.9.9
  16. ./configure
  17. make && make install
  18. cd ../
  19. 4.安装mcrypt
  20. tar -zxvf mcrypt-2.6.8.tar.gz
  21. cd mcrypt-2.6.8
  22. LD_LIBRARY_PATH=/usr/local/lib ./configure
  23. make && make install
  24. cd ../
  25. ### 安装PHP
  26. >extension根据需要定制,新增的OPcache建议暂时不要开启
  27. ``` bash
  28. tar zxvf php-5.5.27.tar.gz
  29. cd php-5.5.27
  30. ./configure --prefix=/app/local/php
  31. --with-config-file-path=/app/local/php/etc
  32. --enable-fpm
  33. --enable-mbstring
  34. --with-mhash
  35. --with-mcrypt
  36. --with-curl
  37. --with-openssl
  38. --with-mysql=mysqlnd
  39. --with-mysqli=mysqlnd
  40. --with-pdo-mysql=mysqlnd
  41. --with-apxs2=/app/local/apache/bin/apxs
  42. #--enable-opcache
  43. make && make install
  44. #配置php.ini
  45. cp php.ini-development /app/local/php/etc/php.ini
  46. #设置时区
  47. sed -i "s#;date.timezone =#date.timezone = Asia/Shanghai#g" /app/local/php/etc/php.ini
  48. #防止nginx文件类型错误解析漏洞
  49. sed -i "s#;cgi.fix_pathinfo=1#cgi.fix_pathinfo=0#g" /app/local/php/etc/php.ini
  50. #禁止显示php版本的信息
  51. sed -i "s#expose_php = On#expose_php = Off#g" /app/local/php/etc/php.ini
  52. #禁用危险函数(可选)
  53. #sed -i "s#disable_functions =#disable_functions = exec,passthru,shell_exec,system,proc_open,popen,curl_exec,curl_multi_exec,parse_ini_file,show_source#g" /app/local/php/etc/php.ini
  54. #enable-opcache后设置(可选)
  55. [OPcache]
  56. zend_extension = opcache.so
  57. opcache.enable=1
  58. opcache.memory_consumption = 64
  59. opcache.interned_strings_buffer = 8
  60. opcache.max_accelerated_files = 4000
  61. opcache.revalidate_freq = 60
  62. opcache.fast_shutdown = 1
  63. opcache.enable_cli = 1
配置php-fpm

</>复制代码

  1. bash#编辑php-fpm
  2. cp /app/local/php/etc/php-fpm.conf.default /app/local/php/etc/php-fpm.conf
  3. vi /app/local/php/etc/php-fpm.conf
  4. [global]
  5. ;错误日志
  6. error_log = log/php-fpm.log
  7. ;错误日志级别
  8. log_level = notice
  9. [www]
  10. ;php-fpm监听端口
  11. listen = 127.0.0.1:9000
  12. ;启动进程的帐户和组
  13. user = www
  14. group = www
  15. ;如果选择static,则由pm.max_children指定固定的子进程数。如果选择dynamic,则由后面3个参数动态决定
  16. pm = dynamic
  17. ;子进程最大数
  18. pm.max_children = 384
  19. ;启动时的进程数
  20. pm.start_servers = 20
  21. ;保证空闲进程数最小值,如果空闲进程小于此值,则创建新的子进程
  22. pm.min_spare_servers = 5
  23. ;保证空闲进程数最大值,如果空闲进程大于此值,此进行清理
  24. pm.max_spare_servers = 35
  25. ;设置每个子进程重生之前服务的请求数。对于可能存在内存泄漏的第三方模块来说是非常有用的。如果设置为 "0" 则一直接受请求。等同于 PHP_FCGI_MAX_REQUESTS 环境变量。默认值: 0
  26. pm.max_requests = 1000
  27. ;每个子进程闲置多长时间就自杀
  28. pm.process_idle_timeout = 10s
  29. ;设置单个请求的超时中止时间。该选项可能会对php.ini设置中的"max_execution_time"因为某些特殊原因没有中止运行的脚本有用。设置为 "0" 表示 "Off".当经常出现502错误时可以尝试更改此选项。
  30. request_terminate_timeout = 120
  31. ;当一个请求该设置的超时时间后,就会将对应的PHP调用堆栈信息完整写入到慢日志中。设置为 "0" 表示 "Off"
  32. request_slowlog_timeout = 3s
  33. ;慢请求的记录日志,配合request_slowlog_timeout使用
  34. slowlog = /app/local/php/var/log/php-fpm.slow.log
  35. ;设置文件打开描述符的rlimit限制。默认值: 系统定义值默认可打开句柄是1024,可使用 ulimit -n查看,ulimit -n 2048修改。
  36. rlimit_files = 65535

</>复制代码

  1. bash
    #设置php环境变量
  2. echo "export PATH=$PATH:/app/local/php/bin">>/etc/profile && source /etc/profile
  3. touch /app/local/php/var/log/php-fpm.slow.log
  4. #添加php-fpm服务
  5. cp /app/local/php-5.5.27/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
  6. chmod +x /etc/rc.d/init.d/php-fpm
  7. service php-fpm start
  8. #设置开机自动启动服务
  9. vi /etc/rc.local
  10. ulimit -SHn 65535
  11. service php-fpm start
  12. service nginx start
  13. service mysqld start
配置memcache/mongo/redis

</>复制代码

  1. 其它extension扩展都可以动态添加,没事的

</>复制代码

  1. bash#memcache
  2. cd /app/local
  3. tar zxvf memcache-3.0.8.tgz
  4. cd memcache-3.0.8
  5. /app/local/php/bin/phpize
  6. ./configure --enable-memcache
  7. --with-php-config=/app/local/php/bin/php-config
  8. --with-zlib-dir
  9. make && make install
  10. #mongo
  11. cd /app/local
  12. tar zxvf mongo-1.6.10.tgz
  13. cd mongo-1.6.10
  14. /app/local/php/bin/phpize
  15. ./configure --with-php-config=/app/local/php/bin/php-config
  16. make && make install
  17. #redis
  18. cd /app/local
  19. tar zxvf redis-2.2.7.tgz
  20. cd redis-2.2.7
  21. /app/local/php/bin/phpize
  22. ./configure --with-php-config=/app/local/php/bin/php-config
  23. make && make install
  24. #php.ini
  25. vi /app/local/php/etc/php.ini
  26. [memcached]
  27. extension=memcached.so
  28. [mongodb]
  29. extension=mongo.so
  30. [redis]
  31. extension=redis.so
  32. #重启生效
  33. service php-fpm restart
  34. php -i | grep php.ini
  35. php -m
自动化部署

</>复制代码

  1. 服务器的上传目录可以自定义,安装目录默认统一修改为/app/{local,data},执行脚本为web.sh

</>复制代码

  1. bashfile://E:QQDownloadLTMP (2 folders, 5 files, 27.66 MB, 30.76 MB in total.)
  2. httpd-2.2.29.tar.gz 7.19 MB
  3. pcre-8.37.tar.gz 1.95 MB
  4. php-5.5.27.tar.gz 16.95 MB
  5. tengine-2.1.0.tar.gz 1.58 MB
  6. web.sh 4.10 KB
  7. ├─init (1 folders, 12 files, 91.42 KB, 92.23 KB in total.)
  8. │ │ allow.conf 35 bytes
  9. │ │ bashrc 2.99 KB
  10. │ │ deny.conf 35 bytes
  11. │ │ limits.conf 1.86 KB
  12. │ │ my.cnf 1.99 KB
  13. │ │ mysqld 8.39 KB
  14. │ │ nginx 2.22 KB
  15. │ │ nginx.conf 1.34 KB
  16. │ │ php-fpm 2.30 KB
  17. │ │ php-fpm.conf 416 bytes
  18. │ │ php.ini 67.83 KB
  19. │ │ sysctl.conf 2.03 KB
  20. │ └─vhosts (0 folders, 1 files, 826 bytes, 826 bytes in total.)
  21. localhost.conf 826 bytes
  22. └─src (0 folders, 6 files, 3.01 MB, 3.01 MB in total.)
  23. libmcrypt-2.5.8.tar.gz 1.27 MB
  24. mcrypt-2.6.8.tar.gz 460.85 KB
  25. memcache-3.0.8.tgz 68.87 KB
  26. mhash-0.9.9.9.tar.gz 909.61 KB
  27. mongo-1.6.10.tgz 204.19 KB
  28. redis-2.2.7.tgz 131.19 KB
  29. #web.sh
  30. #!/bin/bash
  31. ## alias
  32. ltmp_local=$(cd "$(dirname "$0")"; pwd)
  33. mkdir -p /app/{local,data}
  34. unalias cp
  35. ltmp_init=$ltmp_local/init/
  36. ltmp_src=$ltmp_local/src/
  37. ## system
  38. #history
  39. cp ${ltmp_init}bashrc /etc/
  40. #time
  41. rm -rf /etc/localtime
  42. ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
  43. #maildrop
  44. sed "s/MAILTO=root/MAILTO=""/g" /etc/crontab
  45. service crond restart
  46. #selinux
  47. setenforce 0
  48. sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config
  49. #limits
  50. echo ulimit -SHn 65535 >> /etc/profile
  51. source /etc/profile
  52. cp ${ltmp_init}limits.conf /etc/security/
  53. #tcp
  54. cp ${ltmp_init}sysctl.conf /etc/
  55. #yum
  56. yum -y install yum-fastestmirror
  57. yum remove httpd mysql mysql-server php php-cli php-common php-devel php-gd -y
  58. yum install -y wget gcc gcc-c++ openssl* curl curl-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel gd gd2 gd-devel gd2-devel libaio autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel
  59. #download
  60. cd /app/local
  61. ##PCRE - Perl Compatible Regular Expressions
  62. #wget "ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.gz"
  63. ##Tengine
  64. #wget "http://tengine.taobao.org/download/tengine-2.1.0.tar.gz"
  65. ##MySQL
  66. #wget "https://downloads.mariadb.com/archives/mysql-5.6/mysql-5.6.25-linux-glibc2.5-x86_64.tar.gz"
  67. ##PHP
  68. #wget "http://cn2.php.net/distributions/php-5.6.11.tar.gz"
  69. ##Mhash
  70. #wget "http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz"
  71. ##libmcrypt
  72. #wget "http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz"
  73. ##Mcrypt
  74. #wget "http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz"
  75. ## soft
  76. cd $ltmp_local
  77. #pcre
  78. tar zxvf pcre-8.37.tar.gz 1> /dev/null
  79. cd pcre-8.37
  80. ./configure
  81. make && make install
  82. cd ../
  83. #tengine
  84. groupadd www
  85. useradd -g www www
  86. #安装Tengine
  87. cd $ltmp_local
  88. tar zxvf tengine-2.1.0.tar.gz 1> /dev/null
  89. cd tengine-2.1.0
  90. ./configure --user=www --group=www
  91. --prefix=/app/local/nginx
  92. --with-http_stub_status_module
  93. --with-http_ssl_module
  94. --with-pcre=${ltmp_local}/pcre-8.37
  95. make && make install
  96. cd ../
  97. #nginx config
  98. cd $ltmp_local
  99. cp ${ltmp_init}nginx.conf /app/local/nginx/conf/
  100. cp -r ${ltmp_init}vhosts /app/local/nginx/conf/
  101. mkdir -p /app/data/localhost
  102. chmod +w /app/data/localhost
  103. echo "" > /app/data/localhost/phpinfo.php
  104. chown -R www:www /app/data/localhost
  105. echo "export PATH=$PATH:/app/local/nginx/sbin">>/etc/profile && source /etc/profile
  106. cp ${ltmp_init}nginx /etc/rc.d/init.d/
  107. chmod +x /etc/init.d/nginx
  108. ulimit -SHn 65535
  109. service nginx start
  110. #libmcrypt
  111. cd $ltmp_src
  112. tar -zxvf libmcrypt-2.5.8.tar.gz 1> /dev/null
  113. cd libmcrypt-2.5.8
  114. ./configure
  115. make && make install
  116. cd ../
  117. #mhash
  118. cd $ltmp_src
  119. tar -zxvf mhash-0.9.9.9.tar.gz 1> /dev/null
  120. cd mhash-0.9.9.9
  121. ./configure
  122. make && make install
  123. cd ../
  124. #mcrypt
  125. cd $ltmp_src
  126. tar -zxvf mcrypt-2.6.8.tar.gz 1> /dev/null
  127. cd mcrypt-2.6.8
  128. LD_LIBRARY_PATH=/usr/local/lib ./configure
  129. make && make install
  130. cd ../
  131. #php
  132. cd $ltmp_local
  133. tar zxvf php-5.5.27.tar.gz 1> /dev/null
  134. cd php-5.5.27
  135. ./configure --prefix=/app/local/php
  136. --with-config-file-path=/app/local/php/etc
  137. --enable-fpm
  138. --enable-mbstring
  139. --with-mhash
  140. --with-mcrypt
  141. --with-curl
  142. --with-openssl
  143. --with-mysql=mysqlnd
  144. --with-mysqli=mysqlnd
  145. --with-pdo-mysql=mysqlnd
  146. make && make install
  147. #memcache
  148. cd $ltmp_src
  149. tar zxvf memcache-3.0.8.tgz 1> /dev/null
  150. cd memcache-3.0.8
  151. /app/local/php/bin/phpize
  152. ./configure --enable-memcache
  153. --with-php-config=/app/local/php/bin/php-config
  154. --with-zlib-dir
  155. make && make install
  156. #mongo
  157. cd $ltmp_src
  158. tar zxvf mongo-1.6.10.tgz 1> /dev/null
  159. cd mongo-1.6.10
  160. /app/local/php/bin/phpize
  161. ./configure --with-php-config=/app/local/php/bin/php-config
  162. make && make install
  163. #redis
  164. cd $ltmp_src
  165. #redis
  166. tar zxvf redis-2.2.7.tgz 1> /dev/null
  167. cd redis-2.2.7
  168. /app/local/php/bin/phpize
  169. ./configure --with-php-config=/app/local/php/bin/php-config
  170. make && make install
  171. #php-fpm
  172. cp ${ltmp_init}php.ini /app/local/php/etc/
  173. cp ${ltmp_init}php-fpm.conf /app/local/php/etc/
  174. echo "export PATH=$PATH:/app/local/php/bin">>/etc/profile && source /etc/profile
  175. touch /app/local/php/var/log/php-fpm.slow.log
  176. cp ${ltmp_local}/php-5.5.27/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
  177. chmod +x /etc/rc.d/init.d/php-fpm
  178. service php-fpm start

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/39183.html

相关文章

  • phpMyAdmin无需填写IP管理多个MySQL实践

    摘要:前言默认安装,通常只能连一台服务器,其配置信息是保存在的配置文件里的,当我们需要在多台服务器之间进行切换登陆的时候,修改起来非常麻烦。遵照下面的配置方法,我们可以方便的使用连接多台。 showImg(//i.v2ex.co/68353qlH.png); 前言 默认安装phpMyAdmin,通常只能连一台MySQL服务器,其配置信息是保存在phpMyAdmin的配置文件里的,当我们需要在...

    孙淑建 评论0 收藏0
  • 使用RockMongo管理MongoDB

    摘要:前言和数据库相比的管理工具其实不算多,除了客户端以外想要通过类似一样通过管理的数据库应该也只剩下了。 前言 和MySQL数据库相比MongoDB的管理工具其实不算多,除了MongoVUE客户端以外想要通过类似phpMyAdmin一样通过Web管理MongoDB的数据库应该也只剩下RockMongo了。 和phpMyAdmin一样好用的MongoDB管理工具 更新记录 2015年10月...

    lookSomeone 评论0 收藏0

发表评论

0条评论

HelKyle

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<