12.25 更新:
今天遇到一个问题, 邮件发不出去,连接不到邮件服务器。
网上查了下发现是 端口问题
https://blog.csdn.net/qq_42859864/article/details/84862264
虽然 服务器不是阿里云,,但是 是华为云,一个德行,正在想办法,后续 继续更新
报错:
could not connect: Connection timed out
"/root/dead.letter" 11/296
. . . message not sent.
################################################################
脚本可以看下,,但是建议 提高zabbix版本,,防止sql注入
复制以下脚本 执行即可
注意事项:
服务器版本: Ubuntu 14.04.1 LTS
zabbix版本: zabbix-release_3.0
服务器初始环境:已安装 mysql-server ;sudo 不需要输入ubuntu密码
需变化地方:1.mysql密码需改成自己的密码 2.邮箱相关需改成自己的邮箱3.需自行修改电脑的解析
即: 所有mysql -uroot -p 后面接的密码需改为自己的 ;
如下的 邮件系统需改为自己的邮箱
echo "set from=xxx@mjoygames.com" | sudo tee -a /etc/nail.rc ;
echo "set smtp=smtp.ym.163.com" | sudo tee -a /etc/nail.rc ;
echo "set smtp-auth-user=xxx@mjoygames.com" | sudo tee -a /etc/nail.rc ;
echo "set smtp-auth-password=123456" | sudo tee -a /etc/nail.rc ;
echo "set smtp-auth=login" | sudo tee -a /etc/nail.rc ;
#!/bin/bash
: << !
服务器版本: Ubuntu 14.04.1 LTS
zabbix版本: zabbix-release_3.0
脚本内容: 一键部署zabbix服务端
作者: 繁华
服务器初始环境:已安装 mysql-server ;sudo 不需要输入ubuntu密码
需变化地方:1.mysql密码需改成自己的密码 2.邮箱相关需改成自己的邮箱3.需自行修改电脑的解析
即: 所有mysql -uroot -p 后面接的密码需改为自己的 ;
如下的 邮件系统需改为自己的邮箱
echo "set from=xxx@mjoygames.com" | sudo tee -a /etc/nail.rc ;
echo "set smtp=smtp.ym.163.com" | sudo tee -a /etc/nail.rc ;
echo "set smtp-auth-user=xxx@mjoygames.com" | sudo tee -a /etc/nail.rc ;
echo "set smtp-auth-password=123456" | sudo tee -a /etc/nail.rc ;
echo "set smtp-auth=login" | sudo tee -a /etc/nail.rc ;
!
# 安装 zabbix
sudo wget http://repo.zabbix.com/zabbix/3.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_3.0-1+trusty_all.deb
sudo dpkg -i zabbix-release_3.0-1+trusty_all.deb ;
sudo apt-get update ;
sleep 5;
echo -e "下载的包为:\n`dpkg -l | grep zabbix` "
echo -e "这是一道华丽的分割线\n ########################"
sudo apt-get install -y -qq zabbix-server-mysql ;
sudo apt-get install -y -qq php5-mysql ;
sudo apt-get install -y -qq zabbix-frontend-php ;
sudo apt-get install -y -qq php5-fpm ;
sudo apt-get install -y -qq php5-memcache ;
sudo apt-get install -y -qq nginx ;
#php5-fpm php5-curl php5-gd php5-mysql php5-redis php5-cli redis-server memcached php5-memcache
#创建 zabbix database以及导入库
mysql -uroot -p123456 -e "create database zabbix;" ;
mysql -uroot -p123456 -e "grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';" ;
mysql -uroot -p123456 -e " flush privileges;" ;
sudo sed -i '/bind-address/s/127.0.0.1/0.0.0.0/g' /etc/mysql/my.cnf
sudo service mysql restart
sudo zcat /usr/share/doc/zabbix-server-mysql/create.sql.gz | mysql -uroot -p123456 zabbix
echo -e "mysql zabbix database 里有`mysql -uroot -p123456 zabbix -e "show tables ;"|wc -l` 张表" ;
# 配置 zabbix服务端 php5-fpm 以及nginx
#zabbix配置文件
sudo sed -i "s/# DBHost=localhost/DBHost=localhost/g" /etc/zabbix/zabbix_server.conf
sudo sed -i "s/# DBPassword=/DBPassword=zabbix/g" /etc/zabbix/zabbix_server.conf
#php5
sudo sed -i "/post_max_size/s/8/16/g" /etc/php5/fpm/php.ini ;
sudo sed -i "/max_execution_time/s/30/300/g" /etc/php5/fpm/php.ini ;
sudo sed -i "/max_input_time = 60/s/60/300/g" /etc/php5/fpm/php.ini ;
sudo sed -i 's/;date.timezone =/date.timezone = \"Asia\/Shanghai\"/g' /etc/php5/fpm/php.ini ;
#nginx
#文件 /etc/nginx/conf.d/zabbix.local.com.conf
: << !
server {
listen 80;
server_name zabbix.local.com;
root /usr/share/zabbix;
location / {
index index.php index.html;
try_files $uri $uri/ $uri/index.php /index.php?$args;
}
location ~* \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
# limit_conn zone 20;
}
access_log /var/log/nginx/access_sanguotools.log;
}
!
a='try_files $uri $uri/ $uri/index.php /index.php?$args;';
b='fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;';
sudo touch /etc/nginx/conf.d/zabbix.local.com.conf ;
sudo chown ubuntu.ubuntu /etc/nginx/conf.d/zabbix.local.com.conf ;
sudo touch /var/log/nginx/access_zabbix.log;
cat >> /etc/nginx/conf.d/zabbix.local.com.conf << EOF
server {
listen 80;
server_name zabbix.local.com;
root /usr/share/zabbix;
location / {
index index.php index.html;
$a
}
location ~* \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
$b
include fastcgi_params;
# limit_conn zone 20;
}
access_log /var/log/nginx/access_zabbix.log;
}
EOF
sudo chown root.root /etc/nginx/conf.d/zabbix.local.com.conf ;
#重启服务
sudo update-rc.d -f apache2 remove
sudo service apache2 stop
sudo /etc/init.d/zabbix-server restart
sudo service php5-fpm restart
sudo service nginx restart
: << !
搭建已经完成了,给电脑解析一下 地址就可以配置 zabbix网页了
下面写一些 出现的问题和 报警机制
!
#下载中文包 和解决中文乱码问题
sudo apt-get install -y -qq language-pack-zh-hant ;
sudo apt-get install -y -qq language-pack-zh-hans ;
sudo dpkg-reconfigure locales ;
echo -e "当前中文状态:`grep zh_CN /usr/share/zabbix/include/locales.inc.php | awk -F" " '{print $9}' | awk -F"]" '{print $1}'`" ;
sudo apt-get install -y language-pack-kde-zh-hans ;
sudo service php5-fpm restart ;
sudo service nginx restart ;
#报警机制
#搭建邮件系统(自己的某某邮箱)
sudo apt-get install -y -qq sendmail ;
sudo apt-get install -y -qq heirloom-mailx ;
sudo apt-get install -y -qq zabbix-get ;
#配置代发邮件服务器
#sudo echo "set from=xxx@mjoygames.com" >>/etc/nail.rc ;
#sudo echo "set smtp=smtp.ym.163.com" >>/etc/nail.rc ;
#sudo echo "set smtp-auth-user=xxx@mjoygames.com" >>/etc/nail.rc ;
#sudo echo "set smtp-auth-password=123456" >>/etc/nail.rc ;
#sudo echo "set smtp-auth=login" >>/etc/nail.rc ;
echo "set from=xxx@mjoygames.com" | sudo tee -a /etc/nail.rc ;
echo "set smtp=smtp.ym.163.com" | sudo tee -a /etc/nail.rc ;
echo "set smtp-auth-user=xxx@mjoygames.com" | sudo tee -a /etc/nail.rc ;
echo "set smtp-auth-password=123456" | sudo tee -a /etc/nail.rc ;
echo "set smtp-auth=login" | sudo tee -a /etc/nail.rc ;
#修改 zabbix 默认脚本存放位置
sudo sed -i '/AlertScriptsPath=\//s/usr\/lib/etc/g' /etc/zabbix/zabbix_server.conf ;
echo -e "修改脚本位置为`grep -i "alertscriptsPath=/" /etc/zabbix/zabbix_server.conf | awk -F"=" '{print $2}'` " ;
#创建 自动邮件脚本
: << !
sendmail.sh
#!/bin/bash
export LANG=en_US.UTF-8
mailTmp=/etc/zabbix/alertscripts/mailTMP
echo "$3" >$mailTmp
to=$1
subject=$2
sudo dos2unix -k $mailTmp
mail -s "$subject" "$to" < "$mailTmp"
!
# 安装脚本里的dos2unix (防止邮件正文变成附件问题)
sudo apt-get install -y -qq dos2unix ;
#修改zabbix 用户权限
sudo sed -i '/zabbix/s/false/bash/g' /etc/passwd ;
echo "zabbix ALL=(ALL:ALL) NOPASSWD: ALL" | sudo tee -a /etc/sudoers ;
#生成脚本文件
sudo mkdir -p /etc/zabbix/alertscripts/ ;
sudo touch /etc/zabbix/alertscripts/sendmail.sh ;
echo '#!/bin/bash' |sudo tee -a /etc/zabbix/alertscripts/sendmail.sh
echo 'export LANG=en_US.UTF-8' |sudo tee -a /etc/zabbix/alertscripts/sendmail.sh
echo 'mailTmp=/etc/zabbix/alertscripts/mailTMP'|sudo tee -a /etc/zabbix/alertscripts/sendmail.sh
echo 'echo "$3" >$mailTmp' |sudo tee -a /etc/zabbix/alertscripts/sendmail.sh
echo 'to=$1' |sudo tee -a /etc/zabbix/alertscripts/sendmail.sh
echo 'subject=$2' |sudo tee -a /etc/zabbix/alertscripts/sendmail.sh
echo 'sudo dos2unix -k $mailTmp' |sudo tee -a /etc/zabbix/alertscripts/sendmail.sh
echo 'mail -s "$subject" "$to" < "$mailTmp"' |sudo tee -a /etc/zabbix/alertscripts/sendmail.sh
sudo chown -R zabbix.zabbix /etc/zabbix/alertscripts
: << !
网页内容需自行配置了
谢谢
!