一、手工编译nginx服务
1.1 关闭防火墙,将安装nginx所需软件包传到/opt目录下
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
1.2 安装依赖包
yum install -y pcre-devel zlib-devel gcc gcc-c++ make #Nginx的配置及运行需要pcre、zlib等软件包的支持,因此需要安装这些安装的开发包,以便提供相应的库和头文件
1.3 创建运行用户、组
useradd -M -s /sbin/nologin nginx #Nginx服务程序默认以nobody身份运行,建议为其创建专门的用户账号,以便更准确地控制其访问权限
1.4 编译安装nginx
cd /opt
tar zxvf nginx-1.12.0.tar.gz
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的操作命令
1.5 添加 Nginx 系统服务
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 SMAINPID
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
1.6 浏览器测试
二、手工编译mysql数据库(一键部署脚本内容)
\#!/bin/bash
mount /dev/sr0 /mnt
注:mysql的软件包已经拉进opt目录中
\#安装依赖包
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
\#创建mysql用户
useradd -M -s /sbin/nologin mysql
\#修改mysql 配置文件
rm -rf /etc/my.cnf
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
auto-rehash
[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
\#更改mysql安装目录和配置文件的属主属组
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
\#添加mysqld系统服务
cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
systemctl daemon-reload
systemctl start mysqld.service
systemctl enable mysqld
soure /etc/profile
yum -y install expect
mima () {
passwd=$1
/usr/bin/expect <<-EOF
spawn mysqladmin -u root -p password $passwd
expect "Enter password:"
send "\r"
expect eof
EOF
}
mima "264196"
yc () {
/usr/bin/expect <<-EOF
spawn mysql -u root -p
expect "Enter password:" {send "264196\r"}
expect "mysql>" {send "grant all privileges on *.* to ‘root‘@‘%‘ identified by ‘264196‘;\r"}
expect "mysql>" {send "quit\r"}
expect eof
EOF
}
yc
echo -e "mysql安装完成!"
三、手工编译安装PHP
3.1 导入软件包
3.2 安装GD库和GD库关联程序,用来处理和生成图片
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.3 解压软件包
tar jxvf php-7.1.10.tar.bz2
3.4 编译安装
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 \ #相比lamp多了一个fpm模块
--enable-mbstring --enable-xml --enable-session --enable-ftp --enable-pdo --enable-tokenizer --enable-zip
make && make install
3.5 路径优化
ln -s /usr/local/php/bin/* /usr/local/bin/
ln -s /usr/local/php/sbin/* /usr/local/sbin/
3.6 调整PHP配置文件
3.6.1 php.ini主配置文件
1.cp /opt/php-7.1.10/php.ini-development /usr/local/php/lib/php.ini
2.vim /usr/local/php/lib/php.ini
3.date.timezone = Asia/Shanghai #939行;取消注释,修改
4.mysqli.default_socket = /usr/local/mysql/mysql.sock #1170行;修改
5.php -m
3.6.2 php-fpm.conf进程服务配置文件
1.cd /usr/local/php/etc/
2.cp php-fpm.conf.default php-fpm.conf
3.vim php-fpm.conf
4.pid = run/php-fpm.pid #17行;去掉注释符“;”
3.6.3 www.conf扩展配置文件
cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default www.conf
3.7 启动php-fpm
1./usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini
2.netstat -anpt | grep 9000
注:PHP-FPM(FastCGI Process Manager:FastCGI进程管理器)是一个PHPFastCGI管理器, 由于Nginx服务器不能处理动态页面,需要由 Nginx 把动态请求交给php-fpm进程进行解析
3.cd /opt/php-7.1.10/sapi/fpm
4.cp php-fpm.service /usr/lib/systemd/system/php-fpm.service
5.systemctl restart php-fpm.service #把php服务添加到系统system中
3.8 配置Nginx支持PHP解析
vim /usr/local/nginx/conf/nginx.conf
location ~ \.php$ { #65行;取消注释并修改
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name; #将/scripts修改成nginx的工作目录
include fastcgi_params;
}
systemctl restart nginx.service
3.9 测试访问页
1.vim /usr/local/nginx/html/index.php
<?php
phpinfo();
?>
2.使用浏览器访问
http://192.168.80.11/index.php
3.10 验证数据库工作是否正常
1.mysql -u root -p #登入数据库
2.CREATE DATABASE bbs; #创建一个数据库
3.GRANT all ON bbs.* TO ‘bbsuser‘@‘%‘ IDENTIFIED BY ‘264196‘; #把bbs数据库里面所有表的权限授予给bbsuser,并设置密码264196
4.flush privileges; #刷新数据库
5.show databases; #查看有哪些数据库
6.vim /usr/local/nginx/html/index.php
<?php
$link=mysqli_connect(‘192.168.80.11‘,‘bbsuser‘,‘264196‘);
if($link)
echo "<h1> success!!</h1>";
else
echo "failed!";
?>
四、部署 Discuz!社区论坛web应用
4.1 解压安装包
1.cd /opt
unzip /opt/Discuz_X3.4_SC_UTF8.zip -d /opt/dis
2.cd /opt/dis/dir_SC_UTF8/ #上传站点更新包
cp -r upload/ /usr/local/nginx/html/bbs
4.2 给予权限
cd /usr/local/nginx/html/bbs
chmod -R 777 ./config/
chmod -R 777 ./data/
chmod -R 777 ./uc_*
4.3 浏览器进行访问
1.http://192.168.80.11/bbs/install/index.php #论坛页面安装访问
2.http://192.168.80.11/bbs/index.php #论坛内部页面
3.http://192.168.80.11/bbs/admin.php #论坛后台管理员页面
4.3.1 安装论坛
4.3.2 内部页面
4.3.3 管理员页面
lnmp设置及论坛的搭建