Overview of LNMP architecture and construction of related services
- 1. Manually compile nginx service
- Second, manually compile the mysql database (one-click deployment script content)
- Three, manually compile and install PHP
-
- 1. Import the installation package and decompress it
- 2. The installation environment depends on the package
- 3. Compile and install
- 4. Configure the php.ini file
- 5. Configure the php-fpm.conf file
- 6. Configure www.conf file
- 7. Start php-fpm
- 8. Configure nginx to support PHP parsing
- 9. Test access page
- 10. Verify that the database is working properly
- 4. Deploy Discuz! Community Forum web application
1. Manually compile nginx service
1. Turn off the firewall and security mechanism
2. Import the installation package and decompress it
3. Install environment dependent packages and create program users
yum -y install pcre-devel zlib-devel gcc gcc-c++ make
useradd -M -s /sbin/nologin nginx
4. Compile and install nginx
cd nginx-1.12.0/
./configure \
--prefix=/usr/local/nginx \ #指定nginx的安装路径
--user=nginx \ #指定用户名
--group=nginx \ #指定组名
--with-http_stub_status_module #启用 http_stub_status_module 模块以支持状态统计
make && make install
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ #让系统识别nginx的操作命令
5. Start and stop the nginx service
nginx -t #检查配置文件是否配置正确
nginx #启动
cat /usr/local/nginx/logs/nginx.pid #先查看nginx的PID号
kill -3 <PID号>
kill -s QUIT <PID号> #停止
killall -3 nginx
killall -s QUIT nginx
6. Add Nginx system service
vim /lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecrReload=/bin/kill -s HUP $MAINPID
ExecrStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
chmod 754 /lib/systemd/system/nginx.service
systemctl start nginx.service
systemctl enable nginx.service
Second, manually compile the mysql database (one-click deployment script content)
#--------编译安装mysql 服务--------
#mysql-5.7.17.tar.gz
#boost_1_59_0.tar.gz
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
echo "进行安装mysql服务"
mount /dev/sr0 /mnt
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
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
cd /usr/local/mysql/bin/
./mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data
#添加mysqld系统服务
cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/ #用于systemctl服务管理
source /etc/profile
systemctl daemon-reload #刷新识别
systemctl start mysqld.service #开启服务
systemctl enable mysqld #开机自启动
netstat -anpt | grep 3306 #查看端口
yum -y install expect
function abc {
passwd=$1
/usr/bin/expect <<-EOF
spawn mysqladmin -u root -p password $passwd
expect "Enter password:"
send "\r"
expect eof
EOF
}
abc "abc123"
function bcd {
/usr/bin/expect <<-EOF
spawn mysql -u root -p
expect "Enter password:" {
send "abc123\r"}
expect "mysql>" {
send "grant all privileges on *.* to 'root'@'%' identified by 'abc123';\r"}
expect "mysql>" {
send "show databases;\r"}
expect "mysql>" {
send "quit\r"}
expect eof
EOF
}
bcd
echo -e "\033[31m mysql安装完成!\033[0m"
Three, manually compile and install PHP
1. Import the installation package and decompress it
2. The installation environment depends on the package
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
3. Compile and install
cd /opt/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
ln -s /usr/local/php/bin/* /usr/local/bin/
4. Configure the php.ini file
cp /opt/php-7.1.10/php.ini-development /usr/local/php/lib/php.ini
vim /usr/local/php/lib/php.ini
#939行;取消注释,修改
date.timezone = Asia/Shanghai
#1170行;修改
mysqli.default_socket = /usr/local/mysql/mysql.sock
php -m
5. Configure the php-fpm.conf file
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
vim php-fpm.conf
#17行;去掉注释符“;”
pid = run/php-fpm.pid
6. Configure www.conf file
cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default www.conf
7. Start php-fpm
#PHP-FPM(FastCGI Process Manager:FastCGI进程管理器),是一个PHPFastCGI管理器,由于Nginx服务器不能处理动态页面,需要把Nginx把动态请求交给php-fpm进程继续解析。
/usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini
netstat -anpt | grep 9000
8. Configure nginx to support PHP parsing
vim /usr/local/nginx/conf/nginx.conf
#65行;取消注释并修改
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#将/scripts修改成nginx的工作目录
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
systemctl restart nginx.service
9. Test access page
vim /usr/local/nginx/html/index.php
<?php
phpinfo();
?>
#使用浏览器访问
http://192.168.163.10/index.php
10. Verify that the database is working properly
mysql -u root -p
#创建一个数据库
CREATE DATABASE bbs;
#把bbs数据库里面所有表的权限授予给bbsuser,并设置密码010230
GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY '010230';
#刷新数据库
flush privileges;
#查看有哪些数据库
show databases;
vim /usr/local/nginx/html/index.php
<?php
$link=mysqli_connect('192.168.184.70','bbsuser','010230');
if($link)
echo "<h1>Congratulations on your success!!</h1>";
else
echo "Unfortunately, it failed!";
?>
4. Deploy Discuz! Community Forum web application
1. Unzip the installation package and give permission
cd /opt
unzip /opt/Discuz_X3.4_SC_UTF8.zip -d /opt/dis
#上传站点更新包
cd /opt/dis/dir_SC_UTF8/
cp -r upload/ /usr/local/nginx/html/bbs
cd /usr/local/nginx/html/bbs
chmod -R 777 ./config/
chmod -R 777 ./data/
chmod -R 777 ./uc_*
2. Access by browser
论坛页面访问
http://192.168.184.70/bbs/install/index.php
#填写数据库信息
数据库服务器:localhost ###本地架设就用localhost,如何不是在在本机上就要填写IP地址和端口号
数据库名字:bbs
数据库用户名:bbsuser
数据库密码:010230
管理员账号:lucien
管理员密码:010230
#结束
#论坛内部页面
http://192.168.184.70/bbs/index.php
#论坛后台管理员页面
http://192.168.184.70/bbs/admin.php