顯示具有 LANP/LNMP 標籤的文章。 顯示所有文章
顯示具有 LANP/LNMP 標籤的文章。 顯示所有文章

2023年3月5日 星期日

Cacti + LINE Notify

 [root@rocky9 thold]# cat /etc/redhat-release 

Rocky Linux release 9.1 (Blue Onyx)

[root@rocky9 thold]# php -v 

PHP 7.4.33 (cli) (built: Feb 14 2023 09:05:10) ( NTS )

Copyright (c) The PHP Group

Zend Engine v3.4.0, Copyright (c) Zend Technologies

    with Zend OPcache v7.4.33, Copyright (c), by Zend Technologies

[root@rocky9 thold]# mysql

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 2293

Server version: 10.5.16-MariaDB MariaDB Server


Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


MariaDB [(none)]> exit

Bye

[root@rocky9 thold]# 

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

Cacti ver 1.2.24

Thresholds 1.7

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

vi /var/www/html/cacti/plugins/thold/thold_functions.php


Row 5456 Insert :

    shell_exec("curl -X POST https://notify-api.line.me/api/notify -H 'Authorization: Bearer LineNotifyTokenXXXXXXXXXXXXXXXXXXXXXXXXXXXX' -F 'message=$subject \n\n'");







vi /var/www/html/cacti/lib/functions.php


Row 4705 Insert :

 shell_exec("curl -X POST https://notify-api.line.me/api/notify -H 'Authorization: Bearer LineNotifyTokenXXXXXXXXXXXXXXXXXXXXXXXXXXXX' -F 'message=$subject \n\n  $body'");










Advanced DEMO






2012年5月29日 星期二

在 Apache 伺服器上使用 memcached ( LAMP 優化 )


CentOS 5.8 升級 Apache

因為 mod_memcached_cache 這個 Apache模組,僅支援 2.2.4 之後的版本方可使用,
CentOS 5.8 的預設內建的 Apache 版本為 2.2.3-xx.
故無法使用 memcached 的外掛模組.需透過下方網站所提供的方式,
透過YUM的方式將 Apache 升級至2.2.22的版本.方可啟用  memcached 功能.


http://www.jasonlitka.com/yum-repository/

rpm --import http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka
vi /etc/yum.repos.d/utterramblings.repo
[utterramblings]
name=Jason's Utter Ramblings Repo
baseurl=http://www.jasonlitka.com/media/EL$releasever/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka

RHEL 5 / CentOS 5 :
rpm --import http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
httpd upgrade to 2.2.22
#yum upgrade --enablerepo=utterramblings httpd*
#yum upgrade --enablerepo=utterramblings mod_*

Source

#wget http://apache.stu.edu.tw//httpd/httpd-2.2.22.tar.gz
#tar -zvxf  http://apache.stu.edu.tw//httpd/httpd-2.2.22.tar.gz

Install apr_memcache

#wget http://www.outoforder.cc/downloads/apr_memcache/apr_memcache-0.7.0.tar.bz2
#tar -jvxf apr_memcache-0.7.0.tar.bz2 
#cd  apr_memcache-0.7.0/
#./configure --prefix=/usr/local/ --exec-prefix=/usr/local/
#make
#make install

Install mod_memcached_cache

#wget http://modmemcachecache.googlecode.com/files/mod_memcached_cache-0.1.0.tar.bz2
#tar -jxvf mod_memcached_cache-0.1.0.tar.bz2
#cd mod_memcached_cache-0.1.0
#CFLAGS="-I/usr/local/src/httpd-2.2.22/modules/cache/" ./configure --with-apxs=/usr/sbin/apxs  --with-apr-memcache=/usr/local/
#make
#make install
....
   * Apache Modules Directory:    /usr/lib/httpd/modules
....

讓 php 支援 memcached & memcache

yum install    --enablerepo=remi memcache*
yum install    --enablerepo=remi libmemcached*
yum install    --enablerepo=remi php-pecl-memcached
yum install    --enablerepo=remi php-pecl-memcache

[root@apache]# rpm -qa | grep mem
php-pecl-memcached-2.0.1-1.el5.remi
libmemcached-1.0.4-1.el5.remi
libmemcached-devel-1.0.4-1.el5.remi
memcached-1.4.5-2.el5.remi
memcached-devel-1.4.5-2.el5.remi
php-pecl-memcache-3.0.6-2.el5.remi

mamcached 可使用系統預設的 1.4.5 版本
或 http://memcached.org/ 所提供的 v1.4.13 的版本
在這裡我是以membase取代memcached
url為 http://www.couchbase.com/membase
download url 為 http://www.couchbase.com/download

Install membase

[root@naginx ~]# rpm -ivh couchbase-server-community_x86_1.8.0.rpm
Preparing...                ########################################### [100%]
   1:couchbase-server       ########################################### [100%]
Starting couchbase-server[  OK  ]
You have successfully installed Couchbase Server.
Please browse to http://apache:8091/ to configure your server.
Please refer to http://couchbase.com/ for additional resources.
Please note that you have to update your firewall configuration to
allow connections to the following ports: 11211, 11210, 4369, 8091
and from 21100 to 21299.
By using this software you agree to the End User License Agreement.
See /opt/couchbase/LICENSE.txt.
[root@apache ~]# netstat -an | grep 11211
tcp        0      0 0.0.0.0:11211               0.0.0.0:*                   LISTEN     
[root@apache ~]#

vi /etc/httpd/conf/httpd.conf
======================
LoadModule memcached_cache_module modules/mod_memcached_cache.so
<IfModule mod_memcached_cache.c>
        CacheEnable memcached /
        MemcachedCacheServer localhost:11211
        MemcachedMaxServers 10
        MemcachedMinConnections 10
        MemcachedSMaxConnections 10
        MemcachedMaxConnections 10
        MemcachedConnectionTTL 10
        MemcachedCacheMinFileSize 1
        MemcachedCacheMaxFileSize 2097152
        CacheDisable /admin/
        CacheDisable /server-status/
</IfModule>
============================
service httpd restart
============================

mod_memcached_cache 安裝參考的URL為 
http://www.mabishu.com/blog/2009/12/08/using-memcache-server-as-apache-content-cach/

將 membase & memcached 加入 Cacti 監控

新增 cacti 的 manager monitor port

[root@apache scripts]# pwd
/var/www/html/cacti/scripts
[root@apache scripts]# vi  ports.inc
80#HTTP
443#HTTP SSL
110#POP
995#POP SSL
25#SMTP
21#FTPD
53#DNS
389#LDAP
23#Telnet
22#SSH
3306#MYSQL
143#IMAP
993#IMAP SSL
514#RSH
8003#NAV GW
10000#Ipsec
8090#X-Ray
8080#Zope
5903#VNC
11211#memcached
8091#CouchbaseConsole

再進入 cacti \ console \ device \ TCP (Verbose Query) \ 再點選新增的監控服務即可

Cacti Manage Monitor


Couchbase Console

2012年5月28日 星期一

使用 membase 取代 memcached ( LNMP 優化 )


使用 membase 取代 memcached ( LNMP 優化 )


URL http://www.couchbase.com/membase
download http://www.couchbase.com/download

[root@nginx ~]# rpm -ivh couchbase-server-community_x86_1.8.0.rpm  --test
Preparing...                ########################################### [100%]
[root@nginx ~]# rpm -ivh couchbase-server-community_x86_1.8.0.rpm
Preparing...                ########################################### [100%]
   1:couchbase-server       ########################################### [100%]
Starting couchbase-server[  OK  ]
You have successfully installed Couchbase Server.
Please browse to http://nginx:8091/ to configure your server.
Please refer to http://couchbase.com/ for additional resources.
Please note that you have to update your firewall configuration to
allow connections to the following ports: 11211, 11210, 4369, 8091
and from 21100 to 21299.
By using this software you agree to the End User License Agreement.
See /opt/couchbase/LICENSE.txt.
[root@nginx ~]#





使用 google-perftools ( LNMP 優化 )

使用 google-perftools 優化 Nginx

在網路上看到有許多人在談論如何加速 LNMP 的使用環境.
方式為 google-perftools & ngx_cache_purge
再加上 memcache (php模組)及使用 memcached (php模組) 等

安裝 libunwind

http://download.savannah.gnu.org/releases/libunwind/
http://download.savannah.gnu.org/releases/libunwind/libunwind-1.0.1.tar.gz

#tar -zvxf libunwind-1.0.1.tar.gz
#cd libunwind-1.0.1
#CFLAGS=-fPIC ./configure --prefix=/usr
#make CFLAGS=-fPIC
#make CFLAGS=-fPIC install

安裝 google-perftools

http://code.google.com/p/gperftools/downloads/list
http://gperftools.googlecode.com/files/gperftools-2.0.tar.gz

#tar -zvxf gperftools-2.0.tar.gz
#cd gperftools-2.0
#./configure
#make
#make install

#echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
#/sbin/ldconfig


#mkdir /tmp/tcmalloc
#chmod 0777 /tmp/tcmalloc
vi /usr/local/nginx/conf/nginx.conf

#pid        logs/nginx.pid;
google_perftools_profiles /tmp/tcmalloc;

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

ngx_cache_purge
http://labs.frickle.com/nginx_ngx_cache_purge/

http://www.pcre.org/
http://sourceforge.net/projects/pcre/files/pcre/8.30/

Nginx module Source
https://github.com/agentzh/srcache-nginx-module

https://github.com/agentzh/memc-nginx-module

pcre source
http://sourceforge.net/projects/pcre/files/pcre/
http://sourceforge.net/projects/pcre/files/pcre/8.30/pcre-8.30.tar.gz/download


安裝

Nginx

./configure --prefix=/usr/local/nginx3 --user=nginx --group=nginx --with-http_ssl_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_perl_module --with-google_perftools_module --with-pcre=/usr/local/src/pcre-8.30 --add-module=/root/ngx_cache_purge-1.5 --http-proxy-temp-path=/usr/local/nginx3/proxy_temp  --add-module=/root/agentzh-memc-nginx-module-8befc56 --add-module=/root/agentzh-srcache-nginx-module-027dd06

安裝 memcache

http://pecl.php.net/package/memcache
http://pecl.php.net/get/memcache-2.2.6.tgz

#tar -zvxf memcache-2.2.6.tgz
#cd   memcache-2.2.6
#phpize
#./configure --enable-memcache

Installing shared extensions:     /usr/lib/php/modules/
==> memcache.so



安裝 memcached
yum install --enablerepo=remi  php-pecl-memcached
yum install  --enablerepo=remi   memcached
yum install  --enablerepo=remi  memcached-devel

or

http://libevent.org/
wget https://github.com/downloads/libevent/libevent/libevent-2.0.19-stable.tar.gz
tar -zvxf libevent-2.0.19-stable.tar.gz
cd libevent-2.0.19-stable
./configure
make
make test
meke install

ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib/libevent-2.0.so.5
memcached (Service ( DAEMON ) )

http://memcached.org/

wget http://memcached.googlecode.com/files/memcached-1.4.13.tar.gz
tar -zvxf memcached-1.4.13.tar.gz
cd memcached-1.4.13
./configure
make
make test
meke install

/usr/local/bin/memcached -d -m 128 -u nginx -l 127.0.0.1 -p 11211 -c 256 -P /tmp/memcached.pid
kill `cat /tmp/memcached.pid`


https://launchpad.net/libmemcached/+download
libmemcached-1.0.8.tar.gz 
./configure --prefix=/usr  --exec-prefix=usr
make
make install


http://pecl.php.net/package/memcached
http://pecl.php.net/get/memcached-2.0.1.tgz
#wget http://pecl.php.net/get/memcached-2.0.1.tgz
#tar -zvxf memcached-2.0.1.tgz
#cd   memcached-2.0.1
#phpize
#./configure --enable-memcached

Installing shared extensions:     /usr/lib/php/modules/

==> memcached.so



啟動

/usr/local/bin/memcached -d -m 128 -u nginx -l 127.0.0.1 -p 11211 -c 256 -P /tmp/memcached.pid

or
memcached -d -p 11211 -u nginx -m 64 -c 1024
memcached -d -p 11212 -u nginx -m 64 -c 1024
memcached -d -p 11213 -u nginx -m 1024
memcached -d -p 11214 -u nginx -m 1024

vi /etc/php.ini

cgi.fix_pathinfo=1

; zend_optimizer.optimization_level=15
; zend_extension=/usr/lib/php/modules/ZendOptimizer.so

zend_extension=/usr/lib/php/modules/ZendGuardLoader.so
zend_loader.enable=1
zend_loader.disable_licensing=0
zend_loader.obfuscation_level_support=3
zend_loader.license_path=

extension="eaccelerator.so"
extension="memcache.so"
eaccelerator.shm_size="16"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
[memcache]
memcache.hash_strategy = "consistent"
memcache.default_timeout_ms = 300
[root@nginx modules]#

重啟 php-fpm
#service php-rpm restart

========================
[root@nginx modules]# php -m
[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
dom
eAccelerator
ereg
exif
fileinfo
filter
ftp
gd
gettext
gmp
hash
iconv
igbinary
imap
json
ldap
libxml
mbstring
mcrypt
memcache
memcached

mhash
mysql
mysqli
odbc
openssl
pcntl
pcre
PDO
pdo_mysql
PDO_ODBC
pdo_sqlite
Phar
readline
Reflection
session
shmop
SimpleXML
snmp
soap
sockets
SPL
standard
tokenizer
wddx
xml
xmlreader
xmlwriter
xsl
Zend Guard Loader
zip
zlib
[Zend Modules]
Zend Guard Loader
eAccelerator
[root@nginx modules]#



[root@nginx conf]# cat nginx.conf
user  nginx nginx;
worker_processes  1;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;
google_perftools_profiles /tmp/tcmalloc;
events {
    worker_connections  1024;
}

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  logs/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    gzip  on;
    gzip_min_length 1k;
    gzip_buffers 16 64k;
    gzip_http_version 1.1;
    gzip_comp_level 6;
    gzip_types text/plain application/x-javascript text/css application/xml;
    gzip_vary on;
    include  /usr/local/nginx3/conf/proxy.conf;

    upstream memcached {
    server 127.0.0.1:11211;
    }

    server {
        listen       80;
        server_name  localhost;
        charset utf-8;
        #access_log  logs/host.access.log  main;
        location / {
            root   html;
            index  index.html index.htmi index.php;
            # proxy_pass  http://192.168.100.10/;
            proxy_cache             tmpcache;
            proxy_cache_key         $uri$is_args$args;
          
          
            set $key $uri$args;
            srcache_fetch GET /memc $key;
            srcache_store PUT /memc $key;
       
            #set $memcached_key      $host$uri;
            #memcached_pass   memcached;
            #default_type   text/html;
            #error_page 404 = /error_page;
   
        }
        location /memc {
         internal;
         memc_connect_timeout 100ms;
         memc_send_timeout 100ms;
         memc_read_timeout 100ms;
         set $memc_key $query_string;
         set $memc_exptime 300;
         memc_pass memcached;
        }
        #error_page  404              /404.html;
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1/;
        #}
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            fastcgi_param  SCRIPT_FILENAME   /html$fastcgi_script_name;
            include        fastcgi_params;
            set $key $uri$args;
            srcache_fetch GET /memc $key;        
            srcache_store PUT /memc $key;
        }
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
        location /server-status {
         stub_status on;
         access_log off;
         allow 127.0.0.1;
         allow 192.168.100.0/24;
         deny all;
        }
        location /nginx_status {
        stub_status on;
        # disable access_log if requared
        access_log   off;
        allow 127.0.0.1;
        allow 192.168.100.0/24;
        deny all;
        }

        location ~ /purge(/.*) {
        allow                   127.0.0.1;
        deny                    all;
        proxy_cache_purge       tmpcache   $1$is_args$args;
        }

    }

    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

    # HTTPS server
    #
    #server {
    #    listen       443;
    #    server_name  localhost;
    #    ssl                  on;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;
    #    ssl_session_timeout  5m;
    #    ssl_protocols  SSLv2 SSLv3 TLSv1;
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers   on;
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
}



[root@nginx conf]# cat proxy.conf
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 50m;
client_body_buffer_size 256k;
proxy_connect_timeout 30;
proxy_send_timeout 30;
proxy_read_timeout 60;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
proxy_max_temp_file_size 128m;
proxy_temp_path /usr/local/nginx3/proxy_temp/temp;
proxy_cache_path /usr/local/nginx3/proxy_temp/proxy levels=1:2 keys_zone=tmpcache:10m inactive=1d max_size=1g; 
proxy_cache tmpcache;
proxy_cache_valid  200 304 12h;
proxy_cache_valid  301 302 1m;
proxy_cache_valid  any 1m;
proxy_cache_key $host$uri$is_args$args;
[root@nginx conf]#


[root@CentOS6 init.d]# cat memcached
#! /bin/sh
#
# chkconfig: - 55 45
# description:  The memcached daemon is a network memory cache service.
# processname: memcached
# config: /etc/sysconfig/memcached
# pidfile: /var/run/memcached/memcached.pid
# Standard LSB functions
#. /lib/lsb/init-functions
# Source function library.
. /etc/init.d/functions
PORT=11211
USER=root
MAXCONN=1024
CACHESIZE=2048
OPTIONS="-l 127.0.0.1"
if [ -f /etc/sysconfig/memcached ];then
        . /etc/sysconfig/memcached
fi
# Check that networking is up.
. /etc/sysconfig/network
if [ "$NETWORKING" = "no" ]
then
        exit 0
fi
RETVAL=0
prog="memcached"
pidfile=${PIDFILE-/var/run/memcached/memcached.pid}
lockfile=${LOCKFILE-/var/lock/subsys/memcached}
start () {
        echo -n $"Starting $prog: "
        # Ensure that /var/run/memcached has proper permissions
        if [ "`stat -c %U /var/run/memcached`" != "$USER" ]; then
                chown $USER /var/run/memcached
        fi
        daemon --pidfile ${pidfile} /usr/local/memcached/bin/memcached -d -p $PORT -u $USER  -m $CACHESIZE -c $MAXCONN -P ${pidfile} $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch ${lockfile}
}
stop () {
        echo -n $"Stopping $prog: "
        killproc -p ${pidfile} /usr/local/memcached/bin/memcached
        RETVAL=$?
        echo
        if [ $RETVAL -eq 0 ] ; then
                rm -f ${lockfile} ${pidfile}
        fi
}
restart () {
        stop
        start
}

# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        status -p ${pidfile} /usr/local/memcached/bin/memcached
        RETVAL=$?
        ;;
  restart|reload|force-reload)
        restart
        ;;
  condrestart|try-restart)
        [ -f ${lockfile} ] && restart || :
        ;;
  *)
        echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart|try-restart}"
        RETVAL=2
        ;;
esac
exit $RETVAL

===============
mkdir /var/run/memcached
touch /var/run/memcached/memcached.pid

vi vi /etc/sysconfig/memcached

PORT="11211"
USER="root"
# max connection 2048
MAXCONN="2048"
# set ram size to 2048 - 2GiB
CACHESIZE="4096"
# listen to loopback ip 127.0.0.1, for network connection use real ip e.g., 10.0.0.4
OPTIONS="-l 127.0.0.1"