iptables -F 情况防火墙规则,
setenforce 0 关闭增强安全性功能
[root@localhost ~]# wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
[root@localhost ~]# vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
[root@localhost ~]# yum list
[root@localhost ~]# yum install nginx -y
[root@localhost ~]# systemctl start nginx
[root@localhost ~]# systemctl enable nginx
[root@localhost ~]# yum install mariadb-server mariadb -y
[root@localhost ~]# systemctl start mariadb
[root@localhost ~]# systemctl enable mariadb.service
[root@localhost ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): '//初次运行直接回车'
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y '//y。设置密码'
New password: '//输入密码'
Re-enter new password: '//重复输入一次'
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y '//是否删除匿名用户,建议y删除'
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y '//是否禁止root远程登录,建议y禁止'
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] n '//是否删除test数据库,根据实际情况'
... skipping.
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y '//是否重新加载权限表,建议y'
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
[root@localhost ~]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
[root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
[root@localhost ~]# yum install php72w php72w-devel php72w-fpm php72w-gd php72w-mbstring php72w-mysql -y
php -v //查看版本
修改php-fpm的配置文件,将apache改为nginx
[root@localhost ~]# vim /etc/php-fpm.d/www.conf
更改nginx的默认配置文件,配置location,在index中添加index.php
[root@localhost ~]# vim /etc/nginx/conf.d/default.conf
配置php请求被传送到后端的php-fpm模块,默认情况下php配置块是被注释的,将注释取消
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
[root@localhost ~]# vim /etc/php.ini
359 expose_php = Off //隐藏php版本
202 short_open_tag = On //支持php标签
//以下为zabbix配置要求
368 max_execution_time = 300 //执行时间
378 max_input_time = 300 //接收数据等待时间
389 memory_limit = 128M //每个脚本占用内存
656 post_max_size = 16M //POST数据大小
799 upload_max_filesize = 2M //下载文件大小
800 always_populate_raw_post_data = -1 //手动添加,可以用$HTTP_RAW_POST_DATA接收post raw data
878 date.timezone = Asia/Shanghai //时区
[root@localhost ~]# systemctl start php-fpm.service
[root@localhost ~]# systemctl enable php-fpm.service
[root@localhost ~]# systemctl restart nginx
[root@localhost ~]# vim /usr/share/nginx/html/info.php
使用浏览器访问http://192.168.49.11/info.php
##测试连接数据库
[root@localhost ~]# vim /usr/share/nginx/html/info.php
在数据库创建zabbix数据库、zabbix用户
[root@localhost ~]# mysql -uroot -p
create database zabbix character set utf8 collate utf8_bin;
grant all privileges on *.* to 'zabbix'@'%' identified by 'abc123';
flush privileges;
解决创建的账户本地无法登陆的问题
[root@localhost ~]# mysql -uzabbix -p
Enter password:
ERROR 1045 (28000): Access denied for user 'zabbix'@'localhost' (using password: YES)
#原因是有空用户名称占用导致本地无法登陆
MariaDB [(none)]> select user,host from mysql.user;
+--------+---------------+
| user | host |
+--------+---------------+
| zabbix | % |
| root | 127.0.0.1 |
| | 192.168.49.11 |
| root | 192.168.49.11 |
| root | ::1 |
| | localhost |
| root | localhost |
+--------+---------------+
7 rows in set (0.00 sec)
MariaDB [(none)]> drop user ''@'localhost';
MariaDB [(none)]> drop user ''@'192.168.49.11';
[root@localhost ~]# rpm -i https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
[root@localhost ~]# yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent -y
#更改zabbix_server的配置文件
[root@localhost ~]# vim /etc/zabbix/zabbix_server.conf
38 LogFile=/var/log/zabbix/zabbix_server.log
49 LogFileSize=0
72 PidFile=/var/run/zabbix/zabbix_server.pid
82 SocketDir=/var/run/zabbix //注释去掉
91 DBHost=localhost
100 DBName=zabbix
116 DBUser=zabbix
124 DBPassword=abc123 //修改添加数据库密码
356 SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
473 Timeout=4
516 AlertScriptsPath=/usr/lib/zabbix/alertscripts
527 ExternalScripts=/usr/lib/zabbix/externalscripts
563 LogSlowQueries=3000
#
[root@localhost ~]# vim /usr/share/zabbix/include/defines.inc.php
%s /graphfont/kaiti/g
#从微软系统下复制相应的字体文件到/usr/share/zabbix/fonts
[root@localhost ~]# cd /usr/share/zabbix
[root@localhost zabbix]# mkdir fonts
[root@localhost zabbix]# cd fonts/
#上传后查看
[root@localhost fonts]# ls
STKAITI.TTF
[root@localhost fonts]# cp -r /usr/share/zabbix/ /usr/share/nginx/html/
[root@localhost fonts]# chown -R zabbix:zabbix /etc/zabbix/
[root@localhost fonts]# chown -R zabbix:zabbix /usr/share/nginx/
[root@localhost fonts]# chown -R zabbix:zabbix /usr/lib/zabbix/
[root@localhost fonts]# chmod 755 /etc/zabbix/web/
[root@localhost fonts]# chmod 777 /var/lib/php/session/
将相应的文件上传到zabbix数据库
[root@localhost fonts]# zcat /usr/share/doc/zabbix-server-mysql-4.0.20/create.sql.gz | mysql -uzabbix -p zabbix
#开启服务
[root@localhost fonts]# systemctl start zabbix-server.service
[root@localhost fonts]# systemctl enable zabbix-server.service
[root@localhost fonts]# systemctl start zabbix-agent.service
[root@localhost fonts]# systemctl enable zabbix-agent.service
[root@localhost fonts]# systemctl restart php-fpm.service
[root@localhost fonts]# systemctl restart nginx
http://192.168.49.11/zabbix 用户名Admin,密码zabbix
#安装时,会提示缺少zabbix.conf.php文件报错,按照提示下载,并上传到/etc/zabbix/web/
#更改权限
[root@localhost web]# chown zabbix.zabbix zabbix.conf.php
[root@localhost ~]# rpm -i https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm
[root@localhost ~]# yum install zabbix-agent -y
[root@client ~]# vim /etc/zabbix/zabbix_agentd.conf
Server=192.168.49.11 '//98行指向监控服务器地址'
ServerActive=192.168.49.11 '//139行指向监控服务器地址'
Hostname=Zabbix-test '//150行修改名称'
[root@client ~]# systemctl start zabbix-agent.service
[root@client ~]# systemctl enable zabbix-agent.service
[root@localhost ~]# netstat -ntap | grep zabbix
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 41511/zabbix_agentd
tcp6 0 0 :::10050 :::* LISTEN 41511/zabbix_agentd