練習:遠程鏈接客戶機安裝php+tengine,php
1、須要用到腳本8獲取遠程ip以及推送公鑰到遠程機器。html
2、建立以下目錄結構mysql
1.lnmp.shlinux
------------------------------------------------------nginx
lnmpc++
├── confsql
│ ├── index.phpshell
│ ├── nginx.conf數據庫
│ └── php-fpm.confapi
├── include
│ ├── config.sh
│ ├── init_os.sh
│ ├── nginx_install.sh
│ └── php_install.sh
├── installrc
├── lnmp.sh
└── src
├── php-7.2.6.tar.bz2
└── tengine-2.3.0.tar.gz
3、分別編寫腳本
#!/bin/bash
#####lnmp main program
###2019-6-8######
soft_dir=`pwd`/src
config_dir=`pwd`/conf
cpus=`lscpu|awk '/^CPU\(s\)/{print $2}'`
. installrc
. include/init_os.sh
. include/nginx_install.sh
. include/php_install.sh
. include/config.sh
init_os
nginx_install
php_install
config
2.init_os.sh
#!/bin/bash
#### init os #########
###yum########
init_os(){
rm -rf /etc/yum.repos.d/*
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum make cache && yum repolist
####SELinux########
systemctl disable firewalld
systemctl stop firewalld
#firewall-cmd --permanent --add-service=http
#firewall-cmd --permanent --add-service=https
#firewall-cmd --reload
setenforce 0
sed -ri '/^SELINUX=/cSELINUX=disabled' /etc/selinux/config
#NTP
yum -y install chrony
sed -ri '/3.CentOS.pool.ntp.oeg/a\server pool.ntp.org iburst prefer' /etc/chrony.conf
systemctl start chronyd
systemctl enable chronyd
}
3.nginx_install.sh
#!/bin/bash
#
#tengine install scripts
#by Dan Chen 2019-6-8
nginx_install(){
yum -y install gcc gcc-c++ openssl-devel pcre-devel
useradd nginx
cd $soft_dir
tar xf $tengine_version
cd ${tengine_version%.tar.gz}
./configure && make -j $cpus && make install
echo "$nginx_prefix/sbin/nginx" >> /etc/rc.local
chmod a+x /etc/rc.d/rc.local
echo "export PATH=$PATH:$nginx_prefix/sbin" >> /etc/profile
source /etc/profile
}
4.php_install.sh
#!/bin/bash
#
##php install scripts
php_install(){
yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel \
libxml libxml-devel libcurl libcurl-devel libxslt-devel openssl-devel
cd $soft_dir
tar xf $php_version
cd ${php_version%.tar.bz2}
./configure --prefix=$php_prefix --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir \
--with-jpeg-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysql --with-mysqli \
--with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir \
--with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-libxml \
--enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache \
--enable-pcntl --enable-shmop --enable-sockets --enable-sysvsem --enable-xml --enable-zip
make -j $cpus && make install
cp $php_prefix/etc/php-fpm.conf.default $php_prefix/etc/php-fpm.conf
cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
chmod a+x /etc/rc.d/init.d/php-fpm
chkconfig --add php-fpm
}
5.config.sh
#!/bin/bash
#config conf
config() {
#tengine
\cp $config_dir/nginx.conf $nginx_prefix/conf/nginx.conf
\cp $config_dir/index.php $nginx_prefix/html/index.php
\cp $php_prefix/etc/php-fpm.d/www.conf.default $php_prefix/etc/php-fpm.d/www.conf
$nginx_prefix/sbin/nginx
/etc/init.d/php-fpm start
}
6.installrc
#!/bin/bash
#config conf
config() {
#tengine
\cp $config_dir/nginx.conf $nginx_prefix/conf/nginx.conf
\cp $config_dir/index.php $nginx_prefix/html/index.php
\cp $php_prefix/etc/php-fpm.d/www.conf.default $php_prefix/etc/php-fpm.d/www.conf
$nginx_prefix/sbin/nginx
/etc/init.d/php-fpm start
}
總結:
1.本例主要是使用shell函數,在主程序lnmp.sh入口中調用函數,安裝過程大概20分鐘左右
2.本例未安裝mysql數據庫,緣由是通常mysql是單獨安裝在多臺高配置服務器並作成集羣更好一點,有興趣的朋友能夠嘗試完成mysql集羣的搭建。
運行結果:
[root@Node1 etc]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:80 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 127.0.0.1:9000 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*