GLPI资源管理系统脚本安装(v9.5.0)

Shell脚本自动安装GLPI v9.5.0 资源管理系统

#!/bin/bash
#GLPI
#v9.5.0
#itwangqiang
#服务器版本CentOS 7.4

#测试网络联通性
ping -W1 -c3 www.baidu.com &> /dev/null
if [ $? -ne 0 ];then
	echo -e "\e[5;31m Sorry the network not working! Please check your network! \e[0m" && exit 1
fi

#关闭防火墙和selinux
systemctl disable --now firewalld &>/dev/null
sed -ri "/^SELINUX=/cSELINUX=disbaled" /etc/selinux/config
setenforce 0

#安装YUM源
yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum clean all &> /dev/null
yum makecache &> /dev/null
yum repolist all &> /dev/null
echo -e "\e[1;31m YUM source configuration completed! \e[0m"

#安装PHP和依赖
for i in wget php74-php php74-php-gd php74-php-curl php74-php-fileinfo php74-php-json php74-php-mbstring php74-php-mysqli php74-php-session php74-php-zlib php74-php-simplexml php74-php-xml php74-php-intl php74-php-cli php74-php-domxml php74-php-imap php74-php-loap php74-php-openssl php74-php-xmlrpc php74-php-apcu php74-php-fpm php74-php-ldap php-pear-CAS php74-php-pecl-zip php74-php-opcache
do
	rpm -qa | grep $i &> /dev/null
	if [ $? -ne 0 ];then
		yum install -y $i &>/dev/null
	else
		echo -e "\e[1;32m $i Is already installed! \e[0m"
	fi
done	
	echo -e "\e[1;31m Install PHP Dependent Packet Success! \e[0m"

#配置mariadb10.0版本的源
if [ ! -f /etc/yum.repos.d/mariadb.repo ];then
	cat > /etc/yum.repos.d/mariadb.repo <<-EOF
	[mariadb]
	name=MariaDB
	baseurl=http://yum.mariadb.org/10.4/centos7-amd64
	gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
	gpgcheck=1
	EOF
	yum clean all &> /dev/null
	yum repolist all &> /dev/null
fi

#安装数据库和apache
for i in MariaDB-server.x86_64 httpd
do
	yum list $i &> /dev/null
	if [ -$? -eq 0 ];then
		yum install -y $i &> /dev/null
		echo -e "\e[1;31m $i install successfully \e[0m"
	else
		echo -e "\e[5;31m The installation $i is not available! \e[0m" && exit 1
	fi
done

#配置数据库
systemctl enable --now mariadb &> /dev/null
systemctl status mariadb &> /dev/null
if [ $? -eq 0 ];then
	mysqladmin -u root password "root"
	mysql -uroot -proot -e "create user glpi@'%' identified by '123456';"
	mysql -uroot -proot -e "create database glpi;"
	mysql -uroot -proot -e "grant all privileges on glpi.* to glpi@'%';"
	mysql -uroot -proot -e "flush privileges;"
	echo "mysql password is root" >> /root/.password
	echo "SQL user is:glpi ;SQL password is:123456" >> /root/.password
else
	echo -e "\e[5;31m Database not started \e[0m" && exit 1
fi
echo -e "\e[1;31m Database configuration complete \e[0m"

#修改/etc/php.ini
rpm -qa | grep php &> /dev/null
if [ $? -eq 0 ];then
	sed -ri "/^memory_limit/cmemory_limit = 64M" /etc/php.ini
	sed -ri "/^file_uploads/cfile_uploads = on" /etc/php.ini
	sed -ri "/^max_execution_time/cmax_execution_time = 600" /etc/php.ini
	sed -ri "/^session.auto_st/csession.auto_st = off" /etc/php.ini
	sed -ri "/^session.use_trans_sid/csession.use_trans_sid = 0" /etc/php.ini
fi
echo -e "\e[1;31m PHP configuration complete \e[0m"

#修改httpd配置文件
systemctl enable --now httpd &> /dev/null
sed -ri "/^\    DirectoryIndex/c\    DirectoryIndex index.php index.html" /etc/httpd/conf/httpd.conf
systemctl restart httpd

#下载GLPI
wget https://github.com/glpi-project/glpi/releases/download/9.5.0/glpi-9.5.0.tgz
tar -zxvf glpi-9.5.0.tgz -C /var/www/html/ &> /dev/null
chown -R apache.apache /var/www/html/glpi
sed -ri '/^DocumentRoot/cDocumentRoot "/var/www/html/glpi"' /etc/httpd/conf/httpd.conf
systemctl restart httpd

echo "GLPI 安装完成!请在浏览器地址栏输入服务器地址(IP),继续完成GLPI的配置!"
exit
posted @ 2021-02-28 12:25  廿九九  阅读(338)  评论(0)    收藏  举报