安装python3、Redis、mongoDB

安装的软件包若有bin文件,说明它是一个二进制文件,它已经被编译成功了,可以直接使用。若有source文件,说明是源码包,需要编译。Linux中就这两种包

源码包的优点:开源,可以修改源码

                         可以自由选择需要的功能

                          软件是编译安装,可以更加适合自己的系统,更稳定,效率更高

                          卸载方便

源码包的缺点:安装步骤多,在安装大软件集合时,容易出现拼写错误

                           . / configure -prefix = / usr /local / python

                             Make && make install

                           安装时间比二进制包的时间长

                           因为是编译,安装报错难以解决

[root@es_005 ~]#  yum list | grep python3

[root@es_005 ~]#  rz -E                 // 下载源码(python3.12.4官网)tgz

[root@es_005 ~]#  ls

[root@es_005 ~]#  tar -zxvf Python-3.12.4.tgz             // 解压软件包

[root@es_005 ~]#  ls            // 在解压后的目录中找到configure可执行文件

[root@es_005 ~]#  cd Python-3.12.4/                    // 进入目录,运行make,编译编码

[root@es_005 Python-3.12.4]# ls

[root@es_005 Python-3.12.4]# ./configure -prefix=/usr/local/python3124           // 欧洲安装路径:/root/python312.4/configure -prefix = /usr/local/python3214

[root@es_005 Python-3.12.4]# ls

[root@es_005 Python-3.12.4]# make

[root@es_005 Python-3.12.4]# make install

[root@es_005 Python-3.12.4]# yum -y install gcc

[root@es_005 Python-3.12.4]# ls

[root@es_005 Python-3.12.4]# ls /usr/local/

[root@es_005 Python-3.12.4]# cd /usr/local/

[root@es_005 local]# cd python3124/bin/

[root@es_005 bin]# ls

[root@es_005 bin]# ./python3.12

Python 3.12.4 (main, Jul 10 2024, 09:59:17) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux

Type "help", "copyright", "credits" or "license" for more information.

>>> quit()

二进制包,直接运行

[root@es_005 bin]# vim /etc/profile

[root@es_005 bin]# cat /etc/profile | tail -1

export PATH=/usr/local/python3124/bin/:$PATH

[root@es_005 bin]# source /etc/profile

[root@es_005 bin]# python3.12

Python 3.12.4 (main, Jul 10 2024, 09:59:17) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux

Type "help", "copyright", "credits" or "license" for more information.

>>> quit()

网络配置

[root@es_005 ~]# ifconfig ens36        // 命令:ifconfig  网卡名 —— 查看指定网络接口信息

ens36: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.119.88  netmask 255.255.255.0  broadcast 192.168.119.255

        inet6 fe80::fe78:a216:3aa2:fcfb  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:e6:54:b5  txqueuelen 1000  (Ethernet)

// 设置网络接口的IP地址,子网掩码

[root@es_005 ~]# ifconfig ens36 192.168.119.77 netmask  255.255.255.0

[root@es_005 ~]# ifconfig ens36

ens36: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.119.77  netmask 255.255.255.0  broadcast 192.168.119.255

        inet6 fe80::fe78:a216:3aa2:fcfb  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:e6:54:b5  txqueuelen 1000  (Ethernet)

// ifconfig 网络接口 ip地址 【/子网掩码长度 】   

[root@es_005 ~]# ifconfig ens36 192.168.119.66/24

[root@es_005 ~]# ifconfig ens36

ens36: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.119.66  netmask 255.255.255.0  broadcast 192.168.119.255

        inet6 fe80::fe78:a216:3aa2:fcfb  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:e6:54:b5  txqueuelen 1000  (Ethernet)

[root@es_005 ~]# ifconfig ens36 down               // 禁用或重新激活网卡

[root@es_005 ~]# ifconfig ens36

