龚哥哥 - 山里男儿 爱生活、做自己!
Nginx配置多个虚拟机
发表于 2015-8-31 | 浏览(5616) | 服务器
虚拟机分开管理方式
nginx.conf 文件配置如下

#运行用户
user www www;

#启动进程,通常设置成和cpu的数量相等
worker_processes  1;

#一个nginx进程打开的最多文件描述符数目,理论值应该是最多打开文件数(系统的值ulimit -n)与nginx进程数相除,但是nginx分配请求并不均匀,所以建议与ulimit -n的值保持一致。
worker_rlimit_nofile 65535;

#全局错误日志
error_log  /data/log/error.log;

#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;

events {
    #epoll是多路复用IO(I/O Multiplexing)中的一种方式,但是仅用于linux2.6以上内核,可以大大提高nginx的性能
    use epoll;

    #单个后台worker process进行的最大并发连接数
    worker_connections  65535;
}

http{
    #配置信息
    include mime.types; #文件扩展名与文件类型映射表
    default_type application/octet-stream; #默认文件类型

    #charset utf-8; #默认编码
    server_names_hash_bucket_size 128; #服务器名字的hash表大小
    client_header_buffer_size 32k; #上传文件大小限制
    large_client_header_buffers 4 64k; #设定请求缓
    client_max_body_size 8m; #设定请求缓
    sendfile on; #开启高效文件传输模式,sendfile指令指定nginx是否调用sendfile函数来输出文件,对于普通应用设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络I/O处理速度,降低系统的负载。注意:如果图片显示不正常把这个改成off。
    autoindex on; #开启目录列表访问,合适下载服务器,默认关闭。
    tcp_nopush on; #防止网络阻塞
    tcp_nodelay on; #防止网络阻塞
    keepalive_timeout 120; #长连接超时时间,单位是秒

    #FastCGI相关参数是为了改善网站的性能:减少资源占用,提高访问速度。下面参数看字面意思都能理解。
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;

    #gzip模块设置
    gzip on; #开启gzip压缩输出
    gzip_min_length 1k; #最小压缩文件大小
    gzip_buffers 4 16k; #压缩缓冲区
    gzip_http_version 1.0; #压缩版本(默认1.1,前端如果是squid2.5请使用1.0)
    gzip_comp_level 2; #压缩等级
    #gzip_types text/plain text/css text/javascrip application/javascript application/x-javascript image/jepg image/gif image/png;
    gzip_types text/plain text/css text/javascrip application/javascript application/x-javascript;
    #压缩类型,默认就已经包含textml,所以下面就不用再写了,写上去也不会有问题,但是会有一个warn。
    gzip_vary on;
    #limit_zone crawler $binary_remote_addr 10m; #开启限制IP连接数的时候需要使用

    #文件缓存
    open_file_cache max=65535 inactive=60s; #这个将为打开文件指定缓存,默认是没有启用的,max指定缓存数量,建议和打开文件数一致,inactive 是指经过多长时间文件没被请求后删除缓存。
    open_file_cache_valid 80s; #这个是指多长时间检查一次缓存的有效信息。
    open_file_cache_min_uses 1; #参数时间内文件的最少使用次数,如果超过这个数字,文件描述符一直是在缓存中打开的,如上例,如果有一个文件在inactive 时间内一次没被使用,它将被移除。

    #开启404
    fastcgi_intercept_errors on;
    #载入虚拟机配置文件, 载入vhost目录下的所有配置文件, 目录位与nginx.conf同级
    include vhost/*.conf;
}

vhost/demo.conf 文件配置如下
# https
server {
        listen443;
        server_namewww.gongfuxiang.com gongfuxiang.com *.gongfuxiang.com;
        if ( $host != 'www.gongfuxiang.com' ) {
        rewrite ^/(.*)$ https://www.gongfuxiang.com/$1 permanent;
    }
    access_log/data/log/access.log;
    error_log/data/log/error.log warn;
    indexindex.html index.htm index.php;
    root/data/www;
    autoindexoff;
    include/data/www/.htaccess;

    sslon;
    ssl_certificate/data/https_rsa/gongfuxiang.pem;
    ssl_certificate_key/data/https_rsa/gongfuxiang.key;
    ssl_session_timeout5m;

    #4000,500错误定义
    error_page  404 http://$server_name;
    #error_page  500 502 503 504  /50x.html;

    #PHP 脚本请求全部转发到 FastCGI处理. 使用FastCGI默认配置
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    #JS和CSS缓存时间设置
    location ~ .*.(js|css)?$
    {
        expires 1h;
    }

    #所有静态文件由nginx直接读取不经过tomcat或resin
    location ~ .*.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$
    {
        expires 15d;
    }
}

# http
server {
    listen80 default;
    server_namewww.gongfuxiang.com gongfuxiang.com *.gongfuxiang.com;
    if ( $host != 'www.qualifes.com' ) {
        rewrite ^/(.*)$ http://www.gongfuxiang.com/$1 permanent;
    }
    access_log/data/log/access.log;
    error_log/data/log/error.log warn;
    indexindex.html index.htm index.php;
    root/data/www;
    autoindexoff;
    include/data/www/.htaccess;
    #400,500错误定义
    error_page  404 http://$server_name;
    #error_page  500 502 503 504  /50x.html;

    #PHP 脚本请求全部转发到 FastCGI处理. 使用FastCGI默认配置
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    #JS和CSS缓存时间设置
    location ~ .*.(js|css)?$
    {
        expires 1h;
    }

    #所有静态文件由nginx直接读取不经过tomcat或resin
    location ~ .*.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$
    {
        expires 15d;
    }
}

如果有新的虚拟机添加,则在vhost目录下拷贝一个虚拟机配置文件进行修改项目路径以及其它配置即可。

阅读全文

CentOS_6.5安装GitLab_7.51
发表于 2015-8-31 | 浏览(5246) | 服务器

一、把所有包升级到最新版本+rpm包安装

yum -y upgrade

如果网速不好,可以在360云盘下载

http://yunpan.cn/cVfDfDSvuZUff (提取码:a6c7)

curl -O https://downloads-packages.s3.amazonaws.com/centos-6.6/gitlab-7.5.1_omnibus.5.2.0.ci-1.el6.x86_64.rpm
sudo yum install openssh-server
sudo yum install postfix
sudo yum install cronie
sudo service postfix start
sudo chkconfig postfix on
sudo rpm -ivh gitlab-7.5.1_omnibus.5.2.0.ci-1.el6.x86_64.rpm

二、修改配置文件 (sudo gitlab-ctl reconfigure前需要配置的)

vim /etc/gitlab/gitlab.rb
external_url 'hostname'  ->  将其修改为  -> external_url='hostname'
如:external_url = 'www.gongfuxiang.com'

三、重置配置和启动 GitLab

sudo gitlab-ctl reconfigure
sudo lokkit -s http -s ssh

四、修改访问域名和项目域名

1;web端(gitlab-rails)
vim /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml
  ## GitLab settings
  gitlab:
    ## Web server settings (note: host is the FQDN, do not include http://)
    host: www.gongfuxiang.com
    port: 80
    https: false

2;git-shell的
vim /opt/gitlab/embedded/service/gitlab-shell/config.yml
gitlab_url: "http://www.gongfuxiang.com"

五、邮件配置(用户注册的时候使用)

vim /opt/gitlab/embedded/service/gitlab-rails/config/environments/production.rb

在  # config.action_mailer.delivery_method = :sendmail 下加入、# 表示注释。
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.smtp_settings = {
  :address              => "smtp.163.com",
  :port                 => 587,
  :domain               => 'username@163.com',
  :user_name            => 'username@163.com',
  :password             => 'password',
  :authentication       =>  :plain,
  :enable_starttls_auto => true
}

修改显示的邮箱,打开以下文件,找到指定位置,修改即可
vim /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml
# Email address used in the "From" field in mails sent by GitLab
 email_from: username@163.com
 # Email address of your support contact (default: same as email_from)
 support_email: username@163.com

六、gitlab服务开启+重启

gitlab-ctl stop停止
gitlab-ctl start 开启
gitlab-ctl restart重启

安装完成

访问 http://www.gongfuxiang.com

管理员: root

初始密码: 5iveL!fe

阅读全文

CentOS下使用Ngin反向代理配置服务器集群
发表于 2015-8-31 | 浏览(6566) | 服务器

目录结构

/data/soft/src       软件库
/data/soft/nginx    nginx安装目录
/data/www       项目根目录

1.安装PCRE库

ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ 下载最新的 PCRE 源码包,使用下面命令下载编译和安装 PCRE 包:

cd /data/soft/src
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.35.tar.gz
tar -zxvf pcre-8.35.tar.gz
cd pcre-8.35
./configure
make && make install

2.安装nginx

Nginx 一般有两个版本,分别是稳定版和开发版,您可以根据您的目的来选择这两个版本的其中一个,下面是把 Nginx 安装到 /data/soft/nginx 目录下的详细步骤:

cd /data/soft/src
wget http://nginx.org/download/nginx-1.4.2.tar.gz
tar -zxvf nginx-1.4.2.tar.gz
cd nginx-1.4.2
./configure --sbin-path=/data/soft/nginx/nginx \--conf-path=/data/soft/nginx/nginx.conf \--pid-path=/data/soft/nginx/nginx.pid \--with-http_ssl_module \--with-pcre=/data/soft/src/pcre-8.35 --with-http_gzip_static_module --with-http_stub_status_module
make && make install

其中参数 --with-http_stub_status_module 是为了启用 nginx 的 NginxStatus 功能,用来监控 Nginx 的当前状态。

cp /data/soft/nginx/nginx /etc/init.d/
/etc/init.d/nginx               启动nginx
/etc/init.d/nginx -s reload     重启nginx
/etc/init.d/nginx -s stop       关闭nginx

添加nginx开机启动
echo "/etc/init.d/nginx" >> /etc/rc.local

3.配置nginx.conf    文件位置 /data/soft/nginx/nginx.conf

user  www;# 工作进程的属主
worker_processes  4;# 工作进程数,一般与 CPU 核数等同

#error_log  logs/error.log; 
#error_log  logs/error.log  notice; 
#error_log  logs/error.log  info; 

#pid        logs/nginx.pid; 

events { 
    use epoll;#Linux 下性能最好的 event 模式
    worker_connections  2048;# 每个工作进程允许最大的同时连接数
} 

http
{
    include       mime.types; 
    default_type  application/octet-stream; 

    #log_format  main  '$remote_addr - $remote_user [$time_local] $request ' 
    #                  '"$status" $body_bytes_sent "$http_referer" ' 
    #                  '"$http_user_agent" "$http_x_forwarded_for"'; 

    #access_log  off; 
    access_log  logs/access.log;# 日志文件名

    sendfile        on; 
    #tcp_nopush     on; 
    tcp_nodelay     on; 

    keepalive_timeout  65; 

    #include     gzip.conf; #gzip压缩配置

    # 集群中的所有后台服务器的配置信息
    upstream tomcats { 
        server 192.168.14.126:81 weight=10;
        server 192.168.14.126:82 weight=10;
        server 192.168.44.126:83 weight=10;
    }

    server { 
        listen       80;#HTTP 的端口
        server_name  localhost; 

        charset utf-8; 

        #access_log  logs/host.access.log  main; 

        location ~ ^/NginxStatus/ { 
            stub_status on; #Nginx 状态监控配置
            access_log off; 
        } 

        location ~ ^/(WEB-INF)/ { 
            deny all; 
        } 

        location ~ \.(htm|html|asp|php|gif|jpg|jpeg|png|bmp|ico|rar|css|js|zip|java|jar|txt|flv|swf|mid|doc|ppt|xls|pdf|txt|mp3|wma)$ { 
            root /data/www;
            expires 24h; 
        } 

        location / { 
            proxy_pass http://tomcats; # 反向代理
            proxy_redirect off;
            proxy_set_header  X-Real-IP  $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        } 

        error_page 404 /html/404.html; 

        error_page 502 503 /html/502.html; 
        error_page 500 504 /50x.html; 
        location = /50x.html{ 
            root   html; 
        }
    }

    #引入虚拟机
    include vhost/*.conf;
}

4.在vhost目录下添加虚拟机      文件名称 /data/soft/nginx/vhost/one.conf

server {
    listen              *:81; #对于虚拟机配置端口
    server_name         localhost;
    access_log          /data/log/one_access.log;
    error_log           /data/log/one_error.log warn;
    index               index.html index.htm index.php;
    root                /data/www/one; #对应/data/www目录下创建三个目录
    autoindex           off;
    error_page          404 http://$server_name;

    location ~ .*.(js|css)?$
    {
        expires 1h;
    }

    location ~ .*.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$
    {
        expires 15d;
    }
}

创建文件 /data/www/one/index.html   内容:Th is One Node

按照此内容添加3个文件,listen和root对应修改

5.配置完成

重启nginx
访问 192.168.14.126 ,就可以看见不同效果了

阅读全文

Nginx配置支持跨域访问PHP接口
发表于 2015-8-31 | 浏览(7725) | 服务器
location ~ \.php$ {
      #允许跨域访问
      #add_header 'Access-Control-Allow-Origin' '*'; #不限域名
      add_header 'Access-Control-Allow-Origin' 'http://dev.gongfuxiang.com'; #限制域名的方式
      add_header 'Access-Control-Allow-Credentials' 'true';
      add_header 'Access-Control-Allow-Methods' 'OPTION, POST, GET';
      add_header 'Access-Control-Allow-Headers' 'X-Requested-With, Content-Type';

      #PHP配置
      fastcgi_pass   127.0.0.1:9000;
      fastcgi_index  index.php;
      fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include        fastcgi_params;
}

阅读全文

CentOS安装pcre缺少libpcre.so.0文件
发表于 2015-8-31 | 浏览(17026) | 服务器

centos 6.4 64位系统,安装pcre错误:

grep: error while loading shared libraries: libpcre.so.0: cannot open shared object file: No such file or directory

checking for grep that handles long lines and -e... configure: error: no acceptable grep could be found in /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/xpg4/bin

解决方案

wget http://mirror.centos.org/centos/6/os/x86_64/Packages/pcre-7.8-6.el6.x86_64.rpm
rpm -ivh pcre-7.8-6.el6.x86_64.rpm
上面的文件是适合我操作系统的(centos6 , 64位)。如果不适合你的系统,可以去这个网站http://pkgs.org/download/libpcre.so.0 下载适合的文件。

阅读全文

CentOS安装PHP错误:error: xml2-config not found
发表于 2015-8-31 | 浏览(5139) | 服务器

错误

configure: error: xml2-config not found. Please check your libxml2 installation.

解决方案

yum install libxml2
yum install libxml2-devel

阅读全文

安装PHP错误:configure: error: mcrypt.h not found. Plea
发表于 2015-8-31 | 浏览(4977) | 服务器

今天在编译php的时候,出现如下错误php安装出错:configure: error: mcrypt.h not found. Please reinstall libmcrypt.,意思是,没有查找到mcrytp.h,需要安装libcrytp,在下面的地址下载libmarypt:

解决办法一

1、安装第三方yum源
wget http://www.atomicorp.com/installers/atomic
chmod a+x chmod
sh ./atomic

2、使用yum命令安装
yum  install  php-mcrypt  libmcrypt  libmcrypt-devel 

解决办法二

使用php mcrypt 前必须先安装Libmcrypt

wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/attic/libmcrypt/libmcrypt-2.5.7.tar.gz

安装

tar -zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
mkdir -p /usr/local/libmcrypt
./configure prefix=/usr/local/libmcrypt/
make
make install

然后再安装PHP

========================================================================

如果以上方法仍然不能安装,请参考:

rpm -ivh "http://www.lishiming.net/data/attachment/forum/month_1211/epel-release-6-7.noarch.rpm

yum install -y libmcrypt-devel 

因为centos6.x 默认的yum源没有libmcrypt-devel 这个包,只能借助第三方yum源。

文章原创地址:http://blog.163.com/yxba_02/blog/static/1875576201272583532588/

阅读全文

Apache自带的压力测试工具 鸭梨测试ab命令详解
发表于 2015-8-31 | 浏览(5266) | 服务器

1;ab命令

ab -n100 -c10 http://mei.la/index.php
-n100 在测试会话中所执行的请求个数。默认时,仅执行一个请求
-c10 一次产生的请求个数。默认是一次一个
-t60 测试所进行的最大秒数。其内部隐含值是-n 50000,它可以使对服务器的测试限制在一个固定的总时间以内。默认时,没有时间限制
http://mei.la/index.php 目标url地址

2;测试结果

被测试的Web服务器软件名称
Server Software:        nginx

请求的URL主机名
Server Hostname:        mei.la

被测试的Web服务器软件的监听端口
Server Port:            80

请求的URL中的根绝对路径,通过该文件的后缀名,我们一般可以了解该请求的类型
Document Path:          /index.php

HTTP响应数据的正文长度
Document Length:        2041 bytes

并发用户数,这是我们设置的参数之一
Concurrency Level:      10

所有这些请求被处理完成所花费的总时间
Time taken for tests:   0.766 seconds

总请求数量,这是我们设置的参数之一
Complete requests:      100

失败的请求数量,这里的失败是指请求在连接服务器、发送数据等环节发生异常,以及无响应后超时的情况。如果接收到的HTTP响应数据的头信息中含有2XX以外的状态码,则会在测试结果中显示另一个名为       “Non-2xx responses”的统计项,用于统计这部分请求数,这些请求并不算在失败的请求中。
(Connect: 0, Receive: 0, Length: 2, Exceptions: 0)
Failed requests:        2

写入错误
Write errors:           0

所有请求的响应数据长度总和,包括每个HTTP响应数据的头信息和正文数据的长度。注意这里不包括HTTP请求数据的长度,仅仅为web服务器流向用户PC的应用层数据总长度。
Total transferred:      242120 bytes

所有请求的响应数据中正文数据的总和,也就是减去了Total transferred中HTTP响应数据中的头信息的长度
HTML transferred:       219348 byte

吞吐率,计算公式:Complete requests / Time taken for tests
Requests per second:    130.55 [#/sec] (mean)

用户平均请求等待时间,计算公式:Time token for tests/(Complete requests/Concurrency Level)
Time per request:       76.599 [ms] (mean)

服务器平均请求等待时间,计算公式:Time taken for tests/Complete requests,正好是吞吐率的倒数。也可以这么统计:Time per request/Concurrency Level
Time per request:       7.660 [ms] (mean, across all concurrent requests)

表示这些请求在单位时间内从服务器获取的数据长度,计算公式:Total trnasferred/ Time taken for tests,这个统计很好的说明服务器的处理能力达到极限时,其出口宽带的需求量
Transfer rate:          308.68 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       29   33   3.2     32      47
Processing:    30   40  24.0     35     209
Waiting:       30   37  23.6     33     203
Total:         62   73  24.5     68     244

Percentage of the requests served within a certain time (ms)
  50%     68      50%的请求在68ms内返回
  66%     71
  75%     73
  80%     75
  90%     79
  95%     87
  98%    234
  99%    244
  100%   244 (longest request)

阅读全文

Linux下使用webbench测试服务器压力
发表于 2015-8-31 | 浏览(5392) | 服务器

webbench最多可以模拟3万个并发连接去测试网站的负载能力,个人感觉要比Apache自带的ab压力测试工具好,安装使用也特别方便。

适用系统:Linux

1;安装

360云盘下载地址:

    http://yunpan.cn/ccQeU9IE5cRU7 (提取码:74e2)

wget http://blog.zyan.cc/soft/linux/webbench/webbench-1.5.tar.gz
tar zxvf webbench-1.5.tar.gz
cd webbench-1.5
make && make install

2;使用

webbench -c 500 -t 30 http://mei.la/

参数说明
  -c表示并发数,-t表示时间(秒)

3;测试结果

Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.
Benchmarking: GET http://mei.la/
500 clients, running 30 sec.

Speed=3230 pages/min, 11614212 bytes/sec.
Requests: 1615 susceed, 0 failed.

阅读全文

ubuntu下MySQL停止或启动失败
发表于 2015-8-31 | 浏览(5373) | 服务器

有些时候遇到一些奇怪的问题就是mysql不管是启动还是停止都失败。

在这里先看看进程

ps -ef | grep mysql

根据进程号直接杀死进程

kill 27362 29144 29173

然后再停止或启动操作即可

/etc/init.d/mysql stop                停止
/etc/init.d/mysql start               启动
/etc/init.d/mysql restart             重启

阅读全文

TOP