一、配置host,network,iptables
cat /etc/hosts
vim /etc/sysconfig/network-script/ifcfg-eth0
service iptables stop
二、配置yum及安裝依賴包
mkdir /media/yum
mount /dev/cdrom /media/mount
或mount -t iso9660 /dev/cdrom /media/rhel5
cp /etc/yum.repos.d/rhel-source.repo /etc/yum.repos.d/bak.rhel-source.repo.bak
vi /etc/yum.repos.d/rhel-source.repo
rhel-source.repo文件內容以下:
[Server]
name=Server
baseurl=file:///media/rhel5/Server
enabled=1
gpgcheck=0
yum安裝rpm包如下報錯:
warning: rpmts_HdrFromFdno: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY
執行如下命令完成修復:
rpm --import /etc/pki/rpm-gpg/RPM*
安裝依賴包
yum install compat-lib* binutils-2* gcc* glibc-2* glibc-devel-2* ksh libgcc-4* libstdc++-4* libstdc++-d* libaio-0* libaio-d* sysstat-9* make-3*
三、安裝nginx
1.安裝nginx相關依賴包
yum -y install gcc gcc-c++ zlib zlib-devel openssl openssl-devel pcre pcre-devel
2.解壓壓縮包
tar -xvf nginx-1.10.3.tar.gz
3.安裝nginx到目錄/usr/local/nginx
cd nginx-1.10.3
./configure --prefix=/opt/nginx #nginx安裝到此目錄
make #編譯
make&make install #編譯安裝
4.爲後續配合PHP,故需要配置nginx.conf
#在如下目錄新建目錄web_root
cd /opt/nginx
mkdir web_root
#編輯nginx.conf以支持PHP,修改部分見如下紅字。
修改項:
#新建一行:root /opt/nginx/web_root
#修改一行:將之前的scripts修改爲/opt/nginx/web_root
[root@ZABBIX conf]# more nginx.conf
listen 80;
server_name localhost;
############add by guanyy#################
root /opt/nginx/web_root;
##########################################
location / {
root html;
index index.php index.html index.htm;
}
# 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 /opt/nginx/web_root$fastcgi_script_name;
include fastcgi_params;
}
location ~* ^.+\.(ico|gif|jpg|jpeg|png|html|css|htm|bmp|js|svg)$ {
root /opt/nginx/web_root;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one #
#location ~ /\.ht {
# deny all;
#}
}
5.啓動nginx
/opt/nginx/sbin/nginx
6.新建一個測試文件index.php,測試成功後再刪除
cd /usr/local/nginx/web_root/
[root@ZABBIX web_root]# more index.php
<?php
phpinfo();
?>
四、安裝mysql
1、安裝依賴包
yum install cmake gacc* ncurses-devel -y
yum -y install libail perl autoconf
2、修改配置文件
vim /etc/my.cnf
[mysqld]
basedir= /opt/mysql/mysql
datadir=/opt/mysql/mysql_data
socket=/opt/mysql/mysql_data/mysql.sock
log-error=/opt/mysql/error.log
pid-file_=/opt/mysql/mysql.pid
user=root
tmpdir=/tmp
port=3306
3、創建用戶
useradd -g mysql mysql -s /sbin/nologin
chown -R mysql.mysql /opt/mysql
4、設置開啓自啓
cp /opt/mysql/mysql/support-files/mysql.server /etc/init.d/mysql
chmod 755 /etc/init.d/mysql
chkconfig mysql on
5、修改配置環境
echo "/opt/mysql/mysql/lib/">>/etc/ld.so.conf.d/mysql.conf
ldconfig -v | grep mysql
echo "export PATH=$PATH:/opt/mysql/mysql/bin">> /etc/profile.d/mysql.sh
chmod +x /etc/profile.d/mysql.sh
source /etc/profile.d/mysql.sh
6、編譯安裝
./mysqld --defaults-file=/etc/my.cnf --initialize --user=root --pid-file=/opt/mysql/mysql.pid --basedir=/opt/mysql/mysql --datadir=/opt/mysql/mysql_data --tmpdir=/tmp --log-error=/opt/mysql/error.log
make install #編譯安裝
7、開啓數據庫
service mysql start
A temporary password is generated for root@localhost:Eidr>vv1moy:
7.1、更改數據庫賬號密碼及登錄權限
mysql -uroot -p //登錄數據庫
set password for root@localhost = password('gacHZroot@2018');
flush privileges
create database zabbix character set utf8 collate utf8_bin;
grant all privileges on zabbix.* to zabbix@'%' identified by 'zabbix';
flush privileges
7.2將zabbix安裝中的數據寫入數據庫
ls /opt/zabbix-3.0.25/database/mysql
mv zabbix-3.0.25/ zabbix/
mysql -uroot -p zabbix < schema.sql
mysql -uroot -p zabbix < images.sql
mysql -uroot -p zabbix < data.sql
mysql -uroot -p
use zabbix
show table
7.3、初始化報錯
初始化後登錄mysql報錯1:
[root@zabbix mysql]# mysql -uroot -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
解決辦法1:把mysql原有sock鏈接到報錯地址
[root@zabbix mysql]# ps -ef | grep mysql
root 10317 1 0 10:38 pts/5 00:00:00 /bin/sh /opt/mysql/mysql/bin/mysqld_safe --datadir=/opt/mysql/mysql_data --pid-file=/opt/mysql/mysql.pid
root 10508 10317 4 10:38 pts/5 00:00:02 /opt/mysql/mysql/bin/mysqld --basedir=/opt/mysql/mysql --datadir=/opt/mysql/mysql_data --plugin-dir=/opt/mysql/mysql/lib/plugin --user=root --log-error=/opt/mysql/error.log --pid-file=/opt/mysql/mysql.pid --socket=/opt/mysql/mysql_data/mysql.sock --port=3306
root 10564 9024 0 10:39 pts/5 00:00:00 grep mysql
[root@zabbix mysql]# ln -s /opt/mysql/mysql_data/mysql.sock /tmp/mysql.sock
五、安裝zabbix
1、創建用戶
useradd zabbix -s /sbin/nologin
2、安裝rpm依賴包
yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-deve pcre* make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip-devel --skip-broken
yum install mysql-dev gcc net-snmp-devel curl-devel perl-DBI php-gd php-mysql php-bcmath php-mbstring php-xm --skip-broken
yum install java*
3、指定目錄安裝
./configure --prefix=/opt/zabbix --e nable-server --enable-agent --enable-java --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
4、編譯 安裝
make && make install
5、修改配置文件
vim /opt/zabbix/etc/zabbix_server.conf
LogFile=/opt/zabbix/log/zabbix.server.log
DBPassword=zabbix
Timeout=30
Include=/opt/oracle_shell/
AllowRoot=1
User=root
6、賦權
chown -R zabbix.zabbix /opt/zabbix
六、安裝PHP
1、安裝PHP--編譯安裝需刪除rpm包
yum install php*
yum install http*
2、修改配置文件
vim /etc/php.ini
date.timezone = Asia/Chongqing
max_execution_time = 300
post_max_size=32M
max_input_time=300
memory_limit=128M
3、針對使用不同的網頁配置
3.1、使用http
cd /var/www/html/
[root@zabbix html]# mkdir zabbix
[root@zabbix html]# cd zabbix/
[root@zabbix zabbix]# cp -r /opt/zabbix/zabbix-3.0.25/frontends/php/ ./
[root@zabbix zabbix]# cp -r php/ ../../
[root@zabbix sbin]# which httpd
/usr/sbin/httpd
[root@zabbix sbin]# pwd
/usr/sbin
[root@zabbix sbin]# service httpd start
[root@zabbix sbin]# service httpd status
httpd (pid 16056) is running...
[root@zabbix sbin]# ps -ef | grep httpd
3.2、使用nginx
cd /opt/nginx/html/
[root@zabbix html]# mkdir zabbix
[root@zabbix html]# cd zabbix/
[root@zabbix zabbix]# cp -r /opt/zabbix/zabbix-3.0.25/frontends/php/ ./
[root@zabbix zabbix]# cp -r php/ ../../
[root@zabbix sbin]# service php-fpm start
[root@zabbix sbin]# service php-fpm status
httpd (pid 16056) is running...
[root@zabbix sbin]# ps -ef | grep php-fpm
4、編譯安裝php
4.1、安裝依賴包
yum -y install libxml2
yum -y install libxml2-devel
yum -y install openssl
yum -y install openssl-devel
yum -y install curl
yum -y install curl-devel
yum -y install libjpeg
yum -y install libjpeg-devel
yum -y install libpng
yum -y install libpng-devel
yum -y install freetype
yum -y install freetype-devel
yum -y install pcre
yum -y install pcre-devel
yum -y install libxslt
yum -y install libxslt-devel
yum -y install bzip2
yum -y install bzip2-devel
4.2、 指定路徑安裝
./configure --prefix=/opt/php --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip
4.3、編譯安裝
make && make install
4、配置php環境
#複製php配置文件到安裝目錄
cp /opt/php/php-7.1.26/ php.ini-production /opt/php/etc/php.ini
#刪除系統自帶配置文件
rm -rf /etc/php.ini
#添加軟鏈接到 /etc目錄
ln -s /opt/php/etc/php.ini /etc/php.ini
ls -l /etc/php.ini
#複製模板文件爲php-fpm配置
cp /opt/php/etc/php-fpm.conf.default /opt/php/etc/php-fpm.conf
#添加軟件鏈接到 /etc目錄
ln -s /opt/php/etc/php-fpm.conf /etc/php-fpm.conf
#編輯php配置文件php-fpm.conf
vim /opt/php/etc/php-fpm.conf
pid = run/php-fpm.pid //如果這個選項在配置文件存在就取消掉註釋使用,如果不存在可以忽略,請勿手動添加,否則PHP啓動會報錯。
user = apache
group = apache
5、設置php-fpm開機自啓動
#複製php-fpm到啓動目錄
[root@ssticentos65 ~]# cp /opt/php/php-7.1.26/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@ssticentos65 ~]# ls -l /etc/init.d/php-fpm
-rw-r--r--. 1 root root 2354 Jan 6 02:37 /etc/init.d/php-fpm
#賦予php-fpm執行權限
[root@ssticentos65 ~]# chmod 755 /etc/init.d/php-fpm
[root@ssticentos65 ~]# ls -l /etc/init.d/php-fpm
-rwxr-xr-x. 1 root root 2354 Jan 6 02:37 /etc/init.d/php-fpm
#設置php-fpm開機啓動
[root@ssticentos65 ~]# chkconfig php-fpm on
[root@ssticentos65 ~]# chkconfig --list php-fpm
php-fpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off
6、修改PHP.INI配置
#編輯php配置文件php.ini
[root@ssticentos65 ~]# vim /opt/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
找到: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緩存功能 (在文本按Shift+G就能跳到最後一行)
:wq! #保存並退出
7、配置nginx支持php
檢查www用戶和www用戶組是否存在,不存在請手動創建
[root@ssticentos65 ~]# cat /etc/passwd | grep www
apache:x:48:48:Apache:/var/www:/sbin/nologin
www:x:501:3005::/home/www:/bin/bash
[root@ssticentos65 ~]# cat /etc/group | grep www
www:x:3005:
[root@ssticentos65 ~]# vim /opt/nginx/conf/nginx.conf
user www www;
#首行user去掉註釋,修改Nginx運行組爲www www;必須與/opt/php/etc/php-fpm.d/www.conf中的user,group配置相同,否則php運行出錯
location / {
root html;
index index.html index.htm index.php; #添加index.php
}
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,或者使用絕對路徑
:wq! #保存並退出
默認情況下etc/php-fpm.d/下有一個名爲www.conf.defalut的配置用戶的文件,執行下面命令複製一個新文件並且打開:
cp /usr/local/etc/php-fpm.d/www.conf.default /usr/local/etc/php-fpm.d/www.conf
vim /usr/local/etc/php-fpm.d/www.conf
默認user和group的設置爲nobody,將其改爲Apache
#啓動nginx服務
[root@ssticentos65 ~]# /etc/init.d/nginx restart
#啓動php服務
[root@ssticentos65 ~]# /etc/init.d/php-fpm start
網頁訪問192.168.47.53 顯示nginx歡迎主頁
8、測試php配置
#進入nginx默認網站根目錄
[root@ssticentos65 ~]# cd /opt/nginx/html/
[root@ssticentos65 html]# ls
50x.html index.html
#刪除默認測試頁
[root@ssticentos65 html]# rm -rf /opt/nginx/html/*
[root@ssticentos65 html]# pwd
/opt/nginx/html
#新建index.php文件進行測試
[root@ssticentos65 html]# vim index.php
<?php
phpinfo();
?>
:wq! #保存並退出
#設置目錄所有者爲 www
[root@ssticentos65 html]# chown www.www /opt/nginx/html/ -R
#設置目錄權限
[root@ssticentos65 html]# chmod 755 /opt/nginx/html/ -R
打開瀏覽器輸入服務器IP地址http://192.168.47.53,會看到下面的界面就是php安裝成功
七、安裝zabbix
網頁訪問http://192.168.47.53/zabbix/setup.php
初始賬號密碼Admin/zabbix
八、配置zabbix
更改字符
複製字體文件並賦權
[root@zabbix fonts]# cd /opt/nginx/html/zabbix/fonts
chown -R apache.apache msyh.ttf
修改參數文件
[root@zabbix include]# vim /opt/nginx/html/zabbix/include/defines.inc.php
define('ZBX_GRAPH_FONT_NAME', 'msyh'); // font file name
define('DEFAULT_LATEST_ISSUES_CNT', 50);