ens36: flags=4098<BROADCAST,MULTICAST>  mtu 1500

        ether 00:0c:29:e6:54:b5  txqueuelen 1000  (Ethernet)

      

[root@es_005 ~]# ifconfig ens36 up

[root@es_005 ~]# ifconfig ens36

ens36: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.119.88  netmask 255.255.255.0  broadcast 192.168.119.255

        inet6 fe80::fe78:a216:3aa2:fcfb  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:e6:54:b5  txqueuelen 1000  (Ethernet)              

[root@es_005 ~]# ifdown ens36          // ifdown ens37彻底禁止网卡,临时网卡地址不存在    

成功断开设备 'ens36'。

[root@es_005 ~]# ifconfig ens36

ens36: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        ether 00:0c:29:e6:54:b5  txqueuelen 1000  (Ethernet)

[root@es_005 ~]# ifup ens36                               // ifup启动网卡以后需要重启

连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/6)

[root@es_005 ~]# ifconfig ens36

ens36: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.119.88  netmask 255.255.255.0  broadcast 192.168.119.255

        inet6 fe80::fe78:a216:3aa2:fcfb  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:e6:54:b5  txqueuelen 1000  (Ethernet)

        RX packets 1481  bytes 90141 (88.0 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 52  bytes 3868 (3.7 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@es_005 ~]#  ifconfig ens33:1 192.168.119.149

[root@es_005 ~]# ifconfig ens33:1

ens33:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.119.149  netmask 255.255.255.0  broadcast 192.168.119.255

        ether 00:0c:29:e6:54:ab  txqueuelen 1000  (Ethernet)

[root@es_005 ~]# hostname -I             // 查看本主机IP

192.168.119.55

[root@es_005 ~]# hostnamectl set-hostname shark             // 永久修改主机名称

[root@es_005 ~]# hostname

shark

[root@es_005 ~]# vim /etc/hostname                // 修改配置文件

[root@es_005 ~]# cat /etc/hostname

Shark

安装和运行Redis,并且会简单的增删改查

[root@es_005 ~]# rz -E

rz waiting to receive.

[root@es_005 ~]# ls

anaconda-ks.cfg                  Python-3.12.4.tgz                  apache-tomcat-10.1.25.tar.gz   

redis-6.2.14.tar.gz                 elasticsearch-7.17.8-x86_64.rpm  todolist.jar               

Python-3.12.4                  jdk-22_linux-x64_bin.tar.gz 

[root@es_005 ~]# tar -zxvf redis-6.2.14.tar.gz

[root@es_005 ~]# cd redis-6.2.14/

[root@es_005 redis-6.2.14]#   ls

[root@es_005 redis-6.2.14]# make && make install

[root@es_005 redis-6.2.14]# redis-server

安装MongoDB(非关系型数据库:一条数据就是一个文档)

Nosql

非关系型数据库将所有数据保存在内存里面,更快

关系型数据库将数据保存在磁盘里面

启动方式,端口,logo

[root@es_002 ~]# mkdir /usr/local/mongodb

[root@es_002 ~]# rz -E

rz waiting to receive.

[root@es_002 ~]# tar -zxf mongodb-linux-x86_64-rhel70-3.6.3.tgz

[root@es_002 ~]# ls

anaconda-ks.cfg

elasticsearch-7.17.8-x86_64.rpm

mongodb-linux-x86_64-rhel70-3.6.3

mongodb-linux-x86_64-rhel70-3.6.3.tgz

[root@es_002 ~]# ls mongodb-linux-x86_64-rhel70-3.6.3

bin  GNU-AGPL-3.0  MPL-2  README  THIRD-PARTY-NOTICES

[root@es_002 ~]# ls mongodb-linux-x86_64-rhel70-3.6.3/bin/

bsondump         mongodump    mongoperf     mongostat

install_compass  mongoexport  mongoreplay   mongotop

mongo            mongofiles   mongorestore

mongod           mongoimport  mongos

[root@es_002 ~]# cp -r mongodb-linux-x86_64-rhel70-3.6.3/bin/ /usr/local/mongodb/

[root@es_002 ~]# cd /usr/local/mongodb/

[root@es_002 mongodb]# ls

bin

[root@es_002 mongodb]# mkdir etc

[root@es_002 mongodb]# mkdir log

[root@es_002 mongodb]# mkdir -p data/db

[root@es_002 mongodb]# vim /usr/local/mongodb/etc/mongodb.conf

[root@es_002 mongodb]# cat /usr/local/mongodb/etc/mongodb.conf

dbpath=/usr/local/mongodb/data/db

logpath=/usr/local/mongodb/log/mongodb.log

logappend=true

fork=true

bind_ip=192.168.119.22

[root@es_002 mongodb]# ps -C mongod

   PID TTY          TIME CMD

  1677 ?        00:00:10 mongod

[root@es_002 mongodb]# netstat -utnalp | grep 27017

tcp        0      0 192.168.119.22:27017    0.0.0.0:*               LISTEN      1677/mongod        

tcp        0      0 192.168.119.22:49716    192.168.119.22:27017    TIME_WAIT   -   

[root@es_002 mongodb]# PATH=/usr/local/mongodb/bin:$PATH

[root@es_002 mongodb]# echo "PATH=/usr/local/mongodb/bin:$PATH" >> /etc/profile

[root@es_002 mongodb]# source /etc/profile

[root@es_002 mongodb]# echo $PATH

/usr/local/mongodb/bin:/usr/local/mongodb/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

[root@es_002 mongodb]# mongod -f /usr/local/mongodb/etc/mongodb.conf

about to fork child process, waiting until server is ready for connections.

forked process: 1677

child process started successfully, parent exiting

[root@es_002 mongodb]# mongo --host 192.168.119.22 --port 27017

MongoDB shell version v3.6.3

connecting to: mongodb://192.168.119.22:27017/

MongoDB server version: 3.6.3

Welcome to the MongoDB shell.

> db

test

> show  dbs

admin  0.000GB

local  0.000GB

> use t1

switched to db t1

> exit

bye

  • 9
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Python可以使用redis-py库和pymongo库来操作RedisMongoDB。 要使用Redis作为缓存,可以使用redis-py库。首先需要安装redis-py库,然后在Python代码中导入redis模块。接下来,可以使用redis模块的相关方法来与Redis进行交互。例如,可以使用set方法将数据缓存到Redis中,使用get方法从Redis中获取数据。此外,还可以使用expire方法为缓存设置过期时间,使用delete方法从Redis中删除缓存等。 要使用MongoDB作为主数据库,可以使用pymongo库。首先需要安装pymongo库,然后在Python代码中导入pymongo模块。接下来,可以使用pymongo模块的相关方法来与MongoDB进行交互。例如,可以使用insert_one或insert_many方法将数据插入到MongoDB中,使用find方法查询数据,使用update_one或update_many方法更新数据,使用delete_one或delete_many方法删除数据等。 在使用RedisMongoDB的组合方式中,可以将经常被访问的数据缓存到Redis中,从而提高访问速度。当需要获取数据时,首先尝试从Redis中获取,如果不存在则从MongoDB中获取,并将获取的数据缓存到Redis中。同时,还可以通过设置合适的过期时间,以保证缓存的数据不会过时。 需要注意的是,在将数据缓存到Redis中时,应该根据实际需求选择适当的数据结构(如字符串、哈希、列表、有序集合等),以满足不同的缓存需求。在使用MongoDB作为主数据库时,需要根据实际情况设计合理的数据模型和索引,以支持高效的数据存储和查询操作。 总之,通过使用Python操作redismongodb,结合redis作为缓存,mongodb作为主数据库,可以提高数据的读写效率和性能,并实现灵活可扩展的数据存储方案。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值