@[toc]
1、基础信息
2、LNMP环境搭建
2.1、准备工作
安装LNMP之前要安装EPEL,以便安装源以外的软件,如Nginx,phpMyAdmin等。
yum install epel-release -y
yum update
2.2、OpenResty
2.2.1、安装
下载
wget https://openresty.org/download/openresty-1.19.9.1.tar.gz
安装依赖库
yum install pcre-devel openssl-devel gcc curl
解压
tar -zxvf openresty-1.19.9.1.tar.gz
cd openresty-1.19.9.1/
配置(检测环境、生成Makefile、为编译做准备)
./configure
编译
gmake
安装
gmake install
(这俩二选一即可,建议OpenResty)
安装Nginx
yum install nginx
systemctl start nginx #启动nginx
systemctl enable nginx #设置开机启动
2.2.2、启动
配置环境变量
vim /etc/profile
添加一行
export PATH=/usr/local/openresty/bin:/usr/local/openresty/nginx/sbin:$PATH
启动
nginx -c /usr/local/openresty/nginx/conf/nginx.conf
重启
nginx -s reload
测试访问
http://192.168.0.1/
nginx
启动
systemctl start nginx
停止
systemctl stop nginx
重启
systemctl restart nginx
2.3、PHP
2.3.1、安装
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
// 根据自己情况安装指定版本 如果想7.1版本就是 php71w 先search看是否存咋,在进行下面的安装
yum search php72w
安装
yum install php72w php72w-fpm php72w-cli php72w-common php72w-devel php72w-gd php72w-pdo php72w-mysql php72w-mbstring php72w-bcmath php72w-pecl-redis php72w-pecl-igbinary php72w-pecl-mongodb php72w-pecl-xdebug -y
启动
systemctl start php-fpm
停止
systemctl stop php-fpm
重启
systemctl restart php-fpm
开机自动启动
systemctl enable php-fpm
检查是否安装成功
php -v
php-fpm -v
2.3.2、配置
vim /etc/php.ini
cgi.fix_pathinfo=1 #将注释去掉,开启PHP的pathinfo伪静态功能。
date.timezone = "Asia/Shanghai" #修改时区
2.3.3、安装 Yaf
安装
pecl install yaf
添加yaf扩展
vim /etc/php.ini
extension=yaf.so
yaf.use_namespace=1
yaf.use_spl_autoload=1
重启
systemctl restart php-fpm
2.4、安装Composer
安装前请务必确保已经正确安装了 PHP。打开命令行窗口并执行 php -v 查看是否正确输出版本号。
依次执行
php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"
mv composer.phar /usr/local/bin/composer
composer -v
镜像用法
中国全量镜像
composer config -g repo.packagist composer https://packagist.phpcomposer.com
腾讯云
composer config -g repos.packagist composer https://mirrors.cloud.tencent.com/composer/
阿里云
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
2.5、Mysql
2.5.1、安装Mysql
下载mysql源安装包
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
安装mysql源
yum localinstall mysql57-community-release-el7-8.noarch.rpm -y
检查mysql源是否安装成功
yum repolist enabled | grep "mysql.*-community.*"
更新证书(可以先不执行,看是否报错,因为在我安装是有错误,提示证书问题,更新就好了)
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
安装MySQL
yum install mysql-community-server -y
查看MySQL的启动状态
systemctl status mysqld
启动
systemctl start mysqld
停止
systemctl stop mysqld
重启
systemctl restart mysqld
开机启动
systemctl enable mysqld
2.5.2、修改MySQL登陆密码
查看原始密码
grep 'temporary password' /var/log/mysqld.log
登录
mysql -uroot -p
默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。
set password for 'root'@'localhost'=password('Admin123!');
2.6、添加Nginx配置
2.6.1、修改 nginx.conf
Nginx配置引入server下面的配置文件cd /usr/local/openresty/nginx/conf
如果当面目录没有server
文件夹,请执行 mkdir server
vim nginx.conf
在尾部添加
include server/*.conf;
2.6.2、添加项目配置
cd server
,vim hello.conf
# 这个配置就不一一介绍字段意思了。
server {
listen 80;
server_name hello.com;
root "/var/www/html/hello/public";
location / {
index index.php index.html index.htm;
if (-e $request_filename) {
break;
}
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/openresty/nginx/html/50x.html;
}
location ~ \.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PHP_VALUE "open_basedir=$document_root:/tmp/:/var/www/html";
fastcgi_param HTTP_PROXY "";
include fastcgi_params;
}
}
2.6.3、测试访问
vim /var/www/html/hello/public/index.php
,(当前目录没有,请自行创建)
<?php
phpinfo();
服务器添加
vim /etc/hosts
127.0.0.1 hello.com
本地host添加
192.168.0.1 hello.com
浏览器访问 http://hello.com/
2.7、redis
2.7.1、安装redis
安装
yum install redis
启动
systemctl start redis
2.7.2、安装redis
启动
systemctl start redis
停止
systemctl stop redis
重启
systemctl restart redis
查看状态
systemctl status redis
redis开机自启
systemctl enable redis
3、Lua
3.1、安装Lua
1、在 root 目录下,下载Lua安装包
curl -R -O http://www.lua.org/ftp/lua-5.4.2.tar.gz
2、解压文件
tar -C /usr/local -zxvf lua-5.4.2.tar.gz
cd /usr/local/lua-5.4.2/
3、安装lua
make all test
4、验证安装是否成功
lua -v
4、Node
4.1、安装Node
1、在 root 目录下,下载Node.js安装包
wget https://nodejs.org/dist/v14.15.1/node-v14.15.1-linux-x64.tar.xz
2、解压文件
tar xvf node-v14.15.1-linux-x64.tar.xz
3、创建软链接,以便可以在任意目录下使用 node 和 npm 命令(类似在windows上配置全局环境变量)
ln -s /root/node-v14.15.1-linux-x64/bin/node /usr/local/bin/node
ln -s /root/node-v14.15.1-linux-x64/bin/npm /usr/local/bin/npm
4、依次查看node和npm信息(验证安装是否成功)
node -v
npm -v
5、Golang
5.1、安装Go
https://golang.google.cn/dl/
#下载
wget https://golang.google.cn/dl/go1.15.15.linux-amd64.tar.gz
#解压
tar -C /usr/local -xzf go1.15.15.linux-amd64.tar.gz
#建立软连接
ln -s /usr/local/go/bin/* /usr/bin/
#设置环境变量
vim ~/.bashrc
#在文件末尾插入下面2行,保存退出
export GOPATH="$HOME/go"
export PATH="$PATH:/usr/local/go/bin:$GOPATH/bin"
#使配置文件生效
source ~/.bashrc
测试是否安装成功
go version
查看环境变量
go env
#设置 MODULE & GOPROXY 代理
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
6、安装mongodb
配置源:vi /etc/yum.repos.d/mongodb-org-5.0.repo
[mongodb-org-5.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/5.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-5.0.asc
安装mongodb :yum install -y mongodb-org
修改一些配置:vi /etc/mongod.conf
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
storage:
dbPath: /data/mongo
journal:
enabled: true
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
timeZoneInfo: /usr/share/zoneinfo
net:
port: 27017
#port: 7540
#bindIp: 127.0.0.1 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
bindIp: 0.0.0.0 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
创建数据文件
mkdir /data/mongo
chown -R mongod:mongod /data/mongo
常用命令
启动 mongodb
systemctl start mongod
查看 mongod 状态
systemctl status mongod
设置开机启动
systemctl enable mongod
关闭 mongod
systemctl stop mongod
重启
systemctl restart mongod
如遇到启动失败可试
cd /tmp
ls -l *.sock
chown mongod:mongod mongodb-27017.sock
一些基础命令
查询所有库
show dbs
使用这个库
use admin
查询用户
show users
查询所有表
show collections
注意:game表示表名称,根据情况更改
查询数据
db.game.find()
单条插入
db.game.insertOne({name:"monster hunter: rise",orderDate:new Date(),price:298})
{
"acknowledged" : true,
"insertedId" : ObjectId("62ba565711721fa1455eb949")
}
多条插入
db.game.insertMany([{name:"bayonetta",company:"nintendo",price:318},{name:"nier replicant",company:"square enix",price:180},{name:"the king of fighters xiii",company:"snk corporation",price:28}])
{
"acknowledged" : true,
"insertedIds" : [
ObjectId("62ba596511721fa1455eb94a"),
ObjectId("62ba596511721fa1455eb94b"),
ObjectId("62ba596511721fa1455eb94c")
]
}
删除文档
db.game.deleteOne({name:"fifa 22"})
更新文档
db.game.updateOne({_id:1},{$set:{company:"capcon"}})
7、安装kafka
安装配置Java
yum -y install java-1.8.0-openjdk
echo "JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")" | sudo tee -a /etc/profile
source /etc/profile
安装kafka
#下载
wget https://downloads.apache.org/kafka/3.2.3/kafka_2.12-3.2.3.tgz
#解压
tar zxf kafka_2.12-3.2.3.tgz -C /usr/local/
#重命名
mv kafka_2.12-3.2.3 kafka
#修改配置
vi config/server.properties
broker.id=1
log.dirs=/data/kafka-logs
#外网IP
listeners=PLAINTEXT://192.168.122.82:9092
#服务器IP
advertised.listeners=PLAINTEXT://10.16.174.6:9092
测试服务器消费监听:./bin/kafka-console-consumer.sh --bootstrap-server 192.168.122.82:9092 --topic winlogbeat
-----测试一下-------
cd /opt/kafka
#启动zookeeper
./bin/zookeeper-server-start.sh ./config/zookeeper.properties
#启动kafka
./bin/kafka-server-start.sh ./config/server.properties
#创建Topic
./bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic winlogbeat
#查看主题详情
./bin/kafka-topics.sh --bootstrap-server localhost:9092 --describe --topic winlogbeat
#消息提供者
./bin/kafka-console-producer.sh --broker-list localhost:9092 --topic winlogbeat
#消息消费者
./bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic winlogbeat
-----开机自启动 zookeeper-------
vim /etc/systemd/system/zookeeper.service
[Unit]
Description=zookeeper
After=network.target
[Service]
Type=simple
Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.362.b08-1.el7_9.x86_64/jre/bin"
User=root
Group=root
ExecStart=/usr/local/kafka/bin/zookeeper-server-start.sh /usr/local/kafka/config/zookeeper.properties
ExecStop=/usr/local/kafka/bin/zookeeper-server-stop.sh
Restart=on-failure
SyslogIdentifier=zookeeper
[Install]
WantedBy=multi-user.target
# 常用命令
# 重新加载配置文件
systemctl daemon-reload
# 设置服务开机自启
systemctl enable zookeeper
# 手动启动服务
systemctl start zookeeper
# 手动重启服务
systemctl restart zookeeper
# 手动停止服务
systemctl stop zookeeper
# 查看服务状态
systemctl status zookeeper
-----开机自启动 kafka-------
vim /etc/systemd/system/kafka.service
[Unit]
Description=kafka
After=network.target zookeeper.service
[Service]
Type=simple
Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.362.b08-1.el7_9.x86_64/jre/bin"
User=root
Group=root
ExecStart=/usr/local/kafka/bin/kafka-server-start.sh /usr/local/kafka/config/server.properties
ExecStop=/usr/local/kafka/bin/kafka-server-stop.sh
Restart=on-failure
SyslogIdentifier=kafka
[Install]
WantedBy=multi-user.target
# 常用命令
# 重新加载配置文件
systemctl daemon-reload
# 设置服务开机自启
systemctl enable kafka
# 手动启动服务
systemctl start kafka
# 手动重启服务
systemctl restart kafka
# 手动停止服务
systemctl stop kafka
# 查看服务状态
systemctl status kafka