# nginx脚本

```shell
#!/bin/bash
useradd -r nginx -s /bin/false 
cd /opt &&  wget http://nginx.org/download/nginx-1.20.1.tar.gz
tar -zxvf nginx-1.20.1.tar.gz   &&  cd nginx-1.20.1
yum install -y gcc gcc-c++ automake openssl openssl-devel make pcre-devel gd-devel  glibc-devel &> /dev/null
./configure --prefix=/usr/local/nginx --user=nginx  --group=nginx --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/var/log/nginx/nginx.log --http-log-path=/var/log/nginx/access.log --modules-path=/usr/local/nginx/modules --with-select_module --with-poll_module --with-threads  --with-http_ssl_module --with-http_v2_module  --with-http_realip_module --with-http_image_filter_module --with-http_sub_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module  --with-http_stub_status_module --with-stream
make && make install
ln -s /usr/local/nginx/nginx /usr/sbin/nginx
nginx
ps -ef |grep nginx



```

# tomcat脚本

```
#!/bin/bash
cd /opt && wget https://archive.apache.org/dist/tomcat/tomcat-8/v8.5.78/bin/apache-tomcat-8.5.78.tar.gz
tar -zxvf apache-tomcat-8.5.78.tar.gz
mv apache-tomcat-8.5.78 /usr/local/tomcat
cd /usr/local/tomcat/bin
./catalina.sh start
ps -ef |grep tomcat

```

# apache脚本http

```
#!/bin/bash
yum install httpd httpd-devel -y
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed 's/Listen 80/Listen 86/g' /etc/httpd/conf/httpd.conf
systemctl  start  httpd.service
systemctl enable  httpd.service
```

# NFS脚本

```
#!/bin/bash
#nfs脚本
yum -y install 	nfs-utils rpcbind &>> /dev/null
systemctl start rpcbind
systemctl enable rpcbind
systemctl start nfs
systemctl  enable nfs
echo "/opt/nfstest  			192.168.110.*(rw)" >>/etc/exports
mkdir /opt/nfstest
chmod 777 -R /opt/nfstest/
chown nfsnobody.nfsnobody -R /opt/nfstest/

#tab补全
yum install -y bash-completion
source /usr/share/bash-completion/bash_completion
```









# 环境初始化脚本

```
#!/bin/bash
# 获取当前主机名
current_hostname=$(hostnamectl status | grep 'Static hostname' | awk '{print $3}')
# 获取新主机名
read -p "请输入新的主机名": new_hostname
# 修改 /etc/hostname 文件
sudo sed -i "s/$current_hostname/$new_hostname/g" /etc/hostname
# 更新当前主机名
sudo hostnamectl set-hostname $new_hostname
echo "主机名已成功修改为$new_hostname！"

#!/bin/bash
#本地源
mount /dev/cdrom /mnt/
ls /mnt/
mkdir /etc/yum.repos.d/bak  
mv /etc/yum.repos.d/*
ll /etc/yum.repos.d/bak/
echo "[local]
name=local
baseurl=file:///mnt
enable=1
gpgcheck=0
gpgkey=file:///mnt/RPM-GPG-KEY-CentOS-7" > /etc/yum.repos.d/local.repo
yum clean all
yum list
yum repolist
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
ll /etc/yum.repos.d/
yum clean all 
yum list

#tab补全
yum install -y bash-completion
source /usr/share/bash-completion/bash_completion

systemctl stop firewalld
systemctl disable firewalld
setenforce 0

#!/bin/bash
#epel源
yum -y install python-jinja2 PyYAML python-paramiko python-babel python-crypto
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum install -y epel-release
```

# mysql编译安装

```shell
#!/bin/bash
#mysql5.7安装
if [ ! -f mysql-boost-5.7.36.tar.gz ]
   then
     wget http://106.55.16.110/mysql/mysql-boost-5.7.36.tar.gz  /opt &> /dev/null
   else
     echo '二进制包已存在，跳过下载源码包步骤'
fi
yum -y install gcc-c++  ncurses   ncurses-devel cmake
cd /opt/ && tar -xf mysql-boost-5.7.36.tar.gz &> /dev/null
mv /opt/mysql-5.7.36  /usr/local/mysql
yum install openssl openssl-devel bison* libaio libaio-devel -y
cd /usr/local/mysql/ && cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_TCP_PORT=3366 -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDOWNLOAD_BOOST=0 -DWITH_BOOST=/opt/mysql/boost -DWITH_INNODB_MEMCACHED=ON
make && make install
useradd mysql -s /sbin/nologin
mkdir -p /data/mysql
mkdir -p /var/log/mysq
chown mysql:mysql -R /usr/local/mysql  /data/mysql  /var/log/mysql
echo "export PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile && source /etc/profile
echo "[mysqld]
user=mysql 
basedir=/usr/local/mysql
datadir=/data/mysql 
server_id=1
port=3366
socket=/data/mysql/mysql.sock
[mysql] 
socket=/data/mysql/mysql.sock 
[mysqld_safe]
log-error=/var/log/mysql/mysql.log 
pid-file=/data/mysql/mysql.pid" >/etc/my.cnf
mysqld --initialize-insecure  --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
cp /usr/local/mysql/support-files/mysql.server.sh /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld  
systemctl start mysqld
```

