#!/bin/bashfunction memu(){cat <<EOF1.install zabbix_server2.install zabbix_agentEOF}memuread -p "Do you need to install zabbix_server or zabbix-agent,please input 1 or 2: " NUMif [ -z $NUM ];thenecho "请输入{1|2}"exit 1fi if [ $NUM -eq 1 ];thenecho "start install zabbix_server"system_version=`cat /etc/redhat-release|sed -r 's/.* ([0-9]+)\..*/\1/'`yum_dir=/installzabbix#pack_deposit_dir=/usr/local/srcpack_name=install-zabbbix.tar.gzFILE=`date +%F_%T`_install_zabbix.logtouch /tmp/${FILE}INSTALLLOG=/tmp/${FILE}if [ -e ${yum_dir} ];thenecho "${yum_dir} dir already existed" >> ${INSTALLLOG}echo " please change yum_dir name "exit 1; else mkdir -pv ${yum_dir} &>/dev/nullif [ -e ${yum_dir} ];thenecho "${yum_dir} dir create finish" >> ${INSTALLLOG}fififor i in /etc/passwd /etc/shadow /etc/group /etc/gshadowdo if [ `lsattr ${i} | cut -c 5` = i ];then/usr/bin/chattr -i $i /usr/bin/lsattr $i >> ${INSTALLLOG}elseecho "$i不存在i安全属性" >> ${INSTALLLOG}fidone#解压安装包#tar xvf ${pack_deposit_dir}/${pack_name} -C ${yum_dir}tar xvf ${pack_name} tar xvf c${system_version}packges.tar.gz -C ${yum_dir}#安装createrepo包用以生成repodata yum -y install createrepo yum-utilsif [ $? -eq 0 ];thenecho "createrepo packages already install finish" >> ${INSTALLLOG}elseecho "createrepo packeages install failed" >> ${INSTALLLOG}exit 1fi#生成repo文件在/etc/yum.repos.d/目录下yum-config-manager --add-repo=file://${yum_dir}if [ -e /etc/yum.repos.d${yum_dir}.repo ];thenecho "repo文件已经生成" >> ${INSTALLLOG}elseecho " repo 文件没有生成" >> ${INSTALLLOG}exit 1fi#生成repodatacreaterepo ${yum_dir}if [ -e ${yum_dir}/repodata ];thenecho "repodata 已经生成" >> ${INSTALLLOG}elseecho "repodata 没有生成" >> ${INSTALLLOG}fiyum repolist | grep ${yum_dir}if [ $? -eq 0 ];thenecho "yum源配置完成" >> ${INSTALLLOG}elseecho "yum源配置失败" >> ${INSTALLLOG}exit fiecho "----------------------------------------------" >> ${INSTALLLOG}echo "gpgcheck=0" >> /etc/yum.repos.d/${yum_dir}.repo#安装包if [ ${system_version} -eq 6 ];thenyum -y install httpd php php-mysql php-ldap php-gd php-bcmath php-mbstring php-xml libaio libaio-devel yum -y install zabbix-server zabbix-agent zabbix-java-gateway zabbix-web-mysql zabbix-getfiif [ ${system_version} -eq 7 ];thenyum -y install httpd php php-pecl-mysql php-mysqlnd php-ldap php-gd php-bcmath php-mbstring php-xml libaio libaio-devel yum -y install zabbix-server zabbix-agent zabbix-java-gateway zabbix-web-mysql zabbix-getfi#安装mysqlmysql_version=5.7.24mysql_user=mysqlmysql_install_dir=/app/databasemysql_root_passwd=centosbase_dir=${mysql_install_dir}/${mysql_user}mysql_data_dir=/data/mysqlmysql_logs=$mysql_install_dir/logserror_logs=${mysql_logs}/mysqld.logmysql_pid=${mysql_install_dir}/${mysql_user}/mysqld.pidsocket_file=${base_dir}/mysql.sockyum -y install libaio*id $mysql_user &>/dev/nullif [ $? = 0 ];then  echo " $mysql_user user already existed"  exit 1else  useradd -r $mysql_user -s /sbin/nologin fiif [ -e ${mysql_install_dir} ];thenecho " ${mysql_install_dir} dir already existed "exit 1elsemkdir -p $mysql_data_dir mkdir -p $mysql_logstouch $mysql_logs/mysqld.logfiif [ -e mysql-${mysql_version}-linux-glibc2.12-x86_64.tar ];then tar xvf mysql-${mysql_version}-linux-glibc2.12-x86_64.tar  tar xvf mysql-${mysql_version}-linux-glibc2.12-x86_64.tar.gz -C ${mysql_install_dir}else echo " packages inexistence" exit 1ficd ${mysql_install_dir}mv mysql-5.7.24-linux-glibc2.12-x86_64 ${mysql_user}chown -R ${mysql_user}.${mysql_user} ${mysql_install_dir}chmod -R 755 ${mysql_install_dir}cat > /etc/my.cnf <<EOF[client]port = 3306socket = /tmp/mysql.sock[mysqld]default_password_lifetime=360character_set_server=utf8init_connect='SET NAMES utf8'basedir=${base_dir}datadir=${mysql_data_dir}socket=${socket_file}log-error=${error_logs}pid-file=${mysql_pid}#不区分大小写lower_case_table_names = 1sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTIONmax_connections=5000default-time_zone = '+8:00'EOF${base_dir}/bin/mysqld --initialize --user=$mysql_user --basedir=${base_dir} --datadir=${mysql_data_dir}echo "PATH=${base_dir}/bin:$PATH" > /etc/profile.d/mysql.sh source /etc/profile.d/mysql.shcp ${base_dir}/support-files/mysql.server /etc/init.d/mysqldln -sv ${socket_file} /tmp/mysql.sock chkconfig --add mysqldchkconfig mysqld on service mysqld startsleep 5#cat /var/log/mysqld.log | awk '/root@localhost/{print $NF}'#root_init_passwd=`cat ${mysql_logs}/mysqld.log | awk '/root@localhost/{print $NF}'`root_init_passwd=`cat ${mysql_logs}/mysqld.log |grep 'A temporary password'|awk  '{print $NF}'`#/usr/local/mysql/bin/mysql -uroot -p${root_init_passwd} -e "set password for root@localhost=password('centos');"${base_dir}/bin/mysql -uroot -p${root_init_passwd}  --connect-expired-password -e "set  password=password('${mysql_root_passwd}');"${base_dir}/bin/mysql -uroot -p${mysql_root_passwd} --connect-expired-password  -e "flush privileges;"#创建zabbix用户${base_dir}/bin/mysql -uroot -p${mysql_root_passwd} -e "create database zabbix;grant all on zabbix.* to zabbix@'localhost' identified by 'zabbix';" ${base_dir}/bin/mysql -uroot -p${mysql_root_passwd} -e "flush privileges;"#导入zabbix数据zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | ${base_dir}/bin/mysql -uzabbix -hlocalhost -pzabbix zabbix#修改zabbix_server配置文件if [ ${system_version} -eq 6 ];thensed -i 's/# DBHost=localhost/DBHost=localhost/g' /etc/zabbix/zabbix_server.confsed -i 's/# DBname=zabbix/DBname=zabbix/g' /etc/zabbix/zabbix_server.confsed -i 's/# DBPassword=/DBPassword=zabbix/g' /etc/zabbix/zabbix_server.confsed -i 's/# ListenPort=10051/ListenPort=10051/g' /etc/zabbix/zabbix_server.confsed -i 's/# DBSocket=\/tmp\/mysql.sock/DBSocket=\/tmp\/mysql.sock/g' /etc/zabbix/zabbix_server.confls /etc/zabbix/zabbix_server.conf >> ${INSTALLLOG}egrep -v "^$|^#" /etc/zabbix/zabbix_server.conf >> ${INSTALLLOG}echo "----------------------------------------------" >> ${INSTALLLOG}fiif [ ${system_version} -eq 7 ];thensed -i 's/# DBHost=localhost/DBHost=127.0.0.1/g' /etc/zabbix/zabbix_server.confsed -i 's/# DBname=zabbix/DBname=zabbix/g' /etc/zabbix/zabbix_server.confsed -i 's/# DBPassword=/DBPassword=zabbix/g' /etc/zabbix/zabbix_server.confsed -i 's/# ListenPort=10051/ListenPort=10051/g' /etc/zabbix/zabbix_server.confsed -i 's/# DBSocket=\/tmp\/mysql.sock/DBSocket=\/tmp\/mysql.sock/g' /etc/zabbix/zabbix_server.confls /etc/zabbix/zabbix_server.conf >> ${INSTALLLOG}egrep -v "^$|^#" /etc/zabbix/zabbix_server.conf >> ${INSTALLLOG}echo "----------------------------------------------" >> ${INSTALLLOG}fi#修改zabbix_agent配置文件if [ ${system_version} -eq 6 ];thensed -i 's/Hostname=Zabbix server/#Hostname=Zabbix server/g' /etc/zabbix/zabbix_agentd.confsed -i 's/# HostnameItem=system.hostname/HostnameItem=system.hostname/g' /etc/zabbix/zabbix_agentd.confls /etc/zabbix/zabbix_agentd.conf >> ${INSTALLLOG}egrep -v "^$|^#" /etc/zabbix/zabbix_agentd.conf >> ${INSTALLLOG}echo "----------------------------------------------" >> ${INSTALLLOG}fiif [ ${system_version} -eq 7 ];thensed -i 's/Hostname=Zabbix server/#Hostname=Zabbix server/g' /etc/zabbix/zabbix_agentd.confsed -i 's/# HostnameItem=system.hostname/HostnameItem=system.hostname/g' /etc/zabbix/zabbix_agentd.confls /etc/zabbix/zabbix_agentd.conf >> ${INSTALLLOG}egrep -v "^$|^#" /etc/zabbix/zabbix_agentd.conf >> ${INSTALLLOG}echo "----------------------------------------------" >> ${INSTALLLOG}fi#修改php.iniif [ ${system_version} -eq 6 ];thencp /usr/share/doc/zabbix-web-3.4.15/httpd22-example.conf /etc/httpd/conf.d/zabbix.confsed -i 's/# php_value date.timezone Europe\/Riga/php_value date.timezone Asia\/Shanghai/g' /etc/httpd/conf.d/zabbix.confsed -i 's/mysqli.default_socket =/mysqli.default_socket = \/tmp\/mysql.sock/g' /etc/php.inised -i "/post_max_size/s/8/16/g" /etc/php.inised -i "/max_execution_time/s/30/300/g" /etc/php.inised -i "/max_input_time = 60/s/60/300/g" /etc/php.inised -i 's/;date.timezone =/date.timezone = \"Asia\/Shanghai\"/g' /etc/php.inichown -R apache.apache /etc/zabbix/webfiif [ ${system_version} -eq 7 ];thensed -i 's/mysqli.default_socket =/mysqli.default_socket = \/tmp\/mysql.sock/g' /etc/php.inised -i '/<IfModule mod_php5.c>/c\    <IfModule mod_php7.c>' /etc/httpd/conf.d/zabbix.confsed -i 's/# php_value date.timezone Europe\/Riga/php_value date.timezone Asia\/Shanghai/g' /etc/httpd/conf.d/zabbix.conffi#修改http默认访问路径为zabbix的页面sed -i -r '/^DocumentRoot/c\ DocumentRoot "/usr/share/zabbix"' /etc/httpd/conf/httpd.confif [ ${system_version} -eq 6 ];then#启动httpdservice httpd startchkconfig --add httpdchkconfig httpd on#启动本地zabbix_server和zabbix_agent/etc/init.d/zabbix-server start/etc/init.d/zabbix-agent startchkconfig --add zabbix-serverchkconfig zabbix-server onchkconfig --add zabbix-agent chkconfig zabbix-agent onfiif [ ${system_version} -eq 7 ];thensystemctl start httpdsystemctl enable httpdsystemctl start zabbix-server zabbix-agentsystemctl enable zabbix-server zabbix-agentfifor i in /etc/passwd /etc/shadow /etc/group /etc/gshadowdo if [ `lsattr ${i} | cut -c 5` = i ];then   echo " ${i} 存在i安全属性" >> ${INSTALLLOG}else   chattr +i $i   lsattr $i >> ${INSTALLLOG}fidoneecho "----------------------------------------------" >> ${INSTALLLOG}echo "访问地址为zabbix-server ip地址"  >> ${INSTALLLOG}echo "zabbix web页面默认登录账号为admin 密码为zabbix" >> ${INSTALLLOG}echo "mysql 用户名为 ${mysql_user}" >> ${INSTALLLOG}echo "mysql_root_passwd 更改为 ${mysql_root_passwd}" >> ${INSTALLLOG}echo "mysql_install_dir为 ${mysql_install_dir}" >> ${INSTALLLOG}echo -e "\033[1;34m zabbix-server安装完成,输出结果在/tmp目录下${INSTALLLOG}文件中 \033[0m"fiif [ $NUM -eq 2 ];thenecho "start install zabbix_agent"read -p "please input zabbix_server IP: " zabbixserverIPsystem_version=`cat /etc/redhat-release|sed -r 's/.* ([0-9]+)\..*/\1/'`yum_dir=/installzabbix#pack_deposit_dir=/usr/local/srcpack_name=install-zabbbix.tar.gzFILE=`date +%F_%T`_install_zabbix.logtouch /tmp/${FILE}INSTALLLOG=/tmp/${FILE}if [ -e ${yum_dir} ];thenecho "${yum_dir} dir already existed" >> ${INSTALLLOG}#exit 1; else mkdir -pv ${yum_dir} &>/dev/nullif [ -e ${yum_dir} ];thenecho "${yum_dir} dir create finish" >> ${INSTALLLOG}fififor i in /etc/passwd /etc/shadow /etc/group /etc/gshadowdo if [ `lsattr ${i} | cut -c 5` = i ];then/usr/bin/chattr -i $i /usr/bin/lsattr $i >> ${INSTALLLOG}elseecho "$i不存在i安全属性" >> ${INSTALLLOG}fidone#解压安装包tar xvf ${pack_name} tar xvf c${system_version}packges.tar.gz -C ${yum_dir}#安装createrepo包用以生成repodatacd ${yum_dir} yum -y install createrepo yum-utilsif [ $? -eq 0 ];thenecho "createrepo packages already install finish" >> ${INSTALLLOG}elseecho "createrepo packeages install failed" >> ${INSTALLLOG}fi#生成repo文件在/etc/yum.repos.d/目录下yum-config-manager --add-repo=file://${yum_dir}if [ -e /etc/yum.repos.d${yum_dir}.repo ];thenecho "repo文件已经生成" >> ${INSTALLLOG}elseecho " repo 文件没有生成" >> ${INSTALLLOG}fi#生成repodatacreaterepo ${yum_dir}if [ -e ${yum_dir}/repodata ];thenecho "repodata 已经生成" >> ${INSTALLLOG}elseecho "repodata 没有生成" >> ${INSTALLLOG}fiyum repolist | grep ${yum_dir}if [ $? -eq 0 ];thenecho "yum源配置完成" >> ${INSTALLLOG}elseecho "yum源配置失败" >> ${INSTALLLOG}exit fiecho "----------------------------------------------" >> ${INSTALLLOG}echo "gpgcheck=0" >> /etc/yum.repos.d/${yum_dir}.repo#安装包yum -y install zabbix-agentif [ $? -eq 0 ];thenecho " zabbix-agent install finish " >> ${INSTALLLOG}elseecho "zabbix-agent install faild" >> ${INSTALLLOG}exit 1fiecho "----------------------------------------------" >> ${INSTALLLOG}#配置zabbix-agentd.confif [ ${system_version} -eq 6 ];thensed -i "s/Server=127.0.0.1/Server=$zabbixserverIP/g" /etc/zabbix/zabbix_agentd.confsed -i 's/# ListenPort=10050/ListenPort=10050/g' /etc/zabbix/zabbix_agentd.confsed -i "s/ServerActive=127.0.0.1/ServerActive=$zabbixserverIP/g" /etc/zabbix/zabbix_agentd.confsed -i 's/Hostname=Zabbix server/#Hostname=Zabbix server/g' /etc/zabbix/zabbix_agentd.confsed -i 's/# HostnameItem=system.hostname/HostnameItem=system.hostname/g' /etc/zabbix/zabbix_agentd.confls /etc/zabbix/zabbix_agentd.conf >> ${INSTALLLOG}egrep -v "^$|^#" /etc/zabbix/zabbix_agentd.conf >> ${INSTALLLOG}echo "----------------------------------------------" >> ${INSTALLLOG}fiif [ ${system_version} -eq 7 ];thensed -i "s/Server=127.0.0.1/Server=$zabbixserverIP/g" /etc/zabbix/zabbix_agentd.confsed -i 's/# ListenPort=10050/ListenPort=10050/g' /etc/zabbix/zabbix_agentd.confsed -i "s/ServerActive=127.0.0.1/ServerActive=$zabbixserverIP/g" /etc/zabbix/zabbix_agentd.confsed -i 's/Hostname=Zabbix server/#Hostname=Zabbix server/g' /etc/zabbix/zabbix_agentd.confsed -i 's/# HostnameItem=system.hostname/HostnameItem=system.hostname/g' /etc/zabbix/zabbix_agentd.confls /etc/zabbix/zabbix_agentd.conf >> ${INSTALLLOG}egrep -v "^$|^#" /etc/zabbix/zabbix_agentd.conf >> ${INSTALLLOG}echo "----------------------------------------------" >> ${INSTALLLOG}fi#启动zabbix-agentif [ ${system_version} -eq 6 ];then/etc/init.d/zabbix-agent startchkconfig --add zabbix-agent chkconfig zabbix-agent onfiif [ ${system_version} -eq 7 ];thensystemctl start zabbix-agentsystemctl enable zabbix-agentfifor i in /etc/passwd /etc/shadow /etc/group /etc/gshadowdo if [ `lsattr ${i} | cut -c 5` = i ];then   echo " ${i} 存在i安全属性" >> ${INSTALLLOG}else   chattr +i $i   lsattr $i >> ${INSTALLLOG}fidoneecho -e "\033[1;34m zabbix-agent安装完成,输出结果在/tmp目录下${INSTALLLOG}文件中 \033[0m"fi



©著作权归作者所有:来自51CTO博客作者wx5b0938db0a971的原创作品,如需转载,请注明出处,否则将追究法律责任

更多相关文章

  1. 深度学习实践:从零开始做电影评论文本情感分析
  2. python中四种获取文件后缀名的方法
  3. 如何在Mac上的照片中创建新的相册或文件夹?
  4. rsync断点续传
  5. 如何让Mac电脑在Finder窗口顶部显示文件路径?
  6. 常用的Linux命令片段
  7. Mysql主从复制
  8. Linux运维入门教程06-03 (硬盘分区、格式化及文件系统的管理一)
  9. Java 将XML转为Excel方法介绍

随机推荐

  1. 利用xslt对xml进行缩进格式化处理
  2. 用XsltArgumentList实现xsl的参数调用
  3. 使用 XML 模板 (MSSQL手册)
  4. 多级联动下拉选择框,动态获取下一级
  5. 将一个图片以二进制值的形式存入Xml文件
  6. 新兴XML处理方法VTD-XML介绍
  7. 将图片读入到Dom中,并将其存为xml文件
  8. 利用XMLSerializer将对象串行化到XML
  9. 利用XML实现通用WEB报表打印实际使用中的
  10. 广告控件中xml文件的写法