#!/bin/bash
nginx_souecepwd=/usr/local/nginx #源码安装路径
cdnginx_configpwd=/usr/local/nginx/conf
systemd_ExecStartpwd=/usr/local/nginx/sbin/nginx
if [ ! -d $nginx_souecepwd ];then
mkdir $nginx_souecepwd
echo "=========================开始安装Nginx==========================="
sed -i 's/SELINUX=enforcing/\SELINUX=disabled/' /etc/selinux/config #关闭selinux
for nginx_depend_pack in wget gcc pcre pcre-devel zlib zlib-devel;do
nginx_depend_result=$(rpm -qa $nginx_depend_pack)
if [ -z "$nginx_depend_result" ];then
yum install -y $nginx_depend_pack
else
echo "$nginx_depend_pack is 判断是否安装NGINX依赖包OK"
fi
done
nginxdownloadurl="http://192.168.80.113/nginx-1.22.0.tar.gz"
cd $nginx_souecepwd
wget "$nginxdownloadurl"
nginx_targzname=$(echo $nginxdownloadurl | sed 's#.*/##')
tar -zxvf $nginx_targzname #解压缩nginx源码包
dirname=$(echo $nginx_targzname | sed 's/.tar.gz//')
cd $dirname #进入nginx源码包
./configure --prefix=$nginx_souecepwd
make -j4 && make install || exit 1
cp /etc/profile /etc/profile.bak #使用sed 命令操作配置文件前 先备份文件 否则文件有可能找不到
sed -i '$ a export PATH=$PATH:/usr/local/nginx/sbin' /etc/profile #注意:这行可能导致配置文件消失 环境变量全无 (之前笔者由于多写或写多了一个字符就发生血案0.0)#
#往/etc/profile文件最后一行添加环境变量 添加环境变量的好处 可以便管理员直接执行“nginx”命令就可以调用Nginx的主程序#
echo "[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=$systemd_ExecStartpwd
ExecReload=$systemd_ExecStartpwd -s reload
ExecStop=$systemd_ExecStartpwd -s stop
[Install]
WantedBy=multi-user.target" > /usr/lib/systemd/system/nginx.service
#为了使Nginx服务器以systemctl运行
chmod 754 /lib/systemd/system/nginx.service
systemctl start nginx.service
systemctl enable nginx.service
cd $cdnginx_configpwd
cp nginx.conf nginx.conf.bak
sed -i '45s/index index.html index.htm;/ index index.php index.html index.htm ;/g' nginx.conf
sed -i '65,71s/#/ /g' nginx.conf #将65行到71行的
sed -i 's#/scripts#$document_root#g' nginx.conf
nginx -t
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload
programName=${0##*/}
echo $programName
source /etc/profile $programName
else
echo "=========================安装Nginx失败已经安装过Nginx==========================="
fi
#下面是编译PHP安装
php_souece_pwd=/usr/local/php
cd_php_configpwd=/usr/local/php/etc
phpfpm_systemd_ExecStartpwd=/usr/local/php/sbin/php-fpm
cp_phpconf_ini=/usr/local/php/etc/php-fpm.conf.default
cd_phpconf_ini=usr/local/php/etc/php-fpm.conf
if [ ! -d $php_souece_pwd ];then
mkdir $php_souece_pwd
echo "=========================开始安装php==========================="
yum -y install epel-release
for php_depend_pack in gcc gcc-c++ make pcre pcre-devel zlib zlib-devel openssl openssl-devel libxml2 libxml2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel openldap openldap-devel libmcrypt libmcrypt-devel;do
php_depend_result=$(rpm -qa $php_depend_pack)
if [ -z "$php_depend_result" ];then
yum install -y $php_depend_pack
else
echo "$php_depend_pack is 判断是否安装php依赖包OK"
fi
done
phpdownloadurl="http://192.168.80.113/php-5.6.40.tar.gz"
cd $php_souece_pwd
wget "$phpdownloadurl"
php_targz_name=$(echo $phpdownloadurl | sed 's#.*/##')
tar -zxvf $php_targz_name
php_dir_name=$(echo $php_targz_name | sed 's/.tar.gz//')
cd $php_dir_name
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-ctype --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --with-gettext --enable-fpm
#./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-ctype --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --with-gettext --enable-fpm
#./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --with-mhash --with-openssl --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib --enable-bcmath --enable-gd --with-jpeg --with-freetype --enable-mbstring --enable-ftp --enable-sockets --with-gettext --enable-session --with-curl --enable-fpm --with-fpm-user=php --with-fpm-group=php --enable-pdo -enable-tokenizer --with-zip
make -j4 && make install
cp php.ini-production /usr/local/php/etc/php.ini
echo "[Unit]
Description=php-fpm
After=network.target
[Service]
Type=forking
ExecStart=$phpfpm_systemd_ExecStartpwd
[Install]
WantedBy=multi-user.target" > /usr/lib/systemd/system/php-fpm.service
chmod 754 /usr/lib/systemd/system/php-fpm.service
mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cd $cd_php_configpwd
cp /etc/profile /etc/profile.php
#sed -i '164c listen = 0.0.0.0:9000' php-fpm.conf
sed -i '190s/;//g' php-fpm.conf
echo 'export PATH=$PATH:/usr/local/php/sbin/:/usr/local/php/bin/' >> /etc/profile
programName=${0##*/}
echo $programName
source /etc/profile $programName
systemctl start php-fpm.service
systemctl enable php-fpm.service
systemctl restart php-fpm.service
systemctl restart nginx.service
firewall-cmd --zone=public --add-port=9000/tcp --permanent
firewall-cmd --zone=public --add-port=9000/udp --permanent
firewall-cmd --reload
else
echo "=========================安装php失败已经安装过php==========================="
fi
mysql_souece_pwd=/usr/local/mysql
cd_mysql_cnfmypwd=/usr/local/mysql/etc/my.cnf
data_mysql=/data/mysql
cd_mysqlslow_log=/data/mysql/mysql-slow.log
cp_mysqlmy_conf_ini=
cd_mysqlmy_conf_ini=
if [ ! -d $mysql_souece_pwd ];then
mkdir $mysql_souece_pwd
echo "=========================开始安装mysql==========================="
yum -y install epel-release
useradd -s /sbin/nologin mysql
for mysql_depend_pack in gcc gcc-c++ make tar openssl openssl-devel cmake ncurses ncurses-devel;do
mysql_depend_result=$(rpm -qa $mysql_depend_pack)
if [ -z "$mysql_depend_result" ];then
yum install -y $mysql_depend_pack
else
echo "$mysql_depend_pack is 判断是否安装mysql依赖包OK"
fi
done
mysqldownloadurl="http://192.168.80.113/mysql-5.6.39.tar.gz"
cd $mysql_souece_pwd
wget "$mysqldownloadurl"
mysql_targz_name=$(echo $mysqldownloadurl | sed 's#.*/##')
tar -zxvf $mysql_targz_name
mysql_dir_name=$(echo $mysql_targz_name | sed 's/.tar.gz//')
cd $mysql_dir_name
cmake -DCMAKE_INSTALL_PREFIX=$mysql_souece_pwd -DMYSQL_DATADIR=$data_mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=all -DWITH_DEBUG=0 -DWITH_SSL=yes -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 2>/tmp/aa
make -j4 && make install
cp support-files/mysql.server /etc/init.d/mysqld
chmod a+x /etc/init.d/mysqld
cd "$mysql_dir_name"
cp my.cnf my.cnf.bak
mkdir /usr/local/mysql/etc
mv my.cnf /usr/local/mysql/etc/my.cnf.bak
rm -rf /usr/local/mysql/my.cnf
mkdir -pv /data
chmod 777 /data
chown -R mysql:mysql /data/
mkdir -pv /data/mysql
chmod 777 /data/mysql
chown -R mysql:mysql /data/mysql
chown -R mysql:mysql /usr/local/mysql/data
chown -R mysql:mysql /usr/local/mysql /data/mysql
echo "[mysqld]
bind-address=0.0.0.0
port=3306
datadir=/data/mysql
user=mysql
skip-name-resolve
long_query_time=2
slow_query_log_file=/data/mysql/mysql-slow.log
expire_logs_days=2
innodb-file-per-table=1
innodb_flush_log_at_trx_commit = 2
log_warnings = 1
max_allowed_packet = 512M
connect_timeout = 60
net_read_timeout = 120
[mysqld_safe]
log-error=/data/mysql/mysqld.log
pid-file=/data/mysql/mysqld.pid " > /usr/local/mysql/etc/my.cnf
chmod 777 /usr/lib/systemd/system/mysqld.service
mkdir /var/lib//mysql
chmod 777 /var/lib//mysql
yum install -y perl-Module-Install
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --user=mysql --datadir=/data/mysql/
echo '[Unit]
Description=mysqld
After=network.target
[Service]
Type=forking
ExecStart=/etc/init.d/mysqld start
[Install]
WantedBy=multi-user.target' > /usr/lib/systemd/system/mysqld.service
chmod 777 /usr/lib/systemd/system/mysqld.service
ln -s /usr/local/mysql/bin/mysql /usr/bin
echo 'export PATH=$PATH:/usr/local/mysql/bin/' >>/etc/profile
programName=${0##*/}
echo $programName
source /etc/profile $programName
#systemctl daemon-reload
systemctl enable mysqld
systemctl restart mysqld.service
systemctl enable mysqld.service
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
else
echo "=========================安装mysql失败已经安装过mysql==========================="
fi
#
#Zabbix Server编译安装
#mysqladmin -h 127.0.0.1 -u root password 'sjgtest666_SJG' <<EOF
#flush privileges;
#EOF
mysql -uroot -h 127.0.0.1 <<EOF
set password for 'root'@'127.0.0.1'=password('sjgtest666_SJG');
flush privileges;
EOF
mysql -uroot -h 127.0.0.1 -p'sjgtest666_SJG' <<EOF
#create user 'wordpress'@'127.0.0.1' identified with mysql_native_password by 'sjgtest666_SJG';
#grant all privileges on wordpress.* to 'wordpress'@'127.0.0.1' with grant option;
#create database zabbix character set utf8;
#set names utf8;
create database zabbix character set utf8 collate utf8_bin;
grant all privileges on zabbix.* to zabbix@'127.0.0.1' identified by 'zabbixpwd';
#create user zabbix@'127.0.0.1' identified by 'zabbixpwd';
#grant all privileges on zabbix.* to zabbix@'127.0.0.1';
flush privileges;
quit
EOF
yum install -y libevent-devel wget tar gcc gcc-c++ make net-snmp-devel libxml2-devel libcurl-devel
useradd -s /sbin/nologin zabbix
cd /usr/local/src/
#wget 'https://nchc.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.0.3/zabbix-4.0.3.tar.gz'
wget 'http://192.168.80.113/zabbix-4.0.42.tar.gz'
tar -zxvf zabbix-4.0.42.tar.gz
#mkdir /usr/local/zabbix
#mv zabbix-4.0.42 /usr/local/zabbix
cd /usr/local/src/zabbix-4.0.42
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql=/usr/local/mysql/bin/mysql_config --with-net-snmp --with-libcurl --with-libxml2
make -j4 && make install
echo 'export PATH=$PATH:/usr/local/zabbix/sbin/:/usr/local/zabbix/bin/' >> /etc/profile
programName=${0##*/}
echo $programName
source /etc/profile $programName
mysql -uroot -h 127.0.0.1 -p'sjgtest666_SJG' <<EOF
use zabbix;
source /usr/local/src/zabbix-4.0.42/database/mysql/schema.sql;
source /usr/local/src/zabbix-4.0.42/database/mysql/images.sql;
source /usr/local/src/zabbix-4.0.42/database/mysql/data.sql;
EOF
echo 'LogFile=/usr/local/zabbix/zabbix_server.log
DBHost=127.0.0.1
DBName=zabbix
DBUser=zabbix
DBPassword=zabbixpwd
DBPort=3306
Timeout=30
AlertScriptsPath=/usr/local/zabbix/alertscripts
ExternalScripts=/usr/local/zabbix/externalscripts
LogSlowQueries=3000' > /usr/local/zabbix/etc/zabbix_server.conf
chown zabbix:zabbix -R /usr/local/zabbix/
zabbix_server
mkdir /usr/local/nginx/html/zabbix
cp -a /usr/local/src/zabbix-4.0.42/frontends/php/* /usr/local/nginx/html/zabbix/
sed -i '660c post_max_size = 32M' /usr/local/php/etc/php.ini
sed -i '372c max_execution_time = 350' /usr/local/php/etc/php.ini
sed -i '382c max_input_time = 350' /usr/local/php/etc/php.ini
sed -i '936c date.timezone = Asia/Shanghai' /usr/local/php/etc/php.ini
sed -i '702c always_populate_raw_post_data = -1' /usr/local/php/etc/php.ini
systemctl restart php-fpm
firewall-cmd --zone=public --add-port=10051/tcp --permanent
firewall-cmd --zone=public --add-port=10051/udp --permanent
firewall-cmd --reload
标签:enable,--,local,一键,usr,mysql,php,安装,zhabix4.0 From: https://www.cnblogs.com/lypro/p/zhabix4_0_3.html