# mysql二进制安装

```shell
#!/bin/bash
#mysql5.7安装
if [ ! -f mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz ]
   then
     wget http://106.55.16.110/mysql/mysql-5.7.30-linux-glibc2.12-x86_64.tar  /opt &> /dev/null
   else
     echo '二进制包已存在，跳过下载源码包步骤'
fi
#清除环境
yum remove mariadb-libs -y
yum install wget -y
#创建用户和用户组
useradd mysql -s /sbin/nologin
#数据存储目录
mkdir -p /data/mysqldata
#创建日志目录
mkdir -p /var/log/mysql
#创建bilog日志
mkdir /data/binlog
#设置权限
chown mysql:mysql -R /data/mysqldata
chown mysql:mysql -R /var/log/mysql
chown mysql.mysql -R /data/binlog/
#增加环境变量
echo "export PATH=/usr/local/mysql/bin:$PATH">>/etc/profile
echo "正在解压"
#解压包
tar -xf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz
#解压完目录放到软件目录位置
mv mysql-5.7.30-linux-glibc2.12-x86_64  /usr/local/mysql
#设置目录权限
chown mysql:mysql -R /usr/local/mysql

#初始化数据库
mysqld --initialize-insecure  --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysqldata

#配置文件
echo "[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysqldata
server_id=6
log_bin=/data/binlog/mysql-bin
sync_binlog=1
binlog_format=row
expire_logs_days=15
max_binlog_size = 150M
gtid-mode=on
enforce-gtid-consistency=true
log-error=/var/log/mysql/error.log
slow_query_log=1
long_query_time=3
log_queries_not_using_indexes=1
slow_query_log_file=/var/log/mysql/slow.log
port=3306
socket=/tmp/mysql.sock
[mysql]
socket=/tmp/mysql.sock
prompt=mysql[\\d]>
[client]
socket=/tmp/mysql.sock" >/etc/my.cnf

#mysql启动脚本
cp /usr/local/mysql/support-files/mysql.server   /etc/init.d/mysqld
chmod a+x   /etc/init.d/mysqld
/etc/init.d/mysqld start
echo  "查看端口"
netstat -lnp|grep 3306
#添加至systemd管理
chkconfig --add mysqld


```



# php安装

```
#!/bin/bash
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum install autoconf gcc libxml2-devel openssl-devel curl-devel libjpeg-devel libpng-devel libXpm-devel freetype-devel libmcrypt-devel make ImageMagick-devel libssh2-devel gcc-c++ cyrus-sasl-devel  sqlite-devel  oniguruma oniguruma-devel -y
cd /opt && tar -xvf php-7.4.28.tar.gz
cd /opt/php-7.4.28  && ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/etc/php.d --disable-ipv6 --enable-bcmath --enable-calendar --enable-exif --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-ftp --enable-gd-jis-conv --enable-gd-native-ttf --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-mysqlnd --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-static --enable-sysvsem --enable-wddx --enable-xml --with-curl --with-gd --with-jpeg-dir --with-freetype-dir --with-xpm-dir --with-png-dir --with-gettext --with-iconv --with-libxml-dir --with-mcrypt --with-mhash --with-mysqli --with-pdo-mysql --with-pear --with-openssl --with-xmlrpc --with-zlib --disable-debug --disable-phpdbg
cd /opt/php-7.4.28
make && make install
cp /opt/php-7.4.28/sapi/fpm/init.d.php-fpm  /usr/local/php/php-fpm
chmod a+x /usr/local/php/php-fpm
cp /opt/php-7.4.28/php.ini-development  /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default  /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default   /usr/local/php/etc/php-fpm.d/www.conf
useradd www -s /sbin/nologin
/usr/local/php/php-fpm start
cd /www/php  &&  echo "<?php
phpinfo();
?> " index.php
```

