centos下推荐使用yum包管理器来安装软件
先进行Mysql5.7安装
1.下载 MySQL yum包
wget http://repo.mysql.com/mysql57-community-release-el7-10.noarch.rpm
2.安装MySQL源
rpm -Uvh mysql57-community-release-el7-10.noarch.rpm
3.安装MySQL服务端,需要等待一些时间
yum install -y mysql-community-server
4.启动MySQL
systemctl start mysqld.service
# 或
systemctl start mysqld
5.检查是否启动成功
systemctl status mysqld.service
6.获取临时密码,MySQL5.7为root用户随机生成了一个密码
grep 'temporary password' /var/log/mysqld.log
7.通过临时密码登录MySQL,进行修改密码操作
mysql -uroot -p
使用临时密码登录后,不能进行其他的操作,否则会报错,这时候我们进行修改密码操作
set global validate_password_policy=0;
set global validate_password_length=1;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;
quit
8.修改配置文件 /etc/my.cnf
,在 [mysqld]
段中添加
sql_mode=NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER
ngram_token_size=2
9.开启开机自启动
systemctl enable mysqld
systemctl daemon-reload
10.重新启动mysql
systemctl restart mysqld.service
相关命令
systemctl start|stop|status|restart mysqld.service
安装企业级linux扩展源epel
yum install -y epel-release
yum install -y yum-utils
Nginx安装
1.安装命令
yum install -y gcc-c++ pcre pcre-develzlib zlib-developenssl openssl-devel
cd /usr/local/src
wget https://nginx.org/download/nginx-1.20.0.tar.gz
tar zxvf nginx-1.20.0.tar.gz
cd nginx-1.20.0
./configure --prefix=/usr/local/nginx --with-http_ssl_module
make && make install
cd /usr/local/nginx/sbin
./nginx
创建配置文件目录
mkdir -p /etc/nginx/conf.d
mkdir /var/log/nginx/
cp -rf /usr/local/nginx/conf/* /etc/nginx/
修改主nginx配置文件
/etc/nginx/nginx.conf
内容替换为
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http
{
include mime.types;
default_type application/octet-stream;
charset utf-8;
server_tokens off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 60;
client_header_timeout 10;
client_body_timeout 10;
client_header_buffer_size 4k;
server_names_hash_bucket_size 128;
large_client_header_buffers 4 32k;
client_max_body_size 100m;
send_timeout 10;
reset_timedout_connection on;
open_file_cache max=102400 inactive=20s;
open_file_cache_min_uses 1;
open_file_cache_valid 30s;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
gzip off;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_vary on;
gzip_comp_level 2;
gzip_disable "MSIE [1-6]\.";
gzip_proxied any;
gzip_types text/plain application/x-javascript text/css application/xml;
access_log /var/log/nginx/access.log ;
include conf.d/*.conf;
}
启动nginx
/usr/local/nginx/sbin/nginx -c /etc/nginx/nginx.conf
相关命令
nginx -s stop :快速关闭Nginx,可能不保存相关信息,并迅速终止web服务。
nginx -s quit :平稳关闭Nginx,保存相关信息,有安排的结束web服务。
nginx -s reload :因改变了Nginx相关配置,需要重新加载配置而重载。
nginx -s reopen :重新打开日志文件。
nginx -c filename :为 Nginx 指定一个配置文件,来代替缺省的。
nginx -t :不运行,而仅仅测试配置文件。nginx将检查配置文件的语法的正确性,并尝试打开配置文件中所引用到的 文件。
nginx -v:显示 nginx 的版本。
nginx -V:显示 nginx 的版本,编译器版本和配置参数
Redis安装
1.安装命令
yum install -y redis
2.修改配置文件
vi /etc/redis.conf
PS:简单的单机部署只需要把daemonize改为yes即可,更多的配置项请查阅/etc/redis.conf文件
3.启动redis
systemctl start redis
4.测试redis
redis-cli
5.相关命令
systemctl start|stop|status|restart redis
PHP安装
安装php remi源
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum-config-manager --enable remi-php74
yum update
1.安装cmake
cd /usr/local/src
yum remove -y cmake
yum install -y gcc gcc-c++
yum install -y openssl-devel bzip2 bzip2-devel
wget https://github.com/Kitware/CMake/releases/download/v3.21.0/cmake-3.21.0.tar.gz \
&& tar -zxf cmake-3.21.0.tar.gz \
&& cd cmake-3.21.0 \
&& ./bootstrap && make && make install
然后修改 vi /etc/profile,并加入如下内容
PATH=/usr/local/bin:$PATH
export PATH
再执行
source /etc/profile
升级 安装libzip-1.7
cd /usr/local/src
wget https://libzip.org/download/libzip-1.7.3.tar.gz \
&& tar -zxf libzip-1.7.3.tar.gz \
&& cd libzip-1.7.3
mkdir -p build && cd build \
&& cmake -DCMAKE_INSTALL_PREFIX=/usr .. \
&& make \
&& make install
2.安装php7.4并启动php-fpm
cd /usr/local/src
yum install -y php php-cli php-fpm
yum install -y php-zip php-mysqlnd php-mysql php-mysqli php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json
yum install -y php-pecl-redis php-pecl-swoole
systemctl start php-fpm.service
systemctl enable php-fpm
systemctl daemon-reload
3.php的配置文件和目录
/etc/php.ini
/etc/php.d/*
/etc/php-fpm.ini
/etc/php-fpm.d/*
4.相关命令
systemctl start|stop|status|restart php-fpm
测试lnmpr
1.新建nginx虚拟目录配置文件:vi /etc/nginx/conf.d/test-lnmpr.conf
server {
listen 8080;
server_name localhost;
charset UTF-8;
location / {
root /var/webroot;
index index.php index.html index.htm;
}
location ~ \.php$ {
root /var/webroot;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/webroot/$fastcgi_script_name;
include fastcgi_params;
}
}
2.新建php测试文件:
mkdir /var/webroot/
vi /var/webroot/index.php
内容
<?php
phpinfo();
3.重新启动nginx和php-fpm
FAQ
1.如果出现 Connecting to localhost (localhost)|::1|:8080... failed: No route to host.
则表明nginx重启失败,
可 执行 ps aux |grep nginx
查看进程号然后执行 kill -9 进程号
,再启动 nginx systemctl start nginx.service
2.出现http访问nginx访问不了的情况,请查看下防火墙设置
- 关闭firewall:
systemctl stop firewalld.service #停止firewall systemctl disable firewalld.service #禁止firewall开机启动 firewall-cmd --state #查看默认防火墙状态