程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> 關於MYSQL數據庫 >> nginx+mysql+php+cacti+rrdtool全方位急速版

nginx+mysql+php+cacti+rrdtool全方位急速版

編輯:關於MYSQL數據庫
時間調整:
/usr/sbin/ntpdate stdtime.sinica.edu.tw centos5.2 系統測試OK 1、給系統刷新下yum 主件加速yum安裝的速度;
yum -y install yum-fastestmirror.noarch warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID*****
錯誤 執行rpm --import /etc/pki/rpm-gpg/RPM*解決再用解決!
2、更新下系統必須組件;
sudo -s
LANG=C
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 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clIEnts openldap-servers
sudo -s
LANG=C
yum install elfutils elfutils-devel beecrypt beecrypt-devel net-snmp net-snmp-devel lm_sensors lm_sensors-devel zlib zlib-devel libpng libpng-devel freetype freetype-devel libart_lgpl libart_lgpl-devel tcl tcl-devel perl-XML-Parser freetype*
sudo -s
LANG=C
yum install fontconfig fontconfig-devel cairo cairo-devel glib glib-devel pango pango-devel intltool intltool-devel gd gd-devel net-snmp-utils PHP-snmp 以上yum 安裝高手自己挑選,新手照葫蘆話即可! mkdir -p /user/soft
cd /user/soft
3、安裝nginx+MySQL+PHP;
tar zxvf libiconv-1.13.tar.gz
cd libiconv-1.13/
./configure --prefix=/usr/local
make
make install
cd ../ tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure
make
make install
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make
make install
cd ../../ tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make
make install
cd ../ 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/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1 tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make
make install
cd ../ /usr/sbin/groupadd MySQL
/usr/sbin/useradd -g mysql MySQL
tar zxvf MySQL-5.1.38.tar.gz
cd MySQL-5.1.38/
./configure --prefix=/user/web/mysql/ --sysconfdir=/etc --localstatedir=/var/lib/MySQL --with-charset=gbk --with-extra-charset=all --with-low-memory --enable-assembler --with-extra-charsets=complex --enable-thread-safe-clIEnt --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=innobase
make && make install
/user/web/mysql/bin/MySQL_install_db
/usr/sbin/useradd -M -o -r -d /var/lib/MySQL -s /bin/bash -c "MySQL Server" -u 27 MySQL
chown -R mysql:mysql /var/lib/MySQL
chmod -R 755 /var/lib/MySQL
chmod +w /user/web/MySQL
chown -R mysql:mysql /user/web/MySQL
cp support-files/my-medium.cnf /etc/my.cnf
cp support-files/mysql.server /etc/rc.d/init.d/MySQLd
chmod 755 /etc/rc.d/init.d/MySQLd
/sbin/chkconfig --add MySQLd
/sbin/chkconfig MySQLd on
cp /user/web/MySQL/bin/* /usr/sbin
ln -s /user/web/mysql/lib/mysql /usr/lib/MySQL
ln -s /user/web/mysql/include/mysql /usr/include/MySQL
cd ../ service MySQLd restart
mysql -uroot -p GRANT ALL PRIVILEGES ON *.* TO IDENTIFIED BY 'JackHuang2009' WITH GRANT OPTION; (注意:192.168.1.101上面使用了Navicat Lite for MySQL管理軟件的Windows服務器IP)
修改root密碼為:"JackHuang2009"
tar zxvf PHP-5.2.10.tar.gz
gzip -cd php-5.2.10-fpm-0.5.11.diff.gz | patch -d PHP-5.2.10 -p1
cd PHP-5.2.10/
./configure --prefix=/user/web/php --with-config-file-path=/user/web/PHP/etc --with-mysql=/user/web/mysql --with-mysqli=/user/web/mysql/bin/MySQL_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-XML --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-CGI-redirect --enable-mbstring --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 --without-pear --enable-FTP
make ZEND_EXTRA_LIBS='-liconv'
make install
cp php.ini-dist /user/web/php/etc/PHP.ini
cd ../ tar zxvf memcache-2.2.5.tgz
cd memcache-2.2.5/
/user/web/php/bin/PHPize
./configure --with-php-config=/user/web/php/bin/PHP-config
make
make install
cd ../ tar jxvf eaccelerator-0.9.5.3.tar.bz2
cd eaccelerator-0.9.5.3/
/user/web/php/bin/PHPize
./configure --enable-eaccelerator=shared --with-php-config=/user/web/php/bin/PHP-config
make
make install
cd ../ tar zxvf PDO_MySQL-1.0.2.tgz
cd PDO_MySQL-1.0.2/
/user/web/php/bin/PHPize
./configure --with-php-config=/user/web/php/bin/PHP-config --with-pdo-mysql=/user/web/MySQL
make
make install
cd ../ tar zxvf ImageMagick.tar.gz
cd ImageMagick-6.5.1-2/
./configure
make
make install
cd ../ tar zxvf imagick-2.2.2.tgz
cd imagick-2.2.2/
/user/web/php/bin/PHPize
./configure --with-php-config=/user/web/php/bin/PHP-config
make
make install
cd ../ 修改PHP.ini文件
vim /user/web/php/etc/PHP.ini
  手工修改:查找/user/web/php/etc/PHP.ini中的extension_dir = "./"
  修改為extension_dir = "/user/web/php/lib/PHP/extensions/no-debug-non-zts-20060613/" extension = "memcache.so"
extension = "pdo_MySQL.so"
extension = "imagick.so"
  再查找output_buffering = Off
  修改為output_buffering = On 配置eAccelerator加速PHP:
mkdir -p /user/web/eacceleratorcaches
chmod 755 /user/web/eacceleratorcaches
vi /user/web/php/etc/PHP.ini
  按shift+g鍵跳到配置文件的最末尾,加上以下配置信息: [eaccelerator]
zend_extension="/user/web/php/lib/PHP/extensions/no-debug-non-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="64"
eaccelerator.cache_dir="/user/web/eacceleratorcaches"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="3600"
eaccelerator.shm_prune_period="3600"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9" /usr/sbin/groupadd nginx
/usr/sbin/useradd -g nginx nginx vi /user/web/php/etc/PHP-fpm.conf <value name="display_errors">0</value> <value name="display_errors">1</value>       Unix user of processes  
修改其下面user及group用戶名稱為如下:
        <value name="user">nginx</value>
        <value name="group">nginx</value> ulimit -SHn 65535
/user/web/php/sbin/PHP-fpm start tar zxvf pcre-7.9.tar.gz
cd pcre-7.9/
./configure
make && make install
cd ../ tar zxvf nginx-0.8.15.tar.gz
cd nginx-0.8.15/
bzcat ../nginx-Accesskey-2.0.3.diff.bz2 | patch -p1
./configure --user=nginx --group=nginx --prefix=/user/web/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_stub_status_module --with-http_Accesskey_module --with-md5=/usr/lib
make && make install
cd ../ mkdir -p /user/web/Html
chmod -R 755 /user/web/Html
chown -R nginx:nginx /user/web/Html 修改nginx配置:
vim /user/web/nginx/conf/nginx.conf
如下引用: user nginx;
worker_processes 8;
error_log logs/error.log crit;
pid        logs/nginx.pid; events use epoll;
worker_connections 65535;
} http {
include       mime.types;
default_type application/octet-stream;
Access_log off;
sendfile        on;
tcp_nopush     on;
keepalive_timeout 65;
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 on;
gzip_min_length 1k;
gzip_buffers     4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types       text/plain application/x-Javascript text/CSS application/XML;
gzip_vary on;
    server {
        listen       80;
        server_name localhost;
        location / {
            root   /user/web/Html;
            index index.html index.PHP; error_page   402 403 404 /missing.Html;
error_page   500 502 503 504 /missing.Html;
        location = /missing.Html {
            root   /user/web/Html;
        } location ~ \.PHP$ {
            root           /user/web/Html;
            fastCGI_pass   127.0.0.1:9000;
            fastCGI_index index.PHP;
            include        fastCGI_params;         location ~ /\.ht {
            deny all;     }
} vim /user/web/nginx/conf/fastCGI_params
如下引用: 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 GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE    nginx; 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; # PHP only, required if PHP was built with --enable-force-CGI-redirect
fastCGI_param REDIRECT_STATUS    200; vim /etc/rc.local ulimit -SHn 65535
/user/web/php/sbin/PHP-fpm start
/user/web/nginx/sbin/nginx 優化Linux內核參數:
vim /etc/sysctl.conf
shift+G 最後面填加: net.ipv4.tcp_max_syn_backlog = 65536
net.core.Netdev_max_backlog = 32768
net.core.somaxconn = 32768 net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216 net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retrIEs = 2
net.ipv4.tcp_syn_retrIEs = 2 net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_len = 1
net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_max_orphans = 3276800 net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 120
net.ipv4.ip_local_port_range = 1024 65535 最後執行生效修改生效命定:
/sbin/sysctl -p OK 以上MySQL+nginx+php安裝就結束了,我們可以在/user/web/htm文件夾下, vim index.php <?PHP
PHPinfo();
?>
訪問即可查看是否OK!配置snmp:
vim /etc/snmp/snmpd.conf
更改 1、com2sec notConfigUser default       public
       改為:com2sec notConfigUser   127.0.0.1       public
       2、Access notConfigGroup ""      any       noauth    exact systemvIEw none none
       改為:Access notConfigGroup ""      any       noauth    exact all none none
       3、#vIEw all    included .1         80 保存退出 :wq
service snmpd restart tar zxvf rrdtool-1.3.9.tar.gz
cd rrdtool-1.3.9
./configure --prefix=/user/web/rrdtool --disable-tcl --disable-Python
make
make install
cd ../ ln -s /user/web/rrdtool/bin/rrdtool /usr/bin/rrdtool
ln -s /user/web/rrdtool/bin/rrdupdate /usr/bin/rrdupdate
ln -s /user/web/rrdtool/bin/rrdcgi /usr/bin/rrdCGI cd /user/soft
tar zxvf cacti-0.8.7d-cn-utf8.gz
mv cacti-0.8.7d-cn-utf8 /user/web/Html/cacti
/user/web/mysql/bin/mysql -uroot -pJackHuang2009 create database cacti; /user/web/mysql/bin/MySQL -uroot -pJackHuang2009 cacti < /user/web/Html/cacti/cacti.sql
chown -R nginx:nginx /user/web/Html/cacti
chmod -R 777 /user/web/Html/cacti/rra
chmod -R 777 /user/web/html/cacti/log vim /user/web/Html/cacti/include/config.PHP
填寫自己設置的連接數據庫的帳戶密碼 crontab -u root -e
*/5 * * * * /user/web/php/bin/PHP /user/web/Html/cacti/poller.PHP > /dev/null 2>&1 1、cacti監控nginx服務:
nginx編譯時允許http_stub_status_module
在conf文件添加如下:
# vi /user/web/nginx/conf/nginx.conf
location /nginx_status {
stub_status on;
Access_log off; 重啟動
killall nginx
/user/web/nginx/sbin/nginx tar zxvf cacti-nginx.tar.gz
cp cacti-nginx/get_nginx_socket_status.pl /user/web/Html/cacti/scripts/
cp cacti-nginx/get_nginx_clIEnts_status.pl /user/web/Html/cacti/scripts/
chmod 755 /user/web/Html/cacti/scripts/get_nginx*
在cacti管理面板導入:
cacti_graph_template_nginx_clIEnts_stat.XML
cacti_graph_template_nginx_sockets_stat.XML /user/web/Html/cacti/scripts/get_nginx_clIEnts_status.pl http://127.0.0.1/nginx_status 2、cacti監控apache服務:
對apache Server Status的啟用
對apache的狀態管理的模塊是LoadModule status_module modules/mod_status.so,所以這個需要有 ExtendedStatus On
配置apache Server Status的權限 <location /server-status>
         SetHandler server-status
         Order Deny,Allow
         Allow from 127.0.0.1
</location>
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved