一、下載nginx
http://nginx.org/download/nginx-1.12.1.tar.gz
二、下載MySQL
https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.19.tar.gz
三、下載php
http://hk1.php.net/get/php-7.1.8.tar.gz/from/this/mirror
四、下載cmake(MySQL編譯工具)
https://cmake.org/files/v3.9/cmake-3.9.1.tar.gz
五、下載pcre (支持nginx僞靜態)
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.41.tar.gz
六、下載openssl(nginx擴展)
https://www.openssl.org/source/openssl-1.1.0f.tar.gz
七、下載zlib(nginx擴展)
http://www.zlib.net/zlib-1.2.11.tar.gz
八、下載libmcrypt(php擴展)
https://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
九、下載yasm(php擴展)
http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
十、t1lib(php擴展)
http://download.freenas.org/distfiles/t1lib-5.1.2.tar.gz
十一、下載gd庫安裝包
https://github.com/libgd/libgd/releases/download/gd-2.2.4/libgd-2.2.4.tar.gz
十二、libvpx(gd庫須要)
http://storage.googleapis.com/downloads.webmproject.org/releases/webm/libvpx-1.6.1.tar.bz2
1三、tiff(gd庫須要)
http://download.osgeo.org/libtiff/tiff-4.0.8.tar.gz
1四、libpng(gd庫須要)
https://nchc.dl.sourceforge.net/project/libpng/libpng16/1.6.32/libpng-1.6.32.tar.gz
1五、freetype(gd庫須要)
http://ftp.yzu.edu.tw/nongnu/freetype/freetype-2.8.tar.gz
1六、jpegsrc(gd庫須要)
http://www.ijg.org/files/jpegsrc.v9b.tar.gz、
1七、Boost(編譯mysql須要)
https://nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
以上軟件包上傳到/usr/local/src目錄php
yum install -y apr* autoconf automake bison bzip2 bzip2* cloog-ppl compat* \ cpp curl curl-devel fontconfig fontconfig-devel freetype freetype* freetype-devel \ gcc gcc-c++ gtk+-devel gd gettext gettext-devel glibc kernel kernel-headers \ keyutils keyutils-libs-devel krb5-devel libcom_err-devel libpng libpng-devel \ libjpeg* libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp \ libxml2 libxml2-devel libXpm* libxml* libXaw-devel libXmu-devel libtiff libtiff* \ make mpfr ncurses* ntp openssl openssl-devel patch pcre-devel perl php-common \ php-gd policycoreutils telnet t1lib t1lib* nasm nasm* wget zlib-devel \
cd /usr/local/src tar zxvf cmake-3.9.1.tar.gz cd cmake-3.9.1 ./configure make make install
cd /usr/local/src mkdir -p /usr/local/boost cp boost_1_65_0.tar.gz /usr/local/boost useradd -s /sbin/nologin mysql #建立用戶mysql,不容許mysql用戶直接登陸系統 mkdir -p /data/mysql #建立MySQL數據庫存放目錄 chown -R mysql:mysql /data/mysql #設置MySQL數據庫存放目錄權限 mkdir -p /usr/local/mysql #建立MySQL安裝目錄 cd /usr/local/src #進入軟件包存放目錄 tar xf mysql-5.7.19.tar.gz #解壓 cd mysql-5.7.19 #進入目錄 cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/data/mysql \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_EMBEDDED_SERVER=OFF \ -DDOWNLOAD_BOOST=1 \ -DWITH_BOOST=/usr/local/boost \ -DSYSCONFDIR=/etc \
注意:可使用 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost 參數在線安裝boost軟件包,須要服務器聯網,容易下載失敗。html
編譯出錯, 從新編譯前要刪除編譯失敗的文件,從新編譯時,須要清除舊的對象文件和緩存信息。mysql
make clean rm -f CMakeCache.txt
make #編譯 make install #安裝
rm -rf /etc/my.cnf #刪除系統默認的配置文件(若是默認沒有就不用刪除) ps aux|grep mysql|grep 'my.cnf' #查看使用的配置文件 mysql --help|grep 'my.cnf' # 讀取配置文件路徑 cd /usr/local/mysql #進入MySQL安裝目錄 ./bin/mysqld --user=mysql --initialize --basedir=/usr/local/mysql --datadir=/data/mysql #生成mysql系統數據庫 --initialize表示默認生成密碼, --initialize-insecure 表示不生成密碼, 密碼爲空。 看到這一行[Note] A temporary password is generated for root@localhost: i>X18*=Rav=7 ln -s /usr/local/mysql/my.cnf /etc/my.cnf #添加到/etc目錄的軟鏈接 cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld #把Mysql加入系統啓動 chmod 755 /etc/init.d/mysqld #增長執行權限 chkconfig mysqld on #加入開機啓動 vim /etc/rc.d/init.d/mysqld #編輯 basedir=/usr/local/mysql #MySQL程序安裝路徑 datadir=/data/mysql #MySQl數據庫存放目錄 vim /etc/profile #把mysql服務加入系統環境變量:在最後添加下面這一行 export PATH=$PATH:/usr/local/mysql/bin 下面這兩行把myslq的庫文件連接到系統默認的位置,這樣你在編譯相似PHP等軟件時能夠不用指定mysql的庫文件地址。 ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql ln -s /usr/local/mysql/include/mysql /usr/include/mysql mkdir /var/lib/mysql #建立目錄 ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock #添加軟連接 mysql_secure_installation #修改Mysql密碼,輸入以前生成的密CSJlm3DyTG.d回車,根據提示操做 Press y|Y for Yes, any other key for No: y #是否安裝密碼安全插件?選擇y There are three levels of password validation policy: #有如下幾種密碼強度選擇 LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0 #選擇0,只要8位數字便可,選1要有大寫,小寫,特殊字符等 UNINSTALL PLUGIN validate_password ; #卸載密碼強度插件 use mysql; update mysql.user set authentication_string=password('123456') where user='root' ; #登陸mysql控制檯修改
cd /usr/local/src mkdir /usr/local/pcre tar zxvf pcre-8.41.tar.gz cd pcre-8.41 ./configure --prefix=/usr/local/pcre make make install
cd /usr/local/src mkdir /usr/local/openssl tar zxvf openssl-1.1.0f.tar.gz cd openssl-1.1.0f ./config --prefix=/usr/local/openssl make make install vim /etc/profile export PATH=$PATH:/usr/local/openssl/bin source /etc/profile
cd /usr/local/src tar zxvf zlib-1.2.11.tar.gz cd zlib-1.2.11 ./configure --prefix=/usr/local/zlib make make install
useradd -s /sbin/nologin www cd /usr/local/src tar zxvf nginx-1.12.1.tar.gz cd nginx-1.12.1 ./configure --prefix=/usr/local/nginx \ --without-http_memcached_module \ --user=www \ --group=www \ --with-http_stub_status_module \ --with-http_ssl_module \ --with-http_gzip_static_module \ --with-openssl=/usr/local/src/openssl-1.1.0f \ --with-zlib=/usr/local/src/zlib-1.2.11 \ --with-pcre=/usr/local/src/pcre-8.41 \ 注意:--with-openssl=/usr/local/src/openssl-1.1.0f --with-zlib=/usr/local/src/zlib-1.2.11 --with-pcre=/usr/local/src/pcre-8.41 指向的是源碼包解壓的路徑,而不是安裝的路徑,不然會報錯 make make install 配置NGINX systemd service (注意:根據本身配置,配置路徑信息!) vim /usr/lib/systemd/system/nginx.service [Unit] Description=The NGINX HTTP and reverse proxy server After=syslog.target network.target remote-fs.target nss-lookup.target [Service] Type=forking ExecStartPre=/usr/local/nginx/sbin/nginx -t ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/local/nginx/sbin/nginx restart ExecStop=/usr/local/nginx/sbin/nginx stop PrivateTmp=true [Install] WantedBy=multi-user.target 編譯安裝的nginx不會作日誌分割 vim logrotate.sh #!/bin/bash cd /var/log/nginx mv access.log access.log.$(date +%F) mv error.log error.log.$(date +%F) kill -USR1 $(cat /var/log/nginx/run/nginx.pid) sleep 1 gzip access.log.$(date +%F) gzip error.log.$(date +%F) 經過crontab實現定時日誌輪替。
cd /usr/local/src tar zxvf yasm-1.3.0.tar.gz cd yasm-1.3.0 ./configure make make install
cd /usr/local/src tar zxvf libmcrypt-2.5.8.tar.gz cd libmcrypt-2.5.8 ./configure make make install
cd /usr/local/src tar zxvf libvpx-1.6.1.tar.bz2 cd libvpx-1.6.1 ./configure --prefix=/usr/local/libvpx --enable-shared --enable-vp9 make make install
cd /usr/local/src tar zxvf tiff-4.0.8.tar.gz cd tiff-4.0.8 ./configure --prefix=/usr/local/tiff --enable-shared make make install
cd /usr/local/src tar zxvf libpng-1.6.32.tar.gz cd libpng-1.6.32 ./configure --prefix=/usr/local/libpng --enable-shared make make install
cd /usr/local/src tar zxvf freetype-2.8.tar.gz cd freetype-2.8 ./configure --prefix=/usr/local/freetype --enable-shared make make install
cd /usr/local/src tar zxvf jpegsrc.v9b.tar.gz cd jpeg-9b ./configure --prefix=/usr/local/jpeg --enable-shared make make install
cd /usr/local/src tar zxvf libgd-2.2.4.tar.gz cd libgd-2.2.4 ./configure --prefix=/usr/local/libgd \ --enable-shared \ --with-jpeg=/usr/local/jpeg \ --with-png=/usr/local/libpng \ --with-freetype=/usr/local/freetype \ --with-fontconfig=/usr/local/freetype \ --with-xpm=/usr/lib64 \ --with-tiff=/usr/local/tiff \ make make install 說明:若是libgd編譯失敗,能夠先跳過,直接使用系統默認的2.1.0版本,在編譯php的時候把參數--with-gd=/usr/local/libgd修改成--with-gd便可。
cd /usr/local/src tar zxvf t1lib-5.1.2.tar.gz cd t1lib-5.1.2 ./configure --prefix=/usr/local/t1lib --enable-shared make without_doc make install
注意:若是系統是64位,請執行如下兩條命令,不然安裝php會出錯。linux
cp -frp /usr/lib64/libltdl.so* /usr/lib/ cp -frp /usr/lib64/libXpm.so* /usr/lib/
cd /usr/local/src tar -zvxf php-7.1.8.tar.gz cd php-7.1.8 export LD_LIBRARY_PATH=/usr/local/libgd/lib ./configure --prefix=/usr/local/php \ --with-config-file-path=/usr/local/php/etc \ --with-mysqli=/usr/local/mysql/bin/mysql_config \ --with-mysql-sock=/tmp/mysql.sock \ --with-pdo-mysql=/usr/local/mysql \ --with-gd=/usr/local/libgd \ --with-png-dir=/usr/local/libpng \ --with-jpeg-dir=/usr/local/jpeg \ --with-freetype-dir=/usr/local/freetype \ --with-xpm-dir=/usr/lib64 \ --with-zlib-dir=/usr/local/zlib \ --with-iconv \ --enable-libxml \ --enable-xml \ --enable-bcmath \ --enable-shmop \ --enable-sysvsem \ --enable-inline-optimization \ --enable-opcache \ --enable-mbregex \ --enable-fpm \ --enable-mbstring \ --enable-ftp \ --enable-gd-native-ttf \ --with-openssl \ --enable-pcntl \ --enable-sockets \ --with-xmlrpc \ --enable-zip \ --enable-soap \ --without-pear \ --with-gettext \ --enable-session \ --with-mcrypt \ --with-curl \ --enable-ctype \ --enable-mysqlnd \ make #編譯 make install #安裝 說明:若是提示libgd版本錯誤,把php編譯參數--with-gd=/usr/local/libgd修改成--with-gd便可。
配置文件nginx
cp php.ini-production /usr/local/php/etc/php.ini #複製php配置文件到安裝目錄 rm -rf /etc/php.ini #刪除系統自帶配置文件 ln -s /usr/local/php/etc/php.ini /etc/php.ini #添加軟連接到 /etc目錄
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf #拷貝模板文件爲php-fpm配置文件 ln -s /usr/local/php/etc/php-fpm.conf /etc/php-fpm.conf #添加軟鏈接到 /etc目錄 vim /usr/local/php/etc/php-fpm.conf #編輯 pid = run/php-fpm.pid #取消前面的分號
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf vim /usr/local/php/etc/php-fpm.d/www.conf #編輯 user = www #設置php-fpm運行帳號爲www group = www #設置php-fpm運行組爲www
設置 php-fpm開機啓動c++
vim /usr/lib/systemd/system/php-fpm.service [Unit] Description=The PHP FastCGI Process Manager After=syslog.target network.target [Service] Type=simple PIDFile=/run/php-fpm.pid ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf ExecReload=/bin/kill -USR2 $MAINPID ExecStop=/bin/kill -SIGINT $MAINPID [Install] WantedBy=multi-user.target
vim /usr/local/php/etc/php.ini #編輯配置文件 找到:disable_functions = 修改成:disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open, proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink, symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space, checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid, posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid, posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times, posix_ttyname,posix_uname #列出PHP能夠禁用的函數,若是某些程序須要用到這個函數,能夠刪除,取消禁用。
找到:;date.timezone = 修改成:date.timezone = PRC #設置時區 找到:expose_php = On 修改成:expose_php = Off #禁止顯示php版本的信息 找到:short_open_tag = Off 修改成:short_open_tag = ON #支持php短標籤 找到opcache.enable=0 修改成opcache.enable=1 #php支持opcode緩存 找到:;opcache.enable_cli=1 #php支持opcode緩存 修改成:opcache.enable_cli=0 在最後一行添加:zend_extension=opcache.so #開啓opcode緩存功能
配置nginx支持phpgit
vim /usr/local/nginx/conf/nginx.conf 修改/usr/local/nginx/conf/nginx.conf 配置文件,需作以下修改 user www www; #首行user去掉註釋,修改Nginx運行組爲www www;必須與/usr/local/php/etc/php-fpm.conf中的user,group配置相同,不然php運行出錯 index index.html index.htm index.php; #添加index.php # 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 $document_root$fastcgi_script_name; include fastcgi_params; } #取消FastCGI server部分location的註釋,注意fastcgi_param行的參數,改成$document_root$fastcgi_script_name,或者使用絕對路徑
systemctl restart nginx systemctl restart php-fpm
測試github
chmod 700 /usr/local/nginx/html/ -R #設置目錄權限 cd /usr/local/nginx/html/ #進入nginx默認網站根目錄 rm -rf /usr/local/nginx/html/* #刪除默認測試頁 vim index.php #新建index.php文件 <?php phpinfo(); ?> chown www.www /usr/local/nginx/html/ -R #設置目錄全部者
cd /usr/local/src #進入軟件包下載目錄 tar zabbix-3.0.1.tar.gz #解壓 cd /usr/local/src/zabbix-3.0.1/database/mysql #進入mysql數據庫建立腳本目錄 ls #列出文件,能夠看到有schema.sql、images.sql、data.sql這三個文件 mysql -u root -p #輸入密碼,進入MySQL控制檯 create database zabbix character set utf8; #建立數據庫zabbix,而且數據庫編碼使用utf8 grant all on zabbix.* to 'zabbix'@'localhost' identified by '123456' with grant option; #容許帳戶zabbix能從本機鏈接到數據庫zabbix flush privileges; #刷新系統受權表 # zabbix進入mysql use zabbix #進入數據庫 source /usr/local/src/zabbix-3.4.1/database/mysql/schema.sql; #導入腳本文件到zabbix數據庫 source /usr/local/src/zabbix-3.4.1/database/mysql/images.sql; #導入腳本文件到zabbix數據庫 source /usr/local/src/zabbix-3.4.1/database/mysql/data.sql; #導入腳本文件到zabbix數據庫 注意:請按照以上順序進行導入,不然會出錯。
cd /usr/lib64/mysql #32位系統爲/usr/lib/mysql,注意系統版本同,文件版本可能不同,這裏是16.0.0 ln -s libmysqlclient.so.16.0.0 libmysqlclient.so #添加軟鏈接 ln -s libmysqlclient_r.so.16.0.0 libmysqlclient_r.so #添加軟鏈接
useradd -s /sbin/nologin zabbix #建立用戶zabbix
yum install net-snmp-devel curl curl-devel mysql-devel
ln -s /usr/local/lib/libiconv.so.2 /usr/lib/libiconv.so.2 #添加軟鏈接 /sbin/ldconfig #使配置當即生效 cd /usr/local/src/zabbix-3.4.1 #進入安裝目錄 ./configure --prefix=/usr/local/zabbix \ --enable-server \ --enable-agent \ --with-mysql \ --enable-ipv6 \ --with-net-snmp \ --with-libcurl \ --with-libxml2 \ make #編譯 make install #安裝
ln -s /usr/local/zabbix/sbin/* /usr/local/sbin/ #添加系統軟鏈接 ln -s /usr/local/zabbix/bin/* /usr/local/bin/ #添加系統軟鏈接
vim /etc/services #編輯,在最後添加如下代碼 # Zabbix zabbix-agent 10050/tcp # Zabbix Agent zabbix-agent 10050/udp # Zabbix Agent zabbix-trapper 10051/tcp # Zabbix Trapper zabbix-trapper 10051/udp # Zabbix Trapper
cd /usr/local/zabbix/etc vim /usr/local/zabbix/etc/zabbix_server.conf DBName=zabbix #數據庫名稱 DBUser=zabbix #數據庫用戶名 DBPassword=123456 #數據庫密碼 ListenIP=localhost #數據庫ip地址 AlertScriptsPath=/usr/local/zabbix/share/zabbix/alertscripts #zabbix運行腳本存放目錄 vim /usr/local/zabbix/etc/zabbix_agentd.conf Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/ UnsafeUserParameters=1 #啓用自定義key
cp /usr/local/src/zabbix-3.4.1/misc/init.d/fedora/core/zabbix_server /etc/rc.d/init.d/zabbix_server #服務端 cp /usr/local/src/zabbix-3.4.1/misc/init.d/fedora/core/zabbix_agentd /etc/rc.d/init.d/zabbix_agentd #客戶端 chkconfig zabbix_server on #添加開機啓動 chkconfig zabbix_agentd on #添加開機啓動
vim /etc/rc.d/init.d/zabbix_server #編輯服務端配置文件 BASEDIR=/usr/local/zabbix/ #zabbix安裝目錄 vim /etc/rc.d/init.d/zabbix_agentd #編輯客戶端配置文件 BASEDIR=/usr/local/zabbix/ #zabbix安裝目錄
cd /usr/local/src/zabbix-3.4.1 cp -r /usr/local/src/zabbix-3.4.1/frontends/php /usr/local/nginx/html/zabbix chown www.www -R /usr/local/nginx/html/zabbix 備註:/usr/local/nginx/html爲Nginx默認站點目錄 www爲Nginx運行帳戶 service zabbix_server start #啓動zabbix服務端 service zabbix_agentd start #啓動zabbix客戶端
一、vim /etc/php.ini #編輯修改web
post_max_size =16M max_execution_time =300 max_input_time =300
二、vim /usr/local/php/etc/php-fpm.conf #編輯修改sql
request_terminate_timeout = 300
一、修改系統配置文件,讓web頁面支持簡體中文顯示 vim /usr/local/nginx/html/zabbix/include/locales.inc.php #編輯修改 'zh_CN' => array('name' => _('Chinese (zh_CN)'), 'display' => false), 修改成 'zh_CN' => array('name' => _('Chinese (zh_CN)'), 'display' => true),
替換監控圖像上系統默認的字體 #默認字體不支持中文,若是不替換,圖像上會顯示亂碼 usr/local/nginx/html/zabbix/fonts 備份默認的字體文件:DejaVusSans.ttf-bak 修改msyh.ttf名稱爲DejaVusSans.ttf