一、编写nginx一键部署脚本
1、导入数据包
2、开始编写脚本
#!/bin/bash
#nginx
cd /opt
tar zxvf nginx-1.12.2.tar.gz
yum -y install gcc gcc-c++ make pcre-devel zlib-devel
useradd -M -s /sbin/nologin nginx
cd nginx-1.12.2/
./configure --prefix=/usr/local/nginx \
--user=nginx\
--group=nginx\
--with-http_stub_status_module
make && make install
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
echo '#!/bin/bash
#chkconfig: 35 99 20
#nginx
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
start)
$PROG
;;
stop)
kill -s QUIT $(cat $PIDF)
;;
restart)
$0 stop
$0 start
;;
reload)
kill -s HUP $(cat $PIDF)
;;
*)
echo "Usage:$0 {start|stop|restart|reload}"
exit 1
esac
exit 0' > /etc/init.d/nginx
chmod +x /etc/init.d/nginx
chkconfig --add nginx
sed -i -e "s/^#user nobody;/user nobody;/ g" /usr/local/nginx/conf/nginx.conf
sed -i -e "/error.log info;/s/#/ / g" /usr/local/nginx/conf/nginx.conf
systemctl start nginx
systemctl enable nginx
netstat -anptu |grep nginx
二、编写mysql一键部署脚本
1、导入数据包
2、编写脚本
#!/bin/bash
#安装mysql数据库,上传mysql-boost-5.7.20.tar.gz
#需要使用source mysql.sh 执行脚本
yum -y install \
ncurses \
ncurses-devel \
bison \
cmake
useradd -s /sbin/nologin mysql
cd /opt
tar xf mysql-boost-5.7.20.tar.gz
cd /opt/mysql-5.7.20/
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DSYSCONFDIR=/etc \
-DSYSTEMD_PID_DIR=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=boost \
-DWITH_SYSTEMD=1
make && make install
chown -R mysql:mysql /usr/local/mysql/
echo '
[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 1 ' > /etc/my.cnf
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
chown mysql:mysql /etc/my.cnf
echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
echo 'export PATH' >> /etc/profile
source /etc/profile
cd /usr/local/mysql/
bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data
cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
systemctl enable mysqld
systemctl start mysqld
systemctl status mysqld
netstat -anpt | grep 3306
yum -y install expect.x86_64
/usr/bin/expect <<-EOF
spawn mysqladmin -u root -p password 123456
expect {
"Enter password:" {send "\r"}
}
expect eof
EOF
/usr/bin/expect <<-EOF
spawn mysql -u root -p
expect {
"Enter password:" {send "123456\r"}
}
expect eof
EOF
三、编写php一键部署脚本
1、导入数据包
2、编写脚本
#!/bin/bash
#安装php,需要source php.sh来执行
yum -y install \
libjpeg \
libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 \
libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel
cd /opt
tar xjvf php-7.1.10.tar.bz2
cd php-7.1.10
./configure \
--prefix=/usr/local/php \
--with-mysql-sock=/usr/local/mysql/mysql.sock \
--with-mysqli \
--with-zlib \
--with-curl \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-openssl \
--enable-fpm \
--enable-mbstring \
--enable-xml \
--enable-session \
--enable-ftp \
--enable-pdo \
--enable-tokenizer \
--enable-zip
make && make install
cp php.ini-development /usr/local/php/lib/php.ini
sed -i -e "s/mysqli.default_socket =/ /g" /usr/local/php/lib/php.ini
a="mysqli.default_socket = /usr/local/mysql/mysql.sock"
sed -i -e "/mysqli.default_port = 3306/a$a" /usr/local/php/lib/php.ini
sed -i -e "s/^;date.timezone =/ /g" /usr/local/php/lib/php.ini
b="date.timezone = Asia/Shanghai"
sed -i -e "/date.timezone$/a$b" /usr/local/php/lib/php.ini
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default www.conf
cd /usr/local/php/etc/
sed -i -e "/^;pid = run/s/;/ /g" /usr/local/php/lib/php.ini
/usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini
ln -s /usr/local/php/bin/* /usr/local/bin
echo '#!/bin/bash
#chkconfig: 35 99 20
#nginx
PROG_FPM="/usr/local/sbin/php-fpm"
PIDF_FPM="/usr/local/php/var/run/php-fpm.pdi"
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
start)
$PROG
$PROG_FPM
;;
stop)
kill -s QUIT $(cat $PIDF)
kill -s QUIT $(cat $PIDF_FPM)
;;
restart)
$0 stop
$0 start
;;
reload)
kill -s HUP $(cat $PIDF)
kill -s HUP $(cat $PIDF_FPM)
;;
*)
echo "Usage:$0 {start|stop|restart|reload}"
exit 1
esac
exit 0 ' > /etc/init.d/nginx
chmod +x /etc/init.d/nginx
chkconfig --add nginx
d=" location ~ \.php$ {"
e=" root /var/www/aa;"
f=" fastcgi_pass 127.0.0.1:9000;"
g=" include fastcgi.conf;"
h=" }"
sed -i -e "/#charset koi8-r;/a$d\n$e\n$f\n$g\n$h" /usr/local/nginx/conf/nginx.conf
mkdir -p /var/www/aa/
echo '<?php
phpinfo();
?>' > /var/www/aa/index.php
systemctl restart nginx
四、测试效果
五、数据包下载地址
链接:https://pan.baidu.com/s/15HfmQDdUaW4zmjLf8l8lpw
提取码:iwwr