lnmp環境下編譯安裝zabbix可以在各大逛網上下載和安裝。接下來一個個安裝,linux,nginx,mysql,php由於linux實現安裝好,接下來安裝nginx,mysql,php來一步步的演示。

 



                        <一>nginx的安裝和相關的配置

1,首先從官網上下載需要安裝nginx版本(http://nginx.org/en/download.html)我以nginx1.8.0

為準。

2,安裝前需要 prce和openssl包的支援,首先要yum安裝。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
[root@localhost install]# yum install prce*
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: mirrors.pubyun.com
 * extras: mirrors.pubyun.com
 * updates: mirrors.pubyun.com
base                                                     | 3.7 kB     00:00     
base/primary_db                                          | 4.6 MB     00:00     
extras                                                   | 3.4 kB     00:00     
extras/primary_db                                        |  27 kB     00:00     
updates                                                  | 3.4 kB     00:00     
updates/primary_db                                       | 1.3 MB     00:00     
Setting up Install Process
No package prce* available.
[root@localhost install]# yum -y install pcre-devel openssl openssl-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.pubyun.com
 * extras: mirrors.pubyun.com
 * updates: mirrors.pubyun.com
Setting up Install Process
No package prce* available.
Error: Nothing to do
[root@localhost install]# yum -y install openssl*
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.pubyun.com
 * extras: mirrors.pubyun.com
 * updates: mirrors.pubyun.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package openssl.x86_64 0:1.0.1e-15.el6 will be updated
---> Package openssl.x86_64 0:1.0.1e-42.el6 will be an update
---> Package openssl-devel.x86_64 0:1.0.1e-42.el6 will be installed
--> Processing Dependency: zlib-devel for package: openssl-devel-1.0.1e-42.el6.x86_64
--> Processing Dependency: krb5-devel for package: openssl-devel-1.0.1e-42.el6.x86_64
---> Package openssl-perl.x86_64 0:1.0.1e-42.el6 will be installed
--> Processing Dependency: perl(vars) for package: openssl-perl-1.0.1e-42.el6.x86_64
--> Processing Dependency: perl(strict) for package: openssl-perl-1.0.1e-42.el6.x86_64
--> Processing Dependency: perl(WWW::Curl::Easy) for package: openssl-perl-1.0.1e-42.el6.x86_64
--> Processing Dependency: perl(IO::Handle) for package: openssl-perl-1.0.1e-42.el6.x86_64
--> Processing Dependency: perl(Getopt::Std) for package: openssl-perl-1.0.1e-42.el6.x86_64
Dependency Updated:
  e2fsprogs.x86_64 0:1.41.12-22.el6                                             
  e2fsprogs-libs.x86_64 0:1.41.12-22.el6                                        
  keyutils-libs.x86_64 0:1.4-5.el6                                              
  krb5-libs.x86_64 0:1.10.3-42.el6                                              
  libcom_err.x86_64 0:1.41.12-22.el6                                            
  libselinux.x86_64 0:2.0.94-5.8.el6                                            
  libselinux-utils.x86_64 0:2.0.94-5.8.el6                                      
  libss.x86_64 0:1.41.12-22.el6                                                 
Complete!

3,對nginx進行解壓

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@localhost install]# tar zxvf nginx-1.8.0.tar.gz 
nginx-1.8.0/
nginx-1.8.0/auto/
nginx-1.8.0/conf/
nginx-1.8.0/contrib/
nginx-1.8.0/src/
nginx-1.8.0/configure
nginx-1.8.0/LICENSE
nginx-1.8.0/README
nginx-1.8.0/html/
nginx-1.8.0/man/
nginx-1.8.0/CHANGES.ru
nginx-1.8.0/CHANGES
nginx-1.8.0/man/nginx.8
nginx-1.8.0/html/50x.html
nginx-1.8.0/html/index.html

4,編譯安裝:

1
2
3
4
5
6
7
8
9
10
./configure --prefix=/usr/local/nginx   
--with-http_ssl_module 
--with-http_spdy_module 
--with-http_stub_status_module 
--with-pcre           
其中:
--with-http_stub_status_module:支援nginx狀態查詢
--with-http_ssl_module:支援https
--with-http_spdy_module:支援google的spdy,想了解請百度spdy,這個必須有ssl的支援
--with-pcre:為了支援rewrite重寫功能,必須制定pcre
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@localhost nginx-1.8.0]# ./configure --prefix=/usr/local/nginx   --with-http_ssl_module --with-http_spdy_module --with-http_stub_status_module --with-pcre
checking for OS
 + Linux 2.6.32-431.el6.x86_64 x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC) 
checking for gcc -pipe switch ... found
checking for gcc builtin atomic operations ... found
checking for C99 variadic macros ... found
checking for gcc variadic macros ... found
checking for unistd.h ... found
checking for inttypes.h ... found
checking for limits.h ... found
[root@localhost nginx-1.8.0]# make
[root@localhost nginx-1.8.0]# make install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
5,[root@localhost html]# vi /usr/local/nginx/conf/nginx.conf
worker_processes  1;
error_log  /data/nginx/error.log;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    access_log      /data/nginx/access.log;
    keepalive_timeout  65;
    gzip  on;
    
  upstream test.com{
        server 192.168.1.245:80;
              }
    server {
         listen       80;
         server_name  localhost;
        access_log  /data/nginx/log/nginx.access.log;
        index index.php  index.html;
         root      /usr/local/nginx/html;
       # root    /data/php;
       # root    /data/test/php;
       # root    /data/www/php;
         error_page 500 502 503 /50x.html;
     location ~ .php$
         {
            # root   /usr/local/nginx/html/zabbix;
             expires -1s;
             #index index.php  index.html;
             fastcgi_split_path_info ^(.+.php)(/.+)$;
             include fastcgi_params;
             fastcgi_param PATH_INFO $fastcgi_path_info;
             fastcgi_index index.php;
             fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
             fastcgi_pass 127.0.0.1:9000;
           }
    }
}

備註:

常見的安裝配置一:

1
2
3
4
5
6
7
8
9
./configure --prefix=/usr/local/nginx 
--with-http_ssl_module 
--with-http_gzip_static_module 
--with-http_realip_module  
--with-http_stub_status_module 
--with-http_stub_status_module 
--with-pcre=/tmp/install/nginx/pcre-8.36 
--with-openssl=/tmp/install/nginx/openssl-1.0.2a 
--with-zlib=/tmp/install/nginx/zlib-1.2.8


常見的安裝配置二:

1
2
3
4
5
6
7
8
9
10
11
./configure --prefix=/usr/local/nginx 
--user=nginx 
--group=nginx 
--with-http_ssl_module 
--with-http_realip_module 
--with-http_flv_module 
--with-http_gunzip_module 
--with-http_gzip_static_module 
--with-http_stub_status_module 
--http-log-path=/data/logs/nginx/access.log 
--error-log-path=/data/logs/nginx/error.log


6,為nginx提供SysV init指令碼,新建檔案/etc/rc.d/init.d/nginx,把以下內容複製到前面提到的目錄下:

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

7新增啟動項並做成服務:

1
2
3
4
5
6
7
8
9
10
11
12
[root@localhost nginx-1.8.0]chmod +x /etc/rc.d/init.d/nginx
[root@localhost nginx-1.8.0]chkconfig --add nginx
[root@localhost nginx-1.8.0]chkconfig  nginx on
[root@localhost nginx-1.8.0]service nginx start
[root@localhost php]# /etc/init.d/nginx restart
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Stopping nginx: [  OK  ]
Starting nginx: [  OK  ]
[root@localhost php]# ps -A|grep nginx
11724 ?        00:00:00 nginx
11725 ?        00:00:00 nginx