文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

Linux安装 OpenResty、Nginx、PHP、Mysql、Redis、Lua、Node、Golang、MongoDB、Kafka等

2023-09-17 15:01

关注

文章目录

1、基础信息

2、LNMP环境搭建

2.1、准备工作

安装LNMP之前要安装EPEL,以便安装源以外的软件,如Nginx,phpMyAdmin等。

yum install epel-release -yyum 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.gzcd openresty-1.19.9.1/配置(检测环境、生成Makefile、为编译做准备)./configure编译gmake安装gmake install(这俩二选一即可,建议OpenResty)安装Nginxyum 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.rpmrpm -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 -vphp-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.soyaf.use_namespace=1yaf.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.phpphp -r "unlink('composer-setup.php');"mv composer.phar /usr/local/bin/composercomposer -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安装MySQLyum 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,(当前目录没有,请自行创建)

phpinfo();

服务器添加

vim /etc/hosts127.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 redisredis开机自启systemctl enable redis

3、Lua

3.1、安装Lua

1、在 root 目录下,下载Lua安装包curl -R -O http://www.lua.org/ftp/lua-5.4.2.tar.gz2、解压文件tar -C /usr/local -zxvf lua-5.4.2.tar.gzcd /usr/local/lua-5.4.2/3、安装luamake all test4、验证安装是否成功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.xz2、解压文件tar xvf node-v14.15.1-linux-x64.tar.xz3、创建软链接,以便可以在任意目录下使用 nodenpm 命令(类似在windows上配置全局环境变量)ln -s /root/node-v14.15.1-linux-x64/bin/node /usr/local/bin/nodeln -s /root/node-v14.15.1-linux-x64/bin/npm /usr/local/bin/npm4、依次查看node和npm信息(验证安装是否成功)node -vnpm -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=ongo 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 Repositorybaseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/5.0/x86_64/gpgcheck=1enabled=1gpgkey=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.logstorage:  dbPath: /data/mongo  journal:    enabled: trueprocessManagement:  fork: true # fork and run in background  pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile  timeZoneInfo: /usr/share/zoneinfonet:  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/mongochown -R mongod:mongod /data/mongo

常用命令

启动 mongodbsystemctl start mongod查看 mongod 状态systemctl status mongod设置开机启动systemctl enable mongod关闭 mongodsystemctl stop mongod重启systemctl restart mongod

如遇到启动失败可试

cd /tmpls -l *.sockchown 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-openjdkecho "JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")" | sudo tee -a /etc/profilesource /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.propertiesbroker.id=1log.dirs=/data/kafka-logs#外网IPlisteners=PLAINTEXT://192.168.122.82:9092#服务器IPadvertised.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=zookeeperAfter=network.target [Service]Type=simpleEnvironment="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=rootGroup=rootExecStart=/usr/local/kafka/bin/zookeeper-server-start.sh /usr/local/kafka/config/zookeeper.propertiesExecStop=/usr/local/kafka/bin/zookeeper-server-stop.shRestart=on-failureSyslogIdentifier=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=kafkaAfter=network.target zookeeper.service [Service]Type=simpleEnvironment="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=rootGroup=rootExecStart=/usr/local/kafka/bin/kafka-server-start.sh /usr/local/kafka/config/server.propertiesExecStop=/usr/local/kafka/bin/kafka-server-stop.shRestart=on-failureSyslogIdentifier=kafka [Install]WantedBy=multi-user.target# 常用命令# 重新加载配置文件systemctl daemon-reload# 设置服务开机自启systemctl enable kafka# 手动启动服务systemctl start kafka# 手动重启服务systemctl restart kafka# 手动停止服务systemctl stop kafka# 查看服务状态systemctl status kafka

来源地址:https://blog.csdn.net/Klaus_S/article/details/130821688

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     807人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     351人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     314人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     433人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     221人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-数据库
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