环境:centos 6.0 64
准备条件:LNMP nginx、PHP、GD、bcmath、ctype、libxml、mbstring、mysql
一、Mysql的安装
1、安装准备
1)、下载Mysql
wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.23.tar.gz/from/http://mirror.services.wisc.edu/mysql/
2)、安装编译所需要的文件或程序
5.5以后的mysql版本需要通过cmake来编译
yum install gcc gcc-c++ cmake ncurses-devel bison
2、添加Mysql用户
useradd -s /sbin/nologin mysql
3、编译安装
1)、解压mysql
tar zxvf mysql-5.5.23.tar.gz
cd mysql-5.5.23
cmake -DMYSQL_USER=mysql \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_DEBUG=0
make -j 2 && make install
注:-j 用来指定CPU核心数,可加快编译速度,不加也可以。
修改权限
chown -R mysql.mysql /usr/local/mysql/
复制相关文件
cd /usr/local/mysql
cp support-files/my-innodb-heavy-4G.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld\
Mysql初始化
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/
编辑配置文件
vi /etc/my.cnf
在[mysqld]项里添加
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
设置默认引擎为 INnoDB
default-storage-engine = INNODB
启动Mysql
/etc/init.d/mysqld start
二、Nginx安装
在nginx.org下载nginx
yum install gcc openssl-devel pcre-devel zlib-devel
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/tmp/nginx/client/ \
--http-proxy-temp-path=/var/tmp/nginx/proxy/ \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
--with-poll_module
make
make install
ldcofnig
三、PHP编译安装
1.编译安装mhash-0.9.9.9.tar.gz libmcrypt-2.5.8.tar.gz mcrypt-2.6.8.tar.gz
直接解压 make&& make install
出现如下问题
*** If you have an old version installed, it is best to remove it, although
*** you may also be able to get things to work by modifying LD_LIBRARY_PATH
***configure: error: *** libmcrypt was not found
--------------
解决方法:
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
2.编译php,版本5.4.4
./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --enable-fpm --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-libxml-dir=/usr --enable-xml --with-mhash --with-mcrypt --with-config-file-path=/etc/php --with-config-file-scan-dir=/etc/php --with-bz2 --with-curl --enable-bcmath --enable-sockets --with-gettext
3.动态编译php的gd库
安装 gd 前置库 : freetype ,jpegsrc,libpng,
依次进入各个目录执行
./configure --prefix=/usr/local/freetype && make && make install
./configure --prefix=/usr/local/jpeg && make && make install
./configure --prefix=/usr/local/libpng && make && make install
接着cd 到php源码的gd目录
cd $pwd/php-5.4.4/ext/gd
一定要在这个目录下执行 /usr/local/php/bin/phpize
接着在当前目录下执行:
./configure --with-php-config=/usr/local/php/bin/php-config --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/libpng --with-freetype-dir=/usr/local/freetype
make && make install
接着修改php.ini文件 在 ;extension=php_zip.dll 下面添加一行 extension=gd.so
这样在执行 /usr/local/php/bin/php -m 查看gd模块是否加载成功。
4.php配置文件:
# cp php.ini-production /etc/php/php.ini
为php-fpm提供Sysv init脚本,并将其添加至服务列表:
# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
# chkconfig --add php-fpm
# chkconfig php-fpm on
为php-fpm提供配置文件:
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
编辑php-fpm的配置文件:
# vim /usr/local/php/etc/php-fpm.conf
配置pm.的相关选项为你所需要的值,并启用pid文件(如下最后一行):
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8
pid = /var/run/php-fpm.pid
接下来就可以启动php-fpm了:
# service php-fpm start
使用如下命令来验正(如果此命令输出有中几个php-fpm进程就说明启动成功了):
# ps aux | grep php-fpm
php-fpm脚本可在php目录下 find ./ -name "init*"
5.整合nginx和php5
1)、编辑/etc/nginx/nginx.conf,启用如下选项:
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
#最终配置请参考下面zabbix
2).
查看/etc/nginx/fastcgi_params,一般不需要修改,如不是,将其内容更改为如下内容:
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
四、Zabbix的安装
1.下载zabbix文件
wget %20Latest%20Stable/2.0.1/zabbix-2.0.1.tar.gz/download
2.
tar zxvf zabbix-2.0.1.tar.gz
3.创建zabbx用户
groupadd zabbix
useradd -g zabbix zabbix -s /sbin/nologin
4.编译作为server和agent
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl
5.make install
6.安装成功,编辑文件
/usr/local/etc/zabbix_agentd.conf 指定server地址
Server=127.0.0.1
ServerActive=127.0.0.1
Hostname=Zabbix server#Hostname是唯一的,不能重复
/usr/local/etc/zabbix_server.conf 指定数据库用户名、密码
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
7.创建数据库
create database zabbix;
grant all on zabbix.* to zabbix@'localhost' identified by 'zabbix';
配置访问权限
8.启动zabbix_server
/usr/local/zabbix/sbin/zabbix_server
zabbix_server: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/
9.copy zabbix文件
cp -a /opt/soft/zabbix/zabbix-2.0.1/frontends/php/* /usr/local/zabbix/
10.创建数据库
create database zabbix;
grant all on zabbix.* to zabbix@'localhost' identified by 'zabbix';
配置访问权限
11.zabbix 的nginx配置
server {
listen 80;
server_name 192.168.1.102;
access_log logs/access_zabbix.log main;
location / {
index index.html index.php;
root /usr/local/zabbix/php;
}
location ~ \.php$ {
root /usr/local/zabbix/php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/zabbix/php/$fastcgi_script_name;
include fastcgi_params;
}
}
12.所有配置完成以后,启动mysql、nginx、php-fpm、zabbix_server、Zabbix_agentd
浏览器里输入
会出现图形化安装界面,依次填入,最后会生成文件/usr/local/zabbix/php/conf/zabbix.conf.php
输入用户名:admin密码:zabbix可以正常访问
解决字体乱码问题:
在win下copy 字体文件simhei.ttf到 /usr/local/zabbix/fonts
删除以前的字体文件
将simhei.tty改名为DejaVuSans.tt