#!/bin/bash # # # ################################################################# SCREEN=`stty -F /dev/console size` &> /dev/null # WHOLE_SPACE=${SCREEN#* } # SPACE1=$[WHOLE_SPACE-14] # RED="\033[31m" # GREEN="\033[32m" # YELLOW="\033[33m" # BLUE="\033[34m" # PURPLE="\033[35m" # COLOURLESS="\033[0m" # #FUNCTIONS # ################################################################# success() { # STRINGS=$1 # SPACE2=$[$SPACE1-${#STRINGS}] # echo -n $STRINGS # for num in `seq $SPACE2`; do # echo -n " " # done # echo -e "[ ${GREEN}OK${COLOURLESS} ]" # } # failure() { # STRINGS=$1 # SPACE2=$[$SPACE1-${#STRINGS}] # echo -n $STRINGS # for num in `seq $SPACE2`; do # echo -n " " # done # echo -e "[ ${RED}FAILURE${COLOURLESS} ]" # } # warning() { # STRINGS=$1 # SPACE2=$[$SPACE1-${#STRINGS}] # echo -n $STRINGS # for num in `seq $SPACE2`; do # echo -n " " # done # echo -e "[ ${YELLOW}WARNING${COLOURLESS} ]" # } # ################################################################# # ######################## ######ENVIORNMENT####### ######################## # export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin VERS=`cat /etc/centos-release | sed "s/.*release \([0-9]\).*/\1/"` install_environment() { ##NETWORK.---------------------------------------------------------- if ping -c1 -W1 www.baidu.com &> /dev/null; then success "NETWORK RUNNING." else failure "NETWORK STOP." exit 1 fi ##REPOS.------------------------------------------------------------- rpm -q ntp wget epel-release | \ grep -oP '(?<=package )\S+' | \ xargs -r yum install -y ##TIME.------------------------------------------------------------ ntpdate ntp1.aliyun.com &> /dev/null && \ success "TIME sync finish." || \ warning "TIME sync failure." ##SELINUX.---------------------------------------------------------- command -v getenforce &>/dev/null && \ sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config && \ [ $(getenforce) = "Enforcing" ] && \ setenforce 0 success "SELINUX config finish." ##SOURCE-PATH.------------------------------------------------------ SOFTDIR="/usr/local/src/installer" [[ -d $SOFTDIR ]] || \ mkdir $SOFTDIR/{nginx,mysql,php,apache,zabbix} -p } ##BASIC-SOFTS.------------------------------------------------------ yum_install() { rpm -q $* | \ grep -oP '(?<=package )\S+' | \ xargs -r yum install -y } ######################## ########APACHE########## ######################## install_httpd() { clock -s yum groupinstall "Development Tools" -y yum_install make gcc gcc-c++ pcre-devel zlib-devel openssl-devel expat-devel [[ -d $SOFTDIR/apache ]] && cd $SOFTDIR/apache || exit 33 # # # # # # # # # # apr_ver=`curl -sL https://soft.vpser.net/web/apache/ | grep -oE 'apr-[0-9]+.[0-9]+.[0-9]+.tar.[[:alnum:]]+' | sort -u | tail -1` apr_dir=${apr_ver%.tar*} [[ -f $apr_ver ]] || wget -T 300 --tries=300 https://soft.vpser.net/web/apache/$apr_ver [ $? -eq 0 ] || exit 44 [[ -d $apr_dir ]] && rm -rf $apr_dir [[ -d $apr_dir ]] || tar xf $apr_ver cd $apr_dir ./configure --prefix=/usr/local/apr && make -j4 && make install if [ $? -eq 0 ]; then cd .. success "INSTALL apr FINISH." else failure "INSTALL apr FAILURE." exit 28 fi # # # # # # # # # # apr_util_ver=`curl -sL https://soft.vpser.net/web/apache/ | grep -oE 'apr-util-[0-9]+.[0-9]+.[0-9]+.tar.[[:alnum:]]+' | sort -u | tail -1` apr_util_dir=${apr_util_ver%.tar*} [[ -f $apr_util_ver ]] || wget -T 300 --tries=300 https://soft.vpser.net/web/apache/$apr_util_ver [ $? -eq 0 ] || exit 45 [[ -d $apr_util_dir ]] && rm -rf $apr_util_dir [[ -d $apr_util_dir ]] || tar xf $apr_util_ver cd $apr_util_dir ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && make -j4 && make install if [[ $? -eq 0 ]]; then cd .. success "INSTALL apr-util FINISH." else failure "INSTALL apr-util FAILURE." exit 29 fi # # # # # # # # # # httpd_ver=`curl -sL https://soft.vpser.net/web/apache/ | grep -oE 'httpd-[0-9]+.[0-9]+.[0-9]+.tar.[[:alnum:]]+' | sort -u | tail -1` httpd_dir=${httpd_ver%.tar*} [[ -f $httpd_ver ]] || wget -T 300 --tries=300 https://soft.vpser.net/web/apache/$httpd_ver [ $? -eq 0 ] || exit 46 [[ -d $httpd_dir ]] && rm -rf $httpd_dir [[ -d $httpd_dir ]] || tar xf $httpd_ver cd $httpd_dir ./configure --prefix=/usr/local/apache \ --sysconfdir=/etc/httpd \ --with-apr=/usr/local/apr \ --with-apr-util=/usr/local/apr-util \ --with-mpm=prefork \ --with-zlib \ --with-pcre \ --enable-so \ --enable-rewrite \ --enable-ssl \ --enable-cgi \ --enable-cgid \ --enable-modules=most \ --enable-mods-shared=all \ --enable-expires \ --enable-deflate && make -j4 && make install if [ $? -eq 0 ]; then cd .. success "HTTPD INSTALL FINISH." else failure "HTTPD INSTALL FAILURE." fi # # # # # # # # # [[ -d /var/www/html ]] || mkdir /var/www/html -p sed -i "s/^Listen 80/Listen 88/" /etc/httpd/httpd.conf sed -i "s/^#ServerName .*/ServerName localhost:88/" /etc/httpd/httpd.conf sed -i 's@^DocumentRoot .*@DocumentRoot "/var/www/html/"@' /etc/httpd/httpd.conf echo "export PATH=$PATH:/usr/local/apache/bin" > /etc/profile.d/httpd.sh sleep 3 source /etc/profile.d/httpd.sh sleep 2 source /etc/profile.d/httpd.sh sleep 2 apachectl start apachectl restart if ss -tanl | grep 88 &> /dev/null; then success "APACHE START SUCCESS." else failure "APACHE START FAILURE." fi [[ -f /etc/man.config ]] && echo "MANPATH /usr/local/apache/man" >> /etc/man.config [[ -f /usr/local/apache/htdocs/index.html ]] && rm -f /usr/local/apache/htdocs/index.html } ######################## ########NGINX########### ######################## install_nginx() { ##1. TOOLS # yum_install gcc gcc-c++ git wget gd-devel make automake [[ -d $SOFTDIR/nginx ]] && cd $SOFTDIR/nginx || exit 88 ##1.1. PCRE pcre_ver="pcre-8.45.tar.gz" pcre_dir=${pcre_ver%.tar*} [[ -f $pcre_ver ]] || wget -T 300 --tries=300 --no-check-certificate https://9133w.cn/sources/$pcre_ver [[ -d $pcre_dir ]] && rm -rf $pcre_dir [[ -d $pcre_dir ]] || tar xf $pcre_ver if [ $? -eq 0 ]; then success "DOWNLOAD PCRE." else failure "Error: download pcre failure." exit 3 fi ##1.2. ZLIB [[ -f zlib-1.2.11.tgz ]] || wget -T 300 --tries=300 https://9133w.cn/sources/zlib-1.2.11.tar.gz -O zlib-1.2.11.tgz [[ -d zlib-1.2.11 ]] && rm -rf zlib-1.2.11 [[ -d zlib-1.2.11 ]] || tar xf zlib-1.2.11.tgz if [ $? -eq 0 ]; then success "DOWNLOAD ZLIB." else failure "Error: download zlib failure." exit 4 fi ##1.3. OPENSSL #https://www.openssl.org/source/openssl-1.1.1g.tar.gz openssl_ver=openssl-1.1.1g.tar.gz openssl_dir=${openssl_ver%.tar*} [[ -f $openssl_ver ]] || wget --no-check-certificate -T 300 --tries=300 https://www.openssl.org/source/$openssl_ver [[ -d $openssl_dirl ]] && rm -rf $openssl_dirl [[ -d $openssl_dirl ]] || tar xf $openssl_ver if [ $? -eq 0 ]; then success "DOWNLOAD OPENSSL." else failure "Error: download openssl failure." exit 5 fi ##1.4. NGINX-HTTP-CONCAT [[ -d nginx-http-concat ]] || wget https://9133w.cn/sources/nginx-http-concat.tgz if [ $? -ne 0 ]; then failure "Error: download nginx-http-concat failure." exit 6 else success "DOWNLOAD NGINX-HTTP-CONCAT." && tar xf nginx-http-concat.tgz fi ##1.5. headers-more-nginx-module: [[ -d headers-more-nginx-module ]] && rm -rf headers-more-nginx-module [[ ! -d headers-more-nginx-module ]] && \ wget https://9133w.cn/sources/headers-more-nginx-module.tgz && \ tar xf headers-more-nginx-module.tgz if [[ -d headers-more-nginx-module ]] then success "DOWNLOAD headers-more-nginx-module." else failure "Error: download headers-more-nginx-module failure." exit 10 fi ##1.6. ngx_cache_purge: [[ -d ngx_cache_purge ]] && rm -rf ngx_cache_purge [[ ! -d ngx_cache_purge ]] && \ wget https://9133w.cn/sources/ngx_cache_purge.tgz && \ tar xf ngx_cache_purge.tgz if [[ -d ngx_cache_purge ]] then success "DOWNLOAD ngx_cache_purge." else failure "Error: download ngx_cache_purge failure." exit 9 fi ##2. NGINX [[ -d $SOFTDIR/nginx ]] && cd $SOFTDIR/nginx || exit 77 export LUAJIT_LIB=/usr/local/lib export LUAJIT_INC=/usr/local/include/luajit-2.0 id -g www &> /dev/null || groupadd www id -u www &> /dev/null || useradd -g www -s /sbin/nologin www nginx_ver=`curl -sL http://nginx.org/download/|grep -oE 'nginx-([0-9]+.){3}tar.[[:alnum:]]+' | sort | uniq | sort -t. -nrk1.7,1.7 -nrk 2,2 -nrk 3,3 | head -1` nginx_dir=${nginx_ver%.tar*} [[ -f $nginx_ver ]] || wget -T 300 --tries=300 http://nginx.org/download/$nginx_ver if [ $? -eq 0 ]; then [[ -d $nginx_dir ]] && rm -rf $nginx_dir [[ -d $nginx_dir ]] || tar xf $nginx_ver [ $? -eq 0 ] && success "DOWNLOAD NGINX." else failure "Error: download nginx failure." exit 13 fi cd $nginx_dir sed -ri 's@(ngx_http_server_string\[\] = )"Server: nginx"@\1"Server: WEB"@' src/http/ngx_http_header_filter_module.c sed -ri 's@(ngx_http_server_full_string\[\] = )"Server: " NGINX_VER@\1"Server: WEB "@' src/http/ngx_http_header_filter_module.c ./configure --prefix=/usr/local/nginx \ --user=www \ --group=www \ --with-pcre=../$pcre_dir \ --with-zlib=../zlib-1.2.11 \ --with-http_stub_status_module \ --with-http_auth_request_module \ --with-http_ssl_module \ --with-http_realip_module \ --with-http_addition_module \ --with-pcre-jit \ --with-http_v2_module \ --with-http_sub_module \ --without-mail_smtp_module \ --without-mail_imap_module \ --with-http_image_filter_module \ --without-mail_pop3_module \ --with-stream \ --with-ipv6 \ --with-openssl=../$openssl_dir \ --with-openssl-opt='-O3 -fPIC' \ --with-http_gzip_static_module \ --add-module=../nginx-http-concat \ --add-module=../ngx_cache_purge \ --lock-path=/var/lock/nginx.lock #--add-module=../headers-more-nginx-module \ if [ $? -eq 0 ]; then make -j4 && make -j4 install if [ $? -eq 0 ]; then cd .. success "MAKE NGINX." else failure "Error: Make failure,check dependings." exit 14 fi else failure "Error: Configure failure,check it." exit 15 fi sleep 2 cpu_num=`lscpu | awk '/^CPU\(s\):/{print $2}'` case $cpu_num in 1) work_cpu="auto" ;; 2) work_cpu="01 10" ;; 4) work_cpu="0001 0010 0100 1000" ;; 6) work_cpu="000001 000010 000100 001000 010000 100000" ;; 8) work_cpu="00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000" ;; *) work_cpu="auto" ;; esac cd /usr/local/nginx/conf && \ mv ./nginx.conf ./nginx.conf.bak && \ echo > ./nginx.conf && sleep 1 && \ mkdir ./conf.d && \ cat > ./nginx.conf << EOF user root; worker_processes $cpu_num; worker_cpu_affinity $work_cpu; worker_rlimit_nofile 100000; events { worker_connections 10240; use epoll; multi_accept on; } http { include mime.types; default_type application/octet-stream; server_tokens off; sendfile on; # tcp_nopush on; tcp_nodelay on; client_max_body_size 20m; keepalive_timeout 65; gzip on; gzip_min_length 1k; gzip_buffers 4 64k; gzip_http_version 1.1; gzip_comp_level 4; gzip_types text/plain text/css text/xml application/javascript; gzip_vary on; gzip_disable msie6; proxy_connect_timeout 65; proxy_read_timeout 180; proxy_send_timeout 180; proxy_buffering on; proxy_buffers 4 128k; proxy_buffer_size 32k; proxy_busy_buffers_size 256k; proxy_max_temp_file_size 256k; charset utf-8,gbk; proxy_cache_path /usr/local/nginx/cache levels=1:2 keys_zone=hot_cache:128m inactive=3d max_size=2g; server { listen 80; server_name -; return 501; # 跨域通用配置样例: # location / { # add_header 'Access-Control-Allow-Origin' * always; # add_header 'Access-Control-Allow-Credentials' 'true' always; # add_header 'Access-Control-Allow-Methods' * always; # add_header 'Access-Control-Allow-Headers' * always; # add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range'; # if (\$request_method = 'OPTIONS') # add_header 'Access-Control-Max-Age' 1728000; # add_header 'Content-Type' 'text/plain; charset=utf-8'; # add_header 'Content-Length' 0; # return 204; # } # 代理缓存 # proxy_cache hot_cache; # proxy_cache_valid 200 206 304 301 302 1d; # proxy_cache_valid any 30m; # proxy_cache_key \$host\$uri\$is_args\$args; # proxy_cache_min_uses 3; # proxy_cache_lock on; # proxy_cache_lock_timeout 3s; # proxy_no_cache \$cookie_nocache \$arg_nocache \$arg_comment; # add_header Cache-status \$upstream_cache_status; # } # 防盗链 # location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css){ # valid_referers www.xxxx.com.cn; # if (\$invalid_referer) { # return 403; # } # } } include conf.d/*.conf; } EOF [ $(ulimit -n) -lt 60000 ] && \ ulimit -HSn 100001 && \ echo -e "*\tsoft\tnofile\t100000\n*\thard\tnofile\t100001" >> /etc/security/limits.conf grep -q 'pam_limits.so' /etc/pam.d/login || echo -e "session\trequired\tpam_limits.so" >> /etc/pam.d/login cd $SOFTDIR /usr/local/nginx/sbin/nginx ss -tanl | grep 80 &> /dev/null && success "NGINX RUNNING." || failure "NGINX NOT RUNNING." } ######################## ########MYSQL########### ######################## # install_mysql () { yum_install make automake gcc gcc-c++ ncurses-devel autoconf perl perl-devel openssl-devel ##0. USER id -g mysql &> /dev/null || groupadd mysql id -u mysql &> /dev/null || useradd -g mysql -s /sbin/nologin mysql if id mysql &> /dev/null; then success "USER:mysql exist." else failure "USER:mysql not exist,please create it." exit 15 fi my_data="${2:-/data/mysql}" ##1. DATABASE. [[ -d $my_data ]] || mkdir $my_data -p if [ $? -eq 0 ]; then chown -R mysql.mysql $my_data success "DATABASE CREATE." sleep 2 else failure "DATABASE CREATE." exit 15 fi ##2. MYSQL-DIR [[ -d $SOFTDIR/mysql ]] || mkdir $SOFTDIR/mysql -p if [ $? -eq 0 ]; then cd $SOFTDIR/mysql success "MYSQL DIR create finish." sleep 2 else failure "MYSQL DIR create failure." exit 16 fi ##3. TOOLS # ###3.1. BOOST http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz if [ $Versn1 == "5.7" ]; then boost_ver=`curl -sL http://175.6.32.4:88/soft/lib/boost/|grep -oE 'boost(_[0-9]+){3}.tar.gz'|sort -u | tail -1` [[ -f $boost_ver ]] || wget -T 300 --tries=300 http://175.6.32.4:88/soft/lib/boost/$boost_ver if [ $? -eq 0 ]; then [[ -d /usr/local/boost ]] || mkdir -p /usr/local/boost cp $boost_ver /usr/local/boost [ $? -eq 0 ] && success "DOWNLOAD BOOST." || failure "BOOST MOVE FAILURE." else failure "DOWNLOAD BOOST FAILURE." exit 17 fi fi ###3.2. CMAKE cmake_ver_1=`curl -sL https://cmake.org/files/ | grep -oE 'v[0-9]+.[0-9]+'|sort -u | sort -t. -nrk1.2,1.2 -nrk 2,2 | head -1` cmake_ver_2=`curl -sL https://cmake.org/files/$cmake_ver_1/ | grep -oE 'cmake-[0-9]+.[0-9]+.[0-9]+(-[[:alnum:]]+){0,1}.tar.gz' | sort -u | tail -1` cmake_dir=${cmake_ver_2%.tar*} [[ -e $cmake_ver_2 ]] || wget -T 300 --tries=300 --no-check-certificate https://cmake.org/files/$cmake_ver_1/$cmake_ver_2 if [ $? -eq 0 ]; then [[ -d $cmake_dir ]] && rm -rf $cmake_dir [[ -d $cmake_dir ]] || tar xf $cmake_ver_2 cd $cmake_dir ./configure && make -j4 && make -j4 install if [ $? -eq 0 ]; then cd .. success "CMAKE DOWNLOAD AND INSTALL FINISH." else failure "CMAKE INSTALL FAILURE." exit 18 fi else failure "CMAKE DOWNLOAD FAILURE." exit 19 fi ##4. MYSQL if [[ $Versn1 == "5.6" ]]; then mysql_ver=`curl -sL http://mirrors.163.com/mysql/Downloads/MySQL-5.6/ | grep -oE 'mysql-5.6.[0-9]+.tar.gz' | sort -u | tail -1` mysql_dir=${mysql_ver%.tar*} [[ -f $mysql_ver ]] || wget -T 300 --tries=300 http://mirrors.163.com/mysql/Downloads/MySQL-5.6/$mysql_ver if [ $? -eq 0 ]; then [[ -d $mysql_dir ]] && rm -rf $mysql_dir [[ -d $mysql_dir ]] || tar xf $mysql_ver [ $? -eq 0 ] && success "DOWNLOAD $mysql_dir" cd $mysql_dir cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=$my_data \ -DSYSCONFDIR=/etc \ -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \ -DMYSQL_USER=mysql \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_FEDERATED_STORAGE_ENGINE=1 \ -DWITH_READLINE=1 \ -DWITH_SSL=bundled \ -DWITH_ZLIB=bundled \ -DWITH_LIBWRAP=0 \ -DEXTRA_CHARSETS=all \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DENABLED_LOCAL_INFILE=ON \ -DENABLE_DOWNLOADS=1 if [ $? -eq 0 ]; then sleep 2 success "MYSQL CONFIGURE FINISH." make -j4 && make -j4 install if [ $? -eq 0 ]; then sleep 2 success "MYSQL MAKE FINISH." else failure "MYSQL MAKE FAILURE." make clean rm -f CMakeCache.txt [[ -f /etc/my.cnf ]] && rm -f /etc/my.cnf exit 20 fi else failure "MYSQL CONFIGURE FAILURE." exit 21 fi else failure "DOWNLOAD MYSQL-5.6.41" exit 22 fi cd /usr/local/mysql chown -R .mysql ./* scripts/mysql_install_db --user=mysql --datadir=$my_data if [ $? -eq 0 ]; then success "INITIALIZE MYSQL FINISH." else failure "INITIALIZE MYSQL FAILURE." fi sleep 2 [ -f support-files/my-default.cnf ] && /bin/cp support-files/my-default.cnf /etc/my.cnf [ -f /etc/my.cnf ] && sed -i "/^\[mysqld\]/a #extra config\n server_id = 110\n log-bin = master-bin\n log-bin-index = master-bin.index\n long_query_time = 3\n slow_query_log = 1\n slow_query_log_file = $my_data/slow-query.log\n event_scheduler = 1\n lower_case_table_names = 1\n innodb_buffer_pool_size = 5368709120\n max_allowed_packet = 256M\n wait_timeout = 3600\n max_connect_errors = 10000\n open_files_limit = 100000\n max_connections = 2000\n tmp_table_size = 256M\n character-set-server = utf8\n collation-server=utf8_general_ci\n table_definition_cache = 2048\n table_open_cache = 1024" /etc/my.cnf cp support-files/mysql.server /etc/rc.d/init.d/mysqld chmod +x /etc/rc.d/init.d/mysqld chkconfig --add mysqld service mysqld start cd $SOFTDIR ss -tanl | grep 3306 &> /dev/null && success "MYSQL INSTALL AND CONFIG FINISH" || failure "MYSQL INSTALL AND CONFIG FAILURE." echo 'PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile source /etc/profile sleep 2 ln -s /usr/local/mysql/lib /usr/lib/mysql ln -s /usr/local/mysql/include /usr/include/mysql [[ -d /var/lib/mysql ]] || mkdir /var/lib/mysql -p ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock sleep 2 elif [ $Versn1 == "5.7" ]; then mysql_ver=`curl -sL http://mirrors.163.com/mysql/Downloads/MySQL-5.7/ | grep -oE 'mysql-5.7.[0-9]+.tar.gz' | sort -u | tail -1` mysql_dir=${mysql_ver%.tar*} [[ -f $mysql_ver ]] || wget -T 300 --tries=300 http://mirrors.163.com/mysql/Downloads/MySQL-5.7/$mysql_ver if [ $? -eq 0 ]; then [[ -d $mysql_dir ]] && rm -rf $mysql_dir [[ -d $mysql_dir ]] || tar xf $mysql_ver [ $? -eq 0 ] && success "DOWNLOAD $msyql_dir" cd $mysql_dir cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=$my_data \ -DSYSCONFDIR=/etc \ -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \ -DMYSQL_USER=mysql \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_FEDERATED_STORAGE_ENGINE=1 \ -DWITH_READLINE=1 \ -DWITH_SSL=system \ -DWITH_ZLIB=bundled \ -DWITH_LIBWRAP=0 \ -DEXTRA_CHARSETS=all \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DENABLED_LOCAL_INFILE=ON \ -DENABLE_DOWNLOADS=1 \ -DDOWNLOAD_BOOST=1 \ -DWITH_BOOST=/usr/local/boost if [ $? -eq 0 ]; then sleep 2 success "MYSQL CONFIGURE FINISH." make -j4 && make -j4 install if [ $? -eq 0 ]; then sleep 2 success "MYSQL MAKE FINISH." else failure "MYSQL MAKE FAILURE." make clean rm -f CMakeCache.txt [[ -f /etc/my.cnf ]] && rm -f /etc/my.cnf exit 23 fi else failure "MYSQL CONFIGURE FAILURE." exit 24 fi else failure "DOWNLOAD MYSQL-5.6.41" exit 25 fi cd /usr/local/mysql chown -R .mysql ./* ./bin/mysqld --user=mysql --initialize-insecure --basedir=/usr/local/mysql --datadir=$my_data if [ $? -eq 0 ]; then success "INITIALIZE MYSQL FINISH." else failure "INITIALIZE MYSQL FAILURE." fi sleep 2 [ -f support-files/my-default.cnf ] && cp support-files/my-default.cnf /etc/my.cnf [ -f /etc/my.cnf ] && sed -i "/^\[mysqld\]/a #extra config\n long_query_time = 3\n slow_query_log = 1\n slow_query_log_file = $my_data/slowquery.log\n server_id = 110\n log-bin = master-bin\n event_scheduler = 1\n lower_case_table_names = 1\n innodb_buffer_pool_size = 5368709120\n max_allowed_packet = 256M\n wait_timeout = 3600\n max_connect_errors = 10000\n open_files_limit = 100000\n max_connections = 2000\n tmp_table_size = 256M\n character-set-server = utf8\n collation-server=utf8_general_ci\n table_definition_cache = 2048\n table_open_cache = 1024" /etc/my.cnf cp support-files/mysql.server /etc/rc.d/init.d/mysqld chmod +x /etc/rc.d/init.d/mysqld chkconfig --add mysqld service mysqld start cd $SOFTDIR ss -tanl | grep 3306 &> /dev/null && success "MYSQL INSTALL AND CONFIG FINISH" || failure "MYSQL INSTALL AND CONFIG FAILURE." echo 'PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile source /etc/profile sleep 2 ln -s /usr/local/mysql/lib /usr/lib/mysql ln -s /usr/local/mysql/include /usr/include/mysql [[ -d /var/lib/mysql ]] || mkdir /var/lib/mysql -p ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock sleep 2 else warning "YOUR INPUT IS WRONG." exit 24 fi } ######################## #########PHP############ ######################## # install_php() { yum_install make automake gcc gcc-c++ bison bison-devel zlib-devel libmcrypt libmcrypt-devel mcrypt mhash-devel openssl-devel libxml2 libxml2-devel bzip2-devel libjpeg-devel libcurl-devel gd-devel libxslt libxslt-devel readline-devel libedit-devel libpng-devel freetype-devel gmp gmp-devel pcre-devel php-ldap [[ -d $SOFTDIR/php ]] || mkdir $SOFTDIR/php -p cd $SOFTDIR/php id -g www &> /dev/null || groupadd www id -u www &> /dev/null || useradd -g www -s /sbin/nologin www echo "/usr/local/lib" > /etc/ld.so.conf.d/local.conf && ldconfig &> /dev/null php_ver=`curl -sL https://www.php.net/releases/ | grep -oE 'php-${versn2}.[0-9]+.tar.gz' | sort -t. -nrk 3,3 | head -1` php_dir=${php_ver%.tar*} wget -T 60 -O $php_ver http://am1.php.net/distributions/$php_ver if [ $? -eq 0 ]; then [[ -d $php_dir ]] && rm -rf $php_dir [[ -d $php_dir ]] || tar xf $php_ver [ $? -eq 0 ] && success "DOWNLOAD $php_dir FINISH." else failure "DOWNLOAD $php_dir FAILURE." exit 28 fi cd $php_dir ./configure \ --prefix=/usr/local/php \ --with-config-file-path=/etc \ --enable-fpm \ --with-fpm-user=www \ --with-fpm-group=www \ --enable-inline-optimization \ --disable-debug \ --disable-rpath \ --enable-shared \ --enable-soap \ --with-libxml-dir \ --with-xmlrpc \ --with-openssl \ --with-mcrypt \ --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 \ --enable-gd-native-ttf \ --enable-gd-jis-conv \ --with-gettext \ --with-gmp \ --with-mhash \ --enable-json \ --enable-mbstring \ --enable-mbregex \ --enable-mbregex-backtrack \ --with-libmbfl \ --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 success "PHP CONFIGURE FINISH." sleep 2 make -j4 && make -j4 install if [ $? -eq 0 ]; then success "PHP MAKE FINISH." sleep 2 else failure "PHP MAKE FAILURE." exit 30 fi else failure "PHP CONFIGURE FAILURE." exit 31 fi [[ -f /etc/php.ini ]] && cp /etc/php.ini /etc/php.ini.bak cp php.ini-production /etc/php.ini sed -i 's/^;date.timezone =/date.timezone = Asia\/Shanghai/' /etc/php.ini cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf if [[ $Versn2 =~ "7." ]]; then cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf fi cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm chmod +x /etc/rc.d/init.d/php-fpm service php-fpm start if [ $? -eq 0 ]; then success "PHP RUNNING." chkconfig --add php-fpm chkconfig php-fpm on echo "export PATH=$PATH:/usr/local/php/bin" > /etc/profile.d/php.sh source /etc/profile.d/php.sh cd else failure "PHP NOT RUN." fi } ##################################################################################### # #Integrated NGINX and PHP integrate_np() { SIGNAL=`ss -tanl | awk '{print $4}' | grep -E "80|9000" | wc -l` if [[ $SIGNAL -ge 2 ]]; then sed -i 's/^#user.*/user www www;/' /usr/local/nginx/conf/nginx.conf sed -i 's/\(^[[:space:]]*index[[:space:]]*\)\(.*\)/\1index.php \2/' /usr/local/nginx/conf/nginx.conf nl -b a /usr/local/nginx/conf/nginx.conf | grep "FastCGI" | awk '{print $1}' | xargs -I {} sed -i '{}a location ~ \.php$ { \ root html; \ fastcgi_pass 127.0.0.1:9000; \ fastcgi_index index.php; \ fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; \ include fastcgi_params; \ }' /usr/local/nginx/conf/nginx.conf sed -i 's/^\(.*\)/#\1/g' /usr/local/nginx/conf/fastcgi_params cat >> /usr/local/nginx/conf/fastcgi_params << EOF fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx; fastcgi_param QUERY_STRING \$query_string; fastcgi_param REQUEST_METHOD \$request_method; fastcgi_param CONTENT_TYPE \$content_type; fastcgi_param CONTENT_LENGTH \$content_length; fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name; fastcgi_param SCRIPT_NAME \$fastcgi_script_name; fastcgi_param REQUEST_URI \$request_uri; fastcgi_param DOCUMENT_URI \$document_uri; fastcgi_param DOCUMENT_ROOT \$document_root; fastcgi_param SERVER_PROTOCOL \$server_protocol; fastcgi_param REMOTE_ADDR \$remote_addr; fastcgi_param REMOTE_PORT \$remote_port; fastcgi_param SERVER_ADDR \$server_addr; fastcgi_param SERVER_PORT \$server_port; fastcgi_param SERVER_NAME \$server_name; EOF /usr/local/nginx/sbin/nginx -s reload if [ $VERS -eq 7 ]; then I_P=`ifconfig | grep -A 1 -E "^e" | sed -n '2p' | awk -F '[: ]+' '{print $3}'` else I_P=`ifconfig | grep -A 1 -E "^e" | sed -n '2p' | awk -F '[: ]+' '{print $4}'` fi echo "" > /usr/local/nginx/html/a.php curl http://$I_P/a.php &> /dev/null [ $? -eq 0 ] && success "INTEGRATE nginx and php success." fi } ######################################################################## integrate_ap() { SIGNAL2=`ss -tanl | awk '{print $4}' | grep -E "88|9000" | wc -l` if [ $SIGNAL2 -ge 2 ]; then nl -b a /etc/httpd/httpd.conf | grep -E "[[:space:]]{4}AddType application/x-gzip" | awk '{print $1}' | xargs -I {} sed -i '{}a \ AddType application/x-httpd-php .php \ AddType application/x-httpd-php-source .phps' /etc/httpd/httpd.conf sed -i 's/\(DirectoryIndex index.html\)/\1 index.php/' /etc/httpd/httpd.conf sed -i 's/^#LoadModule proxy_module modules\/mod_proxy.so/LoadModule proxy_module modules\/mod_proxy.so/' /etc/httpd/httpd.conf sed -i 's/^#LoadModule proxy_fcgi_module modules\/mod_proxy_fcgi.so/LoadModule proxy_fcgi_module modules\/mod_proxy_fcgi.so/' /etc/httpd/httpd.conf sed -i 's/^#Include \/etc\/httpd\/extra\/httpd-vhosts.conf/Include \/etc\/httpd\/extra\/httpd-vhosts.conf/' /etc/httpd/httpd.conf sleep 1 if [ $VERS -eq 7 ]; then I_P=`ifconfig | grep -A 1 -E "^e" | sed -n '2p' | awk -F '[: ]+' '{print $3}'` else I_P=`ifconfig | grep -A 1 -E "^e" | sed -n '2p' | awk -F '[: ]+' '{print $4}'` fi [[ -d /var/www/html ]] || mkdir /var/www/html -p [[ -f /var/www/html/a.php ]] || touch /var/www/html/a.php echo "" > /var/www/html/a.php sed -i 's/^\(.*\)$/#\1/g' /etc/httpd/extra/httpd-vhosts.conf cat >> /etc/httpd/extra/httpd-vhosts.conf << EOF DocumentRoot "/var/www/html" ServerName $I_P ProxyRequests Off ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/\$1 Options none AllowOverride none Require all granted EOF sleep 2 source /etc/profile.d/httpd.sh sleep 1 apachectl graceful sleep 1 curl http://$I_P:88/a.php &> /dev/null [ $? -eq 0 ] && success "INTEGRATE apache and php success." fi } ######################################################################## proxy_na() { SIGNAL2=`ss -tanl | awk '{print $4}' | grep -E "88|80" | wc -l` if [ $SIGNAL2 -ge 2 ]; then nl -b a /usr/local/nginx/conf/nginx.conf | grep "FastCGI" | awk '{print $1}' | xargs -I {} sed -i '{}a location ~ / { \ proxy_pass http://127.0.0.1:88; \ }' /usr/local/nginx/conf/nginx.conf [[ -d /var/www/html ]] || mkdir -p /var/www/html [[ -f /var/www/html/a.php ]] || touch /var/www/html/a.php echo "" > /var/www/html/a.php curl http://$I_P/a.php &> /dev/null [ $? -eq 0 ] && success "INTEGRATE apache and nginx success." fi } ######################################################################## zb_server() { if ! command -v mysql &> /dev/null then [ $VERS -eq 7 ] && \ yum install -y mariadb || \ yum install -y mysql fi mysql_cmd=`command -v mysql` echo 'Are you have a mysql server? (y/n)' read -p "your answer: " db_answer case $db_answer in y|Y|yes|YES) read -p "Input mysql manager name: " mysql_admin read -p "Input mysql host: " mysql_host read -p "Input mysql port: " mysql_port echo "Input mysql password: " read -s mysql_pass [ -z $mysql_admin -o \ -z $mysql_host -o \ -z $mysql_pass -o \ -z $mysql_port ] && \ failure "absent args" && exit 1 mysql_zb="$mysql_cmd -u$mysql_admin -h$mysql_host -P$mysql_port -p$mysql_pass" ;; n|N|NO|no) install_mysql mysql_zb="$mysql_cmd -uroot" ;; *) failure "invalid answer." exit 1 esac clear && sleep 1 declare -i begin=1 while [ $begin -lt 10 ] do yum install -y zabbix-server-mysql zabbix-web-mysql [ $? -eq 0 ] && break let begin+=1 done [ $? -ne 0 ] && failure "install zabbix-server failure" && exit 1 success "install zabbix-server finish" $mysql_zb -Ns -e "create database zabbix character set utf8 collate utf8_bin;" zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | $mysql_zb zabbix [ $? -ne 0 ] && failure "import mysql metadata failure" && exit 1 zb_conf="/etc/zabbix/zabbix_server.conf" sed -i "s@^# DBHost=localhost@DBHost=$mysql_host@" $zb_conf sed -i "s@^DBUser=zabbix@DBUser=$mysql_admin@" $zb_conf sed -i "s@^# DBPassword.*@DBPassword=$mysql_pass@" $zb_conf sed -i "s@^# DBPort.*@DBPort=$mysql_port@" $zb_conf sed -i 's@# php_value date.timezone.*@php_value date.timezone Asia/Shanghai@' /etc/httpd/conf.d/zabbix.conf sed -i 's@^Listen 80@Listen 8888@' /etc/httpd/conf/httpd.conf zb_font_dir=`grep -oP "(?<=realpath\(').*fonts" /usr/share/zabbix/include/defines.inc.php` default_font_name=`ls /usr/share/zabbix/$zb_font_dir | cut -d. -f1` [ -d /usr/share/fonts/default ] || \ mkdir -p /usr/share/fonts/default pushd /usr/share/fonts/default && \ wget https://9133w.cn/sources/simkai.ttf && \ ln -s /usr/share/fonts/default/simkai.ttf /usr/share/zabbix/$zb_font_dir/simkai.ttf && \ sed -i "s@$default_font_name@simkai@g" /usr/share/zabbix/include/defines.inc.php && popd if [ $VERS -eq 7 ] then systemctl start zabbix-server && \ systemctl enable zabbix-server && \ systemctl start httpd && \ systemctl enable httpd else service zabbix-server start && \ service httpd start && \ chkconfig --add zabbix-server && \ chkconfig --add httpd fi [ $? -ne 0 ] && \ failure "start zabbix-server failure,please check config files" || \ success "start zabbix-server finish" } zb_client() { clear declare -i ins_num=1 while [ $ins_num -lt 10 ] do yum install -y zabbix-agent [ $? -eq 0 ] && break let ins_num+=1 done [ $? -ne 0 ] && failure "zabbix client install failure" && exit 1 success "zabbix client install finish" zb_client_conf="/etc/zabbix/zabbix_agentd.conf" zb_client_userparameter="/etc/zabbix/zabbix_agentd.d/data.conf" [ ! -e $zb_client_conf ] && failure "zabbix client config file not found" && exit 1 read -p "Input zabbix server ip: " server_ip server_ip=${server_ip:-"127.0.0.1"} sed -i 's/^# EnableRemoteCommands=0/EnableRemoteCommands=1/' $zb_client_conf sed -i 's/^# LogRemoteCommands=0/LogRemoteCommands=1/' $zb_client_conf sed -i "s/^Server=.*/Server=$server_ip/" $zb_client_conf sed -i "s/^ServerActive=.*/ServerActive=$server_ip/" $zb_client_conf echo 'UserParameter=tcp_total,/usr/sbin/ss -tn state all | wc -l' >> $zb_client_userparameter echo 'UserParameter=tcp_estab,/usr/sbin/ss -tn state established | wc -l' >> $zb_client_userparameter if [ $VERS -eq 7 ] then systemctl start zabbix-agent && \ systemctl enable zabbix-agent else service zabbix_agent start && \ chkconfig --add zabbix_agent fi [ $? -ne 0 ] && \ failure "zabbix client start failure" || \ success "zabbix client start finish" } install_zabbix() { # # # # # # # # # # [ -d $SOFTDIR/zabbix/ ] || mkdir -p $SOFTDIR/zabbix/ cd $SOFTDIR/zabbix/ z_ver=`curl -s https://repo.zabbix.com/zabbix/ | \ grep -oP '(?<=href=")\d+.\d+' | \ sed '$!{h;d};g'` z_rpm=`curl -s https://repo.zabbix.com/zabbix/$z_ver/rhel/$VERS/x86_64/ | \ grep -o 'zabbix-release.*.rpm"'| sed 's/"//'` rpm -ivh https://repo.zabbix.com/zabbix/$z_ver/rhel/$VERS/x86_64/$z_rpm echo -e "input the number to install:\n[1] SERVER\n[2] CLIENT\n[0] ALL" read -p "choice: " u_choice case $u_choice in 1) zb_server ;; 2) zb_client ;; 0) zb_server zb_client ;; *) failure "invalid choice" exit esac } case $1 in env) install_environment ;; nginx) install_environment install_nginx integrate_np proxy_na ;; http) install_environment install_httpd integrate_ap ;; mysql) read -p "Please input the version of MYSQL:(5.6/5.7) " Versn1 install_environment install_mysql ;; php) read -p "Please input the version of PHP: (5.5/5.6/7.0/7.1...) " Versn2 install_environment install_php integrate_np integrate_ap ;; lnmp) read -p "Please input the version of MYSQL:(5.6/5.7) " Versn1 read -p "Please input the version of PHP: (5.5/5.6/7.0/7.1...) " Versn2 install_environment install_nginx install_mysql install_php integrate_np ;; lnmpa) read -p "Please input the version of MYSQL:(5.6/5.7) " Versn1 read -p "Please input the version of PHP: (5.5/5.6/7.0/7.1...) " Versn2 install_environment install_httpd install_mysql install_php integrate_ap install_nginx proxy_na ;; lamp) read -p "Please input the version of MYSQL:(5.6/5.7) " Versn1 read -p "Please input the version of PHP: (5.5/5.6/7.0/7.1...) " Versn2 install_environment install_httpd install_mysql install_php integrate_ap ;; integrate-np) integrate_np ;; integrate-ap) integrate_ap ;; integrate-na) integrate_ap proxy_na ;; zabbix) install_environment install_zabbix ;; ?) echo "Usage: [nginx|http|mysql|php|env|lnmp|lamp|integrate-np|integrate-ap|integrate-na|zabbix]" ;; *) echo "Usage: [nginx|http|mysql|php|env|lnmp|lamp|integrate-np|integrate-ap|integrate-na|zabbix]" ;; esac exit 0