CentOS7 运维 - LNMP架构企业网站
- 一、Nginx优势
- 二、安装 Nginx
- 三、安装 MySQL
- 四、安装配置 PHP 解析环境
一、Nginx优势
- 静态页处理能力强
- 轻量级
- 并发能力强
- 消息队列[排队]
- 资源消耗低
- 高度模块化
一键安装部署脚本
二、安装 Nginx
yum -y install pcre-devel zlib-devel gcc gcc-c++ make
useradd -M -s /sbin/nologin nginx
#wget -P /opt http://nginx.org/download/nginx-1.19.8.tar.gz
cd /opt
#tar zxvf nginx-1.19.8.tar.gz
#cd nginx-1.19.8
tar zxvf nginx-1.12.0.tar.gz
cd nginx-1.12.0/
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module
make -j && make install
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/nginx
echo '
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target' > /lib/systemd/system/nginx.service
chmod 754 /lib/systemd/system/nginx.service
systemctl start nginx.service
systemctl enable nginx.service &> /dev/null
三、安装 MySQL
yum -y install gcc gcc-c++ ncurses ncurses-devel bison cmake
cd /opt
tar zxvf mysql-5.7.17.tar.gz
tar zxvf boost_1_59_0.tar.gz
cd /opt
mv boost_1_59_0 /usr/local/boost
cd /opt/mysql-5.7.17/
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_EXTRA_CHARSETS=all \
-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=/usr/local/boost \
-DWITH_SYSTEMD=1
make -j 2 && make install
useradd -M -s /sbin/nologin mysql
echo '[client]
port = 3306
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
bind-address = 0.0.0.0
skip-name-resolve
max_connections=2048
default-storage-engine=INNODB
max_allowed_packet=16M
server-id = 1
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' > /etc/my.cnf
chown -R mysql:mysql /usr/local/mysql/
chown mysql:mysql /etc/my.cnf
echo 'export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$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/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
systemctl daemon-reload
systemctl start mysqld.service
systemctl enable mysqld
netstat -anpt | grep 3306
mysqladmin -u root -p password "123456"
四、安装配置 PHP 解析环境
yum -y install \
gd \
libjpeg libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel \
libsqlite3-dev \
epel-release \
oniguruma oniguruma-devel \
libzip libzip-devel
#wget -P /opt https://www.php.net/distributions/php-7.4.16.tar.gz
cd /opt
tar jxvf 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 -j && make install
ln -s /usr/local/php/bin/* /usr/local/bin/
ln -s /usr/local/php/sbin/* /usr/local/sbin/
cp /opt/php-7.1.10/php.ini-development /usr/local/php/php.ini
cd /usr/local/php
cp php.ini{,.bak}
sed -i '1170c mysqli.default_socket = /usr/local/mysql/mysql.sock' php.ini.bak
sed -i '939c date.timezone = Asia/Shanghai' php.ini.bak
cat php.ini.bak > php.ini
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
cp php-fpm.conf{,.bak}
sed -i '17c pid = run/php-fpm.pid' php-fpm.conf.bak
cat php-fpm.conf.bak > php-fpm.conf
cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default www.conf
cp www.conf{,.bak}
sed -i '23c user = nginx' www.conf.bak
sed -i '24c group = nginx' www.conf.bak
sed -i '107c pm.max_children = 50' www.conf.bak
sed -i '112c pm.start_servers = 20' www.conf.bak
sed -i '117c pm.min_spare_servers = 5' www.conf.bak
sed -i '122c pm.max_spare_servers = 20' www.conf.bak
cat www.conf.bak > www.conf
/usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini
netstat -anpt | grep 9000
cd /usr/local/nginx/conf
cp nginx.conf{,.bak}
sed -i '65,71 s/#//g' /usr/local/nginx/conf/nginx.conf.bak
sed -i '69c\\t fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;' /usr/local/nginx/conf/nginx.conf.bak
cat nginx.conf.bak > nginx.conf
systemctl restart nginx.service
cd /usr/local/nginx/html/
echo "<?php
\$link=mysqli_connect('localhost','root','123456');
if(\$link) echo \"<h1>Success</h1>\";
else echo \"Fail~\";
?>" > index.php