毕设相关环境配置,系统安装
ansible安装
4.1 ansible安装
1,安装EPEL源:sudo yum install epel-release
2,安装ansible :sudo yum install ansible
3,检验ansible是否成功安装:ansible --version
zabbix安装
设置selinux为disabled: vim /etc/selinux/config
查看selinux状态: getenforce
关闭防火墙,并取消开机自启:systemctl stop firewalld;systemctl disable firewalld
重启虚拟机:reboot
使用wget安装rpm包: wget https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm --no-check-certificate
安装: rpm -ivh zabbix-release-4.0-2.el8.noarch.rpm
编辑zabbix.repo文件修改下载的zabbix相关资源的地址: vim /etc/yum.repos.d/zabbix.repo
将其中的repo.zabbix.com修改为mirrors.tuna.tsinghua.edu.cn/zabbix;并将gpgcheck属性修改为0
安装zabbix-server-mysql,zabbix-web-mysql: yum install zabbix-server-mysql zabbix-web-mysql -y
安装mariadb: yum install mariadb-server.x86_64
启动,设置开机自启: systemctl stop mariadb;systemctl disable mariadb
数据库安全初始化: mysql_secure_installation
登录MySQL数据库,并创建数据库: create database zabbix character set utf8 collate utf8_bin;
创建zabbix用户,并为指定远程主机设置访问权限: grant all on zabbix.* to zabbix@'%' identified by '411624';
导入数据库表结构: zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -palong@123 zabbix
编辑zabbix-server.conf文件: vim /etc/zabbix/zabbix_server.conf
修改其中的DB相关配置为本机配置
启动,设置开机自启:systemctl stop mariadb zabbix-server;systemctl disable zabbix-server
安装httpd服务: yum install httpd
设置zabbix.conf文件中的时区
启动,设置开机自启: systemctl stop mariadb httpd;systemctl disable httpd
使用ansible playbook安装zabbix agent
yaml文件编写
- hosts: zabbix_server
become: true
tasks:
- name: Install Resource Zabbix
get_url:
url: https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm
dest: /root/zabbix-release-4.0-2.el7.noarch.rpm
validate_certs: no
- name: RPM Zabbix-release
yum:
name: /root/zabbix-release-4.0-2.el7.noarch.rpm
state: present
- name: Update Zabbix-agent Source
replace:
path: /etc/yum.repos.d/zabbix.repo
regexp: 'http://repo.zabbix.com/'
replace: 'http://mirrors.tuna.tsinghua.edu.cn/zabbix/'
- name: Update gpgcheck
lineinfile:
path: /etc/yum.repos.d/zabbix.repo
regexp: '^gpgcheck='
line: 'gpgcheck=0'
- name: stop firewalld
service:
name: firewalld
state: stopped
enabled: no
- name: Install Zabbix Agent
yum:
name: zabbix-agent
state: present
- name: Modify Zabbix Agent Configuration
lineinfile:
path: /etc/zabbix/zabbix_agentd.conf
regexp: '^Server='
line: 'Server=192.168.1.103'
notify: restart zabbix-agent
handlers:
- name: restart zabbix-agent
service:
name: zabbix-agent
state: restarted
grafana安装
# grafana安装
wget https://dl.grafana.com/oss/release/grafana-6.4.3-1.x86_64.rpm
yum install grafana-6.4.3-1.x86_64.rpm
systemctl start grafana-server
systemctl enable grafana-server
#使用命令为grafana安装zabbix插件
grafana-cli plugins install alexanderzobnin-zabbix-app
service grafana restart