版本
Centos7 php7.2.1+mysql5.6+zabbix4.2.3+nginx1.14
#期望安装php+zabbix+nginx到/data目录下方便管理
mkdir -p /data/installation && cd /data
1.安装PHP
安装相关依赖,并编译安装php 7.2.1(php版本需要大于5+)
- php官网
- https://www.php.net/downloads.php
使用最大CPU核数编译后安装yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel libxslt libicu-devel libxslt-devel gcc-c++ glibc-headers
wget https://www.php.net/distributions/php-7.2.1.tar.gz
tar -xvf php-7.2.1.tar.gz && cd php-7.2.1
useradd -M -s /sbin/nologin php
./configure \
--prefix=/data/php \
--with-mhash \
--with-openssl \
--with-config-file-path=/data/php/etc \
--disable-short-tags \
--enable-fpm \
--with-fpm-user=php \
--with-fpm-group=php \
--enable-xml \
--with-libxml-dir \
--enable-bcmath \
--enable-calendar \
--enable-intl \
--enable-mbstring \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-zip \
--enable-mbregex \
--enable-mysqlnd \
--enable-mysqlnd-compression-support \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-gd \
--enable-ftp \
--with-curl \
--with-xsl \
--with-iconv \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--enable-sysvsem \
--enable-inline-optimization \
--with-xmlrpc \
--with-gettext
开机自启动make -j `nproc ` && make install
上传php.ini到/data/php/etc/mv /data/php/etc/php-fpm.conf.default /data/php/etc/php-fpm.conf
mv /data/php/etc/php-fpm.d/www.conf.default /data/php/etc/php-fpm.d/www.conf
cp /data/installation/php-7.2.1/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod 766 /etc/init.d/php-fpm
systemctl daemon-reload
/sbin/chkconfig php-fpm on
service php-fpm restart
2.安装MYSQLwget https://2070n1o927.iok.la/source/Centos7_installation/php/php.ini
- https://www.php.net/downloads.php
下载mysql-5.6.16.tar.gz至/data,并安装相关依赖以及解压
- mysql官网
- https://dev.mysql.com/get/Downloads/
编译配置yum -y install gcc gcc-c++ ncurses ncurses-devel bison cmake make sysstat
useradd -M -s /sbin/nologin mysql
cd /data && wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.16.tar.gz
tar -xvf mysql-5.6.16.tar.gz && cd mysql-5.6.16
使用最大CPU核数编译后安装cmake \
-DCMAKE_INSTALL_PREFIX=/data/mysql \
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \
-DSYSCONFDIR=/etc \
-DSYSTEMD_PID_DIR=/data/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/data/mysql/data \
-DWITH_SYSTEMD=1
修改编译安装完成后的文件夹权限make -j `nproc ` && make install
初始化数据库chown -R mysql:mysql /data/mysql/
mysql配置文件 ```bash cat > /etc/my.cnf << EOF [mysqld] datadir=/data/mysql/data socket=/data/mysql/mysql.sock user=mysql/data/mysql/bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/data/mysql \
--datadir=/data/mysql/data
若取消注释,表示允许本地无密码登陆。
skip-grant-tables
表示允许任何IP都可以访问mysql服务
bind-address = 0.0.0.0最大连接数
max_connections=3000
- https://dev.mysql.com/get/Downloads/
Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid [mysql] socket=/data/mysql/mysql.sock EOF
开机自启动
```bash
cp /data/mysql/support-files/mysql.server /etc/init.d/mysqld
/data/mysql/scripts/mysql_install_db --user=mysql --basedir=/data/mysql --datadir=/data/mysql/data
/data/mysql/bin/mysqld_safe --user=mysql &
systemctl daemon-reload
systemctl enable mysqld
/sbin/chkconfig mysqld on
systemctl restart mysqld
netstat -anpt | grep 3306
安装mysql客户端
yum install mysql mysql-server
停止防火墙(按自己需求)
systemctl stop firewalld
systemctl disable firewalld
systemctl stop iptables
systemctl disable iptables
3.安装ZABBIX
下载zabbix-4.2.3.tar.gz至/data,并安装相关依赖以及解压
- zabbix官网
- https://www.zabbix.com/download_sources
编译配置cd /data yum install expect net-snmp gcc mysql-devel libxml2-devel net-snmp-devel libevent-devel curl-devel -y wget https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/4.2.3/zabbix-4.2.3.tar.gz/download && mv download zabbix-4.2.3.tar.gz tar -xvf zabbix-4.2.3.tar.gz && cd zabbix-4.2.3 useradd -M -s /sbin/nologin zabbix
使用最大CPU核数编译后安装./configure --prefix=/data/zabbix \ --with-mysql=/data/mysql/bin/mysql_config \ --with-net-snmp \ --with-openssl \ --with-libcurl \ --with-libxml2 \ --with-libpcre \ --with-iconv \ --enable-server \ --enable-agent \ --enable-proxy \ --enable-ipv6
配置zabbix_server自启动(有兴趣深入的,可以研究一下自启动文件,以及为什么做软连接)make -j `nproc ` && make install
ln -s /data/zabbix/sbin/zabbix_server /usr/local/sbin/zabbix_server ln -s /data/zabbix/bin/zabbix_get /usr/local/sbin/zabbix_get mv /data/zabbix/share/zabbix /data/zabbix/share/zabbix_bak cp -r /data/zabbix-4.2.3/frontends/php /data/zabbix/share/zabbix cp /data/zabbix-4.2.3/misc/init.d/fedora/core/zabbix_server /etc/init.d/zabbix_server mv /data/zabbix-4.2.3* /data/installation/ chmod 766 /etc/init.d/zabbix_server systemctl daemon-reload systemctl enable zabbix_server /sbin/chkconfig zabbix_server on sed -i 's/# DBPassword=/DBPassword=zabbix/g' /data/zabbix/etc/zabbix_server.conf sed -i 's/# DBSocket=/DBSocket=\/data\/mysql\/mysql.sock/g' /data/zabbix/etc/zabbix_server.conf service zabbix_server restart
- https://www.zabbix.com/download_sources
修改zabbix-agent配置文件中zabbix-server的 IP地址,以及本机主机名。
sed -i 's/Server=127.0.0.1/Server=172.16.169.191/g' /data/zabbix/etc/zabbix_agentd.conf
sed -i 's/ServerActive=127.0.0.1/ServerActive=172.16.169.191/g' /data/zabbix/etc/zabbix_agentd.conf
sed -i 's/Hostname=Zabbix server/Hostname=tenant-saas-s/g' /data/zabbix/etc/zabbix_agentd.conf
配置zabbix_agent自启动(有兴趣稍微研究一下自启动文件,以及为什么做软连接)
ln -s /data/zabbix/sbin/zabbix_agentd /usr/local/sbin/zabbix_agentd
cp /data//installation/zabbix-4.2.3/misc/init.d/fedora/core/zabbix_agentd /etc/init.d/zabbix_agentd
chmod 766 /etc/init.d/zabbix_agentd
systemctl daemon-reload
/sbin/chkconfig zabbix_agentd on
systemctl enable zabbix_agentd
service zabbix_agentd restart
编译安装的字体路径需要修改否则显示吅吅吅吅
wget https://2070n1o927.iok.la/source/Windows/simkai.ttf -O /data/zabbix/share/zabbix/assets/fonts/simkai.ttf
sed -i.ori 's/DejaVuSans/simkai/g' /data/zabbix/share/zabbix/include/defines.inc.php
mysql数据库中建立zabbix的库以及zabbix用户
mysql << EOF
create database zabbix character set utf8 collate utf8_bin;
grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
EOF
mysql -u zabbix -pzabbix --database zabbix < /data/zabbix-4.2.3/database/mysql/schema.sql
mysql -u zabbix -pzabbix --database zabbix < /data/zabbix-4.2.3/database/mysql/images.sql
mysql -u zabbix -pzabbix --database zabbix < /data/zabbix-4.2.3/database/mysql/data.sql
4.安装nginx
下载nginx1.1.14.tar.gz至/data,并安装相关依赖以及解压
- nginx官网
- http://nginx.org/en/download.html
cd /data yum -y install gcc gcc-c++ autoconf automake make unzip net-tools sysstat yum -y install pcre-devel openssl openssl-devel tar -xvf /data/nginx-1.14.0.tar.gz && cd /data/nginx-1.14.0 ./configure --prefix=/data/nginx --user=root --group=root --with-threads --with-http_realip_module --with-http_ssl_module --with-stream --with-stream_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_slice_module make -j `nproc ` && make install mkdir -p /data/nginx/conf/{conf.d,certs} mv /data/nginx-1.14.0* /data/installation && cd /data echo 'PATH=$PATH:/data/nginx/sbin' >> /etc/profile source /etc/profile
配置nginx
- http://nginx.org/en/download.html
vim /data/nginx/conf/nginx.conf
# Nginx Main Configure File.
# NGINX启动用户
user root;
# CPU核数
worker_processes 8;
events {
worker_connections 65535;
}
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;
#配置文件路径
include conf.d/*.conf;
}
配置nginx 虚拟主机zabbix
vim /data/nginx/conf/conf.d/zabbix.conf
#修改 server_name
###
server {
listen 80;
server_name 192.168.2.177;
access_log logs/zabbix_acc.log;
error_log logs/zabbix_err.log;
# 其他常规配置项自行补充
root /data/zabbix/share;
index index.htm index.html index.php;
location /zabbix {
try_files $uri $uri/ /index.php?$args;
}
location ~ .*\.(php)?$ {
expires -1s;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
配置nginx自启动
cat > /usr/lib/systemd/system/nginx.service << EOF
[Unit]
Description=nginx project
After=nginx.service
[Service]
Type=forking
User=root
Group=root
PIDFile=/data/nginx/logs/nginx.pid
ExecStart=/data/nginx/sbin/nginx
ExecReload=/data/nginx/sbin/nginx -s reload
#也可以通过环境变量启动
ExecStop=/data/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable nginx.service
systemctl start nginx
访问zabbix
http://ip