目录
1)关闭防火墙,将安装nginx所需软件包传到/opt目录下
systemctl stop firewalld
systemctl disable firewalld
setenforce 0wget https://nginx.org/download/nginx-1.22.1.tar.gz -P /opt #wget下载,-P指定下载到/opt目录
2)安装扩展包,官方源默认没有Nginx的yum源,使用yum部署Nginx需要先安装epel-release扩展包
yum install epel-release -y #安装epel-release扩展源
3)依赖包、扩展源安装完后直接安装Nginx。
yum install nginx -y #安装nginx服务
4)创建建运行用户、组(Nginx 服务程序默认以 nobody 身份运行,建议为其创建专门的用户账号,以便更准确地控制其访问权限)
useradd -M -s /sbin/nologin nginx #新建nginx用户方便管理
5)安装包下载完成后安装编译需要的依赖环境和工具,然后进入对应的目录进行解压编译
yum -y install gcc pcre-devel openssl-devel zlib-devel #安装编译安装需要的依赖包和工具
cd /opt #进入指定安装包下载的目录 /opt下
tar xf nginx-1.22.1.tar.gz #将nginx包解压到当前文件夹
cd nginx-1.22.1 #进入解压后nginx包中
#检测环境并安装功能
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_modulemake -j4 && make install #执行完成检测编译安装环境、将nginx安装包翻译为二进制和翻译完成后将包写入磁盘中
chown -R nginx.nginx /usr/local/nginx #递归设置属主属组
6)创建软连接后直接 nginx启动
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
创建Nginx 自启动文件:
#创建.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
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
7)重新加载配置、设置开机自启并开启服务
#磁盘上的ngin服务更改,运行'systemctl daemon-reload'重新加载单元。
systemctl daemon-reload #重新加载配置
systemctl start nginx #开启nginx
systemctl enable --now nginx #开机自启并立即启动
systemctl status nginx.service #查看服务状态(验证)
8)写进磁盘完成后进入部署的文件夹使用绝对路径启动nginx服务,然后查看是否有nginx进程,查看到进程就代表Nginx编译完成
/usr/local/nginx/sbin/nginx #使用绝对路径启动nginx
ps aux |grep nginx #查看是否有nginx进程
1)安装Mysql环境依赖包
yum -y install \
ncurses \
ncurses-devel \
bison \
cmake
2)创建运行用户
useradd -s /sbin/nologin mysql
3)编译安装
#切换至/opt
cd /opt/
#解压下载好的压缩包
tar -zxf mysql-boost-5.7.20.tar.gz
#切换至解压后的目录
cd 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
注释:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
#指定mysql的安装路径
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
#指定mysql进程监听套接字文件(数据库连接文件)的存储路径
-DSYSCONFDIR=/etc \
#指定配置文件的存储路径
-DSYSTEMD_PID_DIR=/usr/local/mysql \
#指定进程文件的存储路径
-DDEFAULT_CHARSET=utf8 \
#指定默认使用的字符集编码,如utf8
-DDEFAULT_COLLATION=utf8_general_ci \
#指定默认使用的字符集校对规则
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
#安装INNOBASE存储引擎
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
#安装ARCHIVE存储引擎
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
#安装BLACKHOLE存储引擎
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
#安装FEDERATED存储引擎
-DMYSQL_DATADIR=/usr/local/mysql/data \
#指定数据库文件的存储路径
-DWITH_BOOST=boost \
#指定boost的路径,
-DWITH_SYSTEMD=1
#生成便于systemctl管理的文件
#安装时间长
make -j2 && make install#数据库目录进行权限调整
chown -R mysql:mysql /usr/local/mysql/
4)修改mysql 配置文件
- #进入配置文件,把内容全删掉,然后加入以下内容
- vim /etc/my.cnf
-
- [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
-
- 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
5)更改mysql安装目录和配置文件的属主属组
chown -R mysql:mysql /usr/local/mysql/
chown mysql:mysql /etc/my.cnf
6)设置路径环境变量
echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
echo 'export PATH' >> /etc/profile
7)初始化数据库
#切换至指定目录
cd /usr/local/mysql/bin/
#初始化数据库./mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data
#能用systemd启动cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
8)检测数据库开启自启、 关闭、状态
systemctl enable mysqld #开启自启
systemctl start mysqld.service #启动服务
systemctl stop mysqld #关闭服务
systemctl status mysqld #查看状态systemctl daemon-reload #刷新识别
ss -natp | grep 3306 #查看端口
9)修改mysql 的登录密码和授权远程登录
此处可能出现输入命令mysql或mysqladmin会发现提示命令不存在
这是由于系统默认会查找/usr/bin下的命令,如果这个命令不在这个目录下,当然会找不到命令,我们需要做的就是映射一个链接到/usr/bin目录下,相当于建立一个链接文件。
首先得知道mysql命令或mysqladmin命令的完整路径,
比如mysql的路径是:/usr/local/mysql/bin/mysql,我们则可以这样执行命令:
ln -s /usr/local/mysql/bin/mysql /usr/bin
比如mysqladmin的路径是:/usr/local/mysql/bin/mysqladmin,我们则可以这样执行命令:
ln -s /usr/local/mysql/bin/mysqladmin /usr/bin
mysqladmin -u root -p password "123abc" #给root账号设置密码为123abc,提示输入的是原始密码(为空)
mysqladmin -uroot -p password "123abc"
# 命令 -u 用户 -p 旧密码(默认为空) password 新密码mysql -u root -p #授权远程登录(登入数据库验证是否成功)
quit或exit #退出数据库
1)安装环境依赖包
#安装依赖环境
#安装GD库和GD库关联程序,用来处理和生成图片
yum -y install \
libjpeg \
libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 \
libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel
将PHP源代码包放在 /opt目录下解压
tar -jxvf php-7.1.10.tar.bz2
cd /opt/php-7.1.10/
2)编译安装
#编译环境检测 功能模块添加
./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 -j2 && make install
3)路径优化
ln -s /usr/local/php/bin/* /usr/local/bin/
ln -s /usr/local/php/sbin/* /usr/local/sbin/
4)调整PHP配置文件
php有三个配置文件
php.ini 主配置文件
php-fpm.conf 进程服务配置文件
www.conf 扩展配置文件
cp /opt/php-7.1.10/php.ini-development /usr/local/php/lib/php.ini #复制
vim /usr/local/php/lib/php.ini #修改主配置文件
cd /usr/local/php/etc/
#注意格式(空格)修改第1170行和939行(去掉注释)
1170 mysqli.default_socket = /usr/local/mysql/mysql.sock
939 date.timezone = Asia/Shanghai
调整进程服务配置文件cp php-fpm.conf.default php-fpm.conf
vim php-fpm.conf
pid = run/php-fpm.pid #将这一行注释去掉(第17行)
调整扩展配置文件
cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default www.conf
5)启动php-fpm
/usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini
ss -napt | grep 9000
cd /opt/php-7.1.10/sapi/fpm
cp php-fpm.service /usr/lib/systemd/system/php-fpm.servicesystemctl restart php-fpm.service
6)配置nginx支持PHP功能
vim /apps/nginx/conf/nginx.conf
#65到71行 取消注释,修改
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /apps/nginx/html$fastcgi_script_name; #将/scripts修改为nginx的工作目录
include fastcgi_params;
}systemctl restart nginx.service #重启服务
7)验证PHP 测试页
#创建网页文件
vim /apps/nginx/html/index.php
phpinfo();
?>
#重启nginx服务
systemctl restart nginx
#在网页测试
http://192.168.47.103/index.php
1)以 root 用户身份登录到 MySQL 数据库,进行配置
mysql -u root -p #以 root 用户身份登录到 MySQL 数据库
mysql> CREATE DATABASE bbs; #创建一个数据库
mysql> GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY 'admin123'; #把bbs数据库里面所有表的权限授予给bbsuser,并设置密码
mysql>flush privileges; #刷新数据库
2)解压Discuz源码包并配置
unzip /opt/Discuz_X3.5_SC_UTF8.zip #解压
cd /opt
cd upload/
cp -r upload/ /apps/nginx/html/bbs/ #拷贝文件到数据
#改权限 改属组属主
cd /appsl/nginx/html/bbs/chown -R root:nginx ./config/
chown -R root:nginx ./data/
chown -R root:nginx ./uc_client/
chown -R root:nginx ./uc_server/chmod -R 777 ./config/
chmod -R 777 ./data/
chmod -R 777 ./uc_client/
chmod -R 777 ./uc_server/
3)安装Discuz论坛
浏览器访问
http://192.168.47.103/bbs/install/index.php
进入安装向导界面
访问论坛
访问Discuz论坛
http://192.168.47.103/bbs/index.php
- #创建数据库
- mysql -u root -p
- create database wordpress;
- grant all privileges on wordpress.* to 'wordpress'@'%' identified by '123abc';
- grant all privileges on *.* to 'root'@'%' identified by '123abc';
- flush privileges;
- quit
-
- #解压软件包
- cd /opt
- unzip wordpress-4.9.4-zh_CN.zip
-
- #授权
- mkdir /apps/nginx/html/wordpress
- cp -r wordpress/* /apps/nginx/html/wordpress
- chown -R nginx:nginx /apps/nginx/html/wordpress/
- chmod 777 wordpress/
-
- #网页访问
- 192.168.47.103/wordpress/wp-admin/setup-config.php
-
- http://192.168.47.103/wordpress/wp-admin/index.php
- //准备工作
- systemctl stop firewalld
- setenfore 0
-
- //安装 nginx
- vim /etc/yum.repos.d/nginx.repo
- [nginx-stable]
- name=nginx stable repo
- baseurl=http://nginx.org/packages/centos/7/$basearch/
- gpgcheck=0
- enabled=1
-
-
- yum install nginx -y
- nginx -v
-
- systemctl start nginx
- systemctl enable nginx
-
-
- //安装 mysql 5.7 (mariadb)
- yum remove mariadb* -y
-
- wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
- yum -y install mysql57-community-release-el7-10.noarch.rpm
- sed -i 's/gpgcheck=1/gpgcheck=0/' mysql-community.repo
- yum -y install mysql-community-server
- 或
- wget https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm
- rpm -ivh mysql57-community-release-el7-11.noarch.rpm
- sed -i 's/gpgcheck=1/gpgcheck=0/' mysql-community.repo
- yum -y install mysql-server
-
- systemctl start mysqld.service
- systemctl enable mysqld.service
-
- grep "password" /var/log/mysqld.log #在日志文件中找出root用户的初始密码
- 2021-07-31T07:55:00.366359Z 1 [Note] A temporary password is generated for root@localhost: ga7%<d<0*jD&
-
- grep "password" /var/log/mysqld.log | awk '{print $NF}'
-
- //登录 mysql
- mysql -uroot -p
- Enter password: #输入初始密码 ga7%<d<0*jD&
-
- ALTER USER 'root'@'localhost' IDENTIFIED BY 'Admin@123';
- #密码设置要求有 大小写字母、数字和符号 组合
-
- grant all privileges on *.* to root@"%" identified by "Admin@123" with grant option;
- flush privileges;
-
- yum -y remove mysql57-community-release-el7-10.noarch
- #为了防止每次yum操作都会自动更新,卸载这个软件
-
-
- //安装 php7.2
- rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
- rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
-
- yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-gd php72w-mbstring php72w-pdo php72w-xml php72w-fpm php72w-mysqlnd php72w-opcache php72w-redis
-
-
- systemctl start php-fpm
- systemctl enable php-fpm
- php -v
-
-
- //配置 nginx 支持 PHP 解析
- cd /etc/nginx/conf.d
- vim default.conf
- ......
- location ~ \.php$ {
- root html;
- fastcgi_pass 127.0.0.1:9000;
- fastcgi_index index.php;
- fastcgi_param SCRIPT_FILENAME /apps/nginx/html$fastcgi_script_name; #将 /scripts 修改为nginx的工作目录
- include fastcgi_params;
- }
-
- systemctl restart nginx
-
- cd /apps/nginx/html
- vim index.php
- <?php
- phpinfo();
- ?>
-
- 浏览器访问:http://192.168.47.103/index.php
-
-
- //测试mysql是否能连接成功
- vim /apps/nginx/html/index.php
- <?php
- $link=mysqli_connect('192.168.79.210','root','Admin@123');
- if($link) echo "
Success!!
"; - else echo "Fail!!";
- ?>
-
- 浏览器访问:http://192.168.47.103/index.php