此脚本是LAMP环境搭建Zabbix监控平台自动化安装脚本,有需要朋友可以参考,脚本内容如下:
系统环境:CentOS 7.9文章源自小柒网-https://www.yangxingzhen.cn/6766.html
软件版本:文章源自小柒网-https://www.yangxingzhen.cn/6766.html
Apache:2.4.29文章源自小柒网-https://www.yangxingzhen.cn/6766.html
Mysql:5.7.29文章源自小柒网-https://www.yangxingzhen.cn/6766.html
PHP:7.3.7文章源自小柒网-https://www.yangxingzhen.cn/6766.html
Zabbix:4.4.3文章源自小柒网-https://www.yangxingzhen.cn/6766.html
[root@localhost ~]# vim auto_install_lamp_zabbix.sh文章源自小柒网-https://www.yangxingzhen.cn/6766.html
#!/bin/bash
#Date:2018-5-20 14:08:55
#Author Blog:
# https://www.yangxingzhen.cn
#Author WeChat:
# 微信公众号:小柒博客
#Author mirrors site:
# https://mirrors.yangxingzhen.com
#About the Author
# BY:YangXingZhen
# Mail:xingzhen.yang@yangxingzhen.com
#Auto Install LAMP Environment And Zabbix
source /etc/rc.d/init.d/functions
#Define APR path variables
APR_URL=https://mirrors.yangxingzhen.com/apr
APR_FILES=apr-1.6.5.tar.gz
APR_FILES_DIR=apr-1.6.5
APR_PREFIX=/usr/local/apr
#Define APR-util path variables
APR_UTIL_URL=https://mirrors.yangxingzhen.com/apr-util
APR_UTIL_FILES=apr-util-1.6.1.tar.gz
APR_UTIL_FILES_DIR=apr-util-1.6.1
APR_UTIL_PREFIX=/usr/local/apr-util
#Define PCRE path variables
PCRE_URL=https://mirrors.yangxingzhen.com/pcre
PCRE_FILES=pcre-8.41.tar.gz
PCRE_FILES_DIR=pcre-8.41
PCRE_PREFIX=/usr/local/pcre
#Define Apache path variables
APACHE_URL=https://mirrors.yangxingzhen.com/apache
APACHE_FILES=httpd-2.4.39.tar.gz
APACHE_FILES_DIR=httpd-2.4.39
APACHE_PREFIX=/usr/local/apache
APACHE_INIT_FILE=/etc/init.d/httpd
#Define Boost path variables
Boost_URL=https://mirrors.yangxingzhen.com/mysql
Boost_File=boost_1_59_0.tar.gz
#Define Mysql path variables
MYSQL_URL=http://mirrors.163.com/mysql/Downloads/MySQL-5.7
MYSQL_FILES=mysql-5.7.29.tar.gz
MYSQL_FILES_DIR=mysql-5.7.29
MYSQL_PREFIX=/usr/local/mysql
MYSQL_DIR=/data/mysql
MYSQL_USER=mysql
#Define ZIP path variables
ZIP_URL=https://nih.at/libzip
ZIP_FILE=libzip-1.2.0.tar.gz
ZIP_FILE_DIR=libzip-1.2.0
#Define PHP path variables
PHP_URL=http://mirrors.sohu.com/php
PHP_FILE=php-7.3.7.tar.gz
PHP_FILE_DIR=php-7.3.7
PHP_PREFIX=/usr/local/php
USER=apache
#Define Zabbix path variables
ZABBIX_URL=http://mirrors.yangxingzhen.com/zabbix
ZABBIX_FILES=zabbix-4.4.3.tar.gz
ZABBIX_FILES_DIR=zabbix-4.4.3
ZABBIX_PREFIX=/usr/local/zabbix
function Install_Apache (){
#Install APR
if [ ! -d ${APR_PREFIX} ];then
yum -y install gcc gcc-c++ wget
cd ${HOME} && wget -c ${APR_URL}/${APR_FILES}
tar zxf ${APR_FILES}
cd ${APR_FILES_DIR}
./configure --prefix=${APR_PREFIX}
if [ $? -eq 0 ];then
make && make install
action "The APR Install Sussess..." /bin/true
else
aciton "The APR Install Failed..." /bin/false
exit 1
fi
else
echo -e "\033[32mThe APR Already Install...\033[0m"
fi
#Install APR-util
if [ ! -d ${APR_UTIL_PREFIX} ];then
yum -y install expat expat-devel
cd ${HOME} && wget -c ${APR_UTIL_URL}/${APR_UTIL_FILES}
tar zxf ${APR_UTIL_FILES}
cd ${APR_UTIL_FILES_DIR}
./configure --prefix=${APR_UTIL_PREFIX} --with-apr=${APR_PREFIX}
if [ $? -eq 0 ];then
make && make install
action "The APR-util Install Sussess..." /bin/true
else
aciton "The APR-util Install Failed..." /bin/false
exit 1
fi
else
echo -e "\033[32mThe APR-util Already Install...\033[0m"
fi
#Install PCRE
if [ ! -d ${PCRE_PREFIX} ];then
cd ${HOME} && wget -c ${PCRE_URL}/${PCRE_FILES}
tar zxf ${PCRE_FILES}
cd ${PCRE_FILES_DIR}
./configure --prefix=${PCRE_PREFIX}
if [ $? -eq 0 ];then
make && make install
action "The PCRE Install Sussess..." /bin/true
else
aciton "The PCRE Install Failed..." /bin/false
exit 1
fi
else
echo -e "\033[32mThe PCRE Already Install...\033[0m"
fi
#Install Apache
if [ ! -d ${APACHE_PREFIX} ];then
yum -y install openssl openssl-devel
cd ${HOME} && wget -c ${APACHE_URL}/${APACHE_FILES}
tar zxf ${APACHE_FILES}
cd ${APACHE_FILES_DIR}
./configure --prefix=${APACHE_PREFIX} \
--with-apr=${APR_PREFIX} \
--with-apr-util=${APR_UTIL_PREFIX} \
--enable-so \
--enable-rewrite \
--enable-ssl \
--with-pcre=${PCRE_PREFIX} \
--with-mpm=worker
if [ $? -eq 0 ];then
make && make install
action "The Apache Install Sussess..." /bin/true
else
aciton "The Apache Install Failed..." /bin/false
exit 1
fi
else
echo -e "\033[32mThe Apache Already Install...\033[0m"
exit 0
fi
}
function Install_Mysql (){
if [ ! -d ${MYSQL_PREFIX} ];then
#Install Package
yum -y install ncurses-devel perl perl-devel cmake wget gcc gcc-c++ bison* autoconf openssl-devel openssl
#Install Boost
cd ${HOME} && wget -c ${Boost_URL}/${Boost_File}
tar zxf ${Boost_File} -C /usr/local/
#Install MYSQL
wget -c ${MYSQL_URL}/${MYSQL_FILES}
tar zxf ${MYSQL_FILES}
cd ${MYSQL_FILES_DIR}
cmake . -DCMAKE_INSTALL_PREFIX=${MYSQL_PREFIX} \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DMYSQL_DATADIR=${MYSQL_DIR} \
-DSYSCONFDIR=/etc \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/usr/local/boost_1_59_0 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_TCP_PORT=3306 \
-DWITH_READLINE=1 \
-DMYSQL_USER=${MYSQL_USER} \
-DWITH_SSL=yes
if [ $? -eq 0 ];then
make && make install
action "The Mysql Install Sussess..." /bin/true
else
action "The Mysql Install Failed..." /bin/false
exit 1
fi
else
echo -e "\033[31mThe Mysql Already Install...\033[0m"
exit 1
fi
}
function Install_PHP() {
#Install Libzip
yum –y install wget gcc gcc-c++
cd ${HOME} && wget -c ${ZIP_URL}/${ZIP_FILE}
tar zxf ${ZIP_FILE}
cd ${ZIP_FILE_DIR}
./configure
if [ $? -eq 0 ];then
make && make install
action "The Libzip Install Sussess..." /bin/true
else
action "The Libzip Install Failed..." /bin/false
exit 1
fi
cat >/etc/ld.so.conf <<EOF
/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64
EOF
ldconfig -v
#Install PHP
if [ ! -d ${PHP_PREFIX} ];then
#Install Package
yum -y install epel-release
yum -y install wget gcc gcc-c++ pcre pcre-devel openssl openssl-devel libxml2 libxml2-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel cmake
cd ${HOME} && wget -c ${PHP_URL}/${PHP_FILE}
tar zxf ${PHP_FILE}
cd ${PHP_FILE_DIR}
./configure --prefix=${PHP_PREFIX} \
--with-config-file-path=/etc \
--with-apxs2=/usr/local/apache/bin/apxs \
--enable-fpm \
--with-fpm-user=${USER} \
--with-fpm-group=${USER} \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-libxml-dir \
--with-xmlrpc \
--with-openssl \
--with-mhash \
--with-pcre-regex \
--with-sqlite3 \
--with-zlib \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--with-cdb \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--with-pcre-dir \
--enable-ftp \
--with-gd \
--with-openssl-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--with-onig \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-zlib-dir \
--with-pdo-sqlite \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-libxml-dir \
--with-xsl \
--enable-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-opcache
if [ $? -eq 0 ];then
\cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
make && make install
action "The PHP Install Sussess..." /bin/true
else
action "The PHP Install Failed..." /bin/false
exit 1
fi
else
echo -e "\033[31mThe PHP already Install...\033[0m"
exit 1
fi
}
function LAMP_Config() {
#Apache config and Integrating PHP
useradd -s /sbin/nologin ${USER} >/dev/null 2>&1
\cp ${APACHE_PREFIX}/bin/apachectl ${APACHE_INIT_FILE}
chmod o+x ${APACHE_INIT_FILE}
sed -i 's/User daemon/User apache/' ${APACHE_PREFIX}/conf/httpd.conf
sed -i 's/Group daemon/Group apache/' ${APACHE_PREFIX}/conf/httpd.conf
sed -i '/AddType *.* .tgz/a\\tAddType application/x-httpd-php .php' ${APACHE_PREFIX}/conf/httpd.conf
sed -i 's/index.html/index.php index.html/' ${APACHE_PREFIX}/conf/httpd.conf
sed -i 's/#ServerName www.example.com:80/ServerName localhost:80/' ${APACHE_PREFIX}/conf/httpd.conf
#Config PHP
\cp php.ini-production /etc/php.ini
\cp ${PHP_PREFIX}/etc/php-fpm.conf.default ${PHP_PREFIX}/etc/php-fpm.conf
\cp ${PHP_PREFIX}/etc/php-fpm.d/www.conf.default ${PHP_PREFIX}/etc/php-fpm.d/www.conf
\cp sapi/fpm/php-fpm.service /usr/lib/systemd/system
cat >/usr/local/php/etc/php-fpm.d/www.conf <<EOF
[www]
listen = 0.0.0.0:9000
listen.mode = 0666
user = ${USER}
group = ${USER}
pm = dynamic
pm.max_children = 128
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 10000
rlimit_files = 1024
slowlog = log/\$pool.log.slow
EOF
#Mysql Config
useradd -s /sbin/nlogin mysql >/dev/null 2>&1
mkdir -p ${MYSQL_DIR}
chown -R ${MYSQL_USER}.${MYSQL_USER} ${MYSQL_DIR}
cat >/etc/my.cnf <<EOF
[mysqld]
#数据存储目录
datadir = ${MYSQL_DIR}
#socket通信文件
socket = /tmp/mysql.sock
#使用mysql用户启动
user = ${MYSQL_USER}
#MYSQL服务运行的端口号
port = 3306
#开启bin-log日志
log-bin = mysql-bin
#MYSQL服务ID号
server-id = 1
#定义error错误文件
log-error = ${MYSQL_DIR}/mysqld.log
#PID文件路径
pid-file = mysqld.pid
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#设置字符集为utf8
character-set-server = utf8
[client]
default-character-set = utf8
port = 3306
socket = /tmp/mysql.sock
[mysql]
default-character-set = utf8
EOF
#Initialization Mysql
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/data/mysql/ --basedir=/usr/local/mysql
ln -sf ${MYSQL_PREFIX}/bin/* /usr/bin
\cp ${MYSQL_PREFIX}/support-files/mysql.server /etc/init.d/mysqld
chmod o+x /etc/init.d/mysqld
#Start Mysql、php-fpm、Apache and Add MySQL、php-fpm、Apache boot self start
${APACHE_INIT_FILE} start
systemctl start php-fpm
/etc/init.d/mysqld start
sed -i '/#!\/bin\/sh/a#description: apache web server' ${APACHE_INIT_FILE}
sed -i '/#!\/bin\/sh/a#chkconfig: - 20 90' ${APACHE_INIT_FILE}
chkconfig --add httpd
chkconfig httpd on
chkconfig --add mysqld
chkconfig mysqld on
systemctl enable php-fpm
}
function Install_Zabbix_Server (){
#Install Zabbix_Server
if [ ! -d ${ZABBIX_PREFIX} ];then
#Install Package
yum -y install net-snmp net-snmp-devel perl-DBI curl curl-devel libevent libevent-devel wget gcc gcc-c++ pcre pcre-devel
cd ${HOME} && wget -c ${ZABBIX_URL}/${ZABBIX_FILES}
tar xf ${ZABBIX_FILES}
cd ${ZABBIX_FILES_DIR}
./configure --prefix=${ZABBIX_PREFIX} --enable-server --enable-agent --with-mysql=/usr/local/mysql/bin/mysql_config --enable-ipv6 --with-net-snmp --with-libcurl
if [ $? -eq 0 ];then
make && make install
echo -e "\033[32mThe Zabbix_Server Install sussess...\033[0m"
else
echo -e "\033[31mThe Zabbix_Server Install fail,Please check...\033[0m"
exit 1
fi
else
echo -e "\033[31mThe Zabbix_Server already Install...\033[0m"
exit 1
fi
#Create Mysql
mysql -e "create database zabbix charset=utf8;"
mysql -e "grant all on zabbix.* to zabbix@'localhost' identified by 'www.yangxingzhen.cn';"
mysql -e "flush privileges"
#Import the SQL file to the Zabbix Database
cd database/mysql
mysql -uzabbix -pwww.yangxingzhen.cn 2>/dev/null zabbix < schema.sql
mysql -uzabbix -pwww.yangxingzhen.cn 2>/dev/null zabbix < images.sql
mysql -uzabbix -pwww.yangxingzhen.cn 2>/dev/null zabbix < data.sql
#Copy File
\cp -a ${HOME}/zabbix-4.4.3/frontends/php/* ${APACHE_PREFIX}/htdocs
ln -sf /${MYSQL_PREFIX}/lib/libmysqlclient.so.20 /usr/lib64
mkdir -p /var/lib/mysql
ln -sf /tmp/mysql.sock /var/lib/mysql
#Backup Configuration File
\cp ${ZABBIX_PREFIX}/etc/zabbix_server.conf ${ZABBIX_PREFIX}/etc/zabbix_server.conf.bak
\cp ${ZABBIX_PREFIX}/etc/zabbix_agentd.conf ${ZABBIX_PREFIX}/etc/zabbix_agentd.conf.bak
ln -sf ${ZABBIX_PREFIX}/sbin/zabbix_* /usr/local/sbin/
#Config Zabbix_Server File
cat >${ZABBIX_PREFIX}/etc/zabbix_server.conf <<EOF
LogFile=/tmp/zabbix_server.log
PidFile=/tmp/zabbix_server.pid
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=www.yangxingzhen.cn
Timeout=30
LogSlowQueries=3000
EOF
#Config Zabbix_Server File
cat >${ZABBIX_PREFIX}/etc/zabbix_agentd.conf <<EOF
LogFile=/tmp/zabbix_agentd.log
Server=localhost
ServerActive=localhost
Hostname=localhost
EnableRemoteCommands=1
UnsafeUserParameters=1
LogFileSize=10
Timeout=30
EOF
#Configuring system services
\cp ${HOME}/zabbix-4.4.3/misc/init.d/tru64/zabbix_* /etc/init.d/
chmod o+x /etc/init.d/zabbix_*
#Create zabbix user
useradd -s /sbin/nologin zabbix >/dev/null 2>&1
#PHP Config
sed -i 's/post_max_size = 8M/post_max_size = 16M/' /etc/php.ini
sed -i 's/max_execution_time = 30/max_execution_time = 300/' /etc/php.ini
sed -i 's/max_input_time = 60/max_input_time = 300/' /etc/php.ini
sed -i 's/;date.timezone =/date.timezone = Asia\/Shanghai/' /etc/php.ini
sed -i 's/;always_populate_raw_post_data = -1/always_populate_raw_post_data = -1/' /etc/php.ini
#Start Zabbix_Server And Zabbix_Agentd or Apache
/etc/init.d/zabbix_server start
/etc/init.d/zabbix_agentd start
${APACHE_INIT_FILE} restart
#Configure power on self start
grep -qw "/etc/init.d/zabbix_server" /etc/rc.d/rc.local
if [ $? -ne 0 ];then
echo "/etc/init.d/zabbix_server start" >>/etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local
fi
grep -qw "/etc/init.d/zabbix_agentd" /etc/rc.d/rc.local
if [ $? -ne 0 ];then
echo "/etc/init.d/zabbix_agentd start" >>/etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local
fi
}
function Main() {
Install_Apache
Install_Mysql
Install_PHP
LAMP_Config
Install_Zabbix_Server
}
Main
脚本执行方式:文章源自小柒网-https://www.yangxingzhen.cn/6766.html
[root@localhost ~]# sh auto_install_lamp_zabbix.sh文章源自小柒网-https://www.yangxingzhen.cn/6766.html 文章源自小柒网-https://www.yangxingzhen.cn/6766.html
若文章图片、下载链接等信息出错,请在评论区留言反馈,博主将第一时间更新!如本文“对您有用”,欢迎随意打赏,谢谢!
继续阅读
Wechat
微信扫一扫,加我!
我的微信
微信号已复制
微信公众号
微信扫一扫,关注我!
我的公众号
公众号已复制
评论