centos7安装python3.7

1.安装环境

cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

2.安装epel网络yum源

yum -y install epel-release

3.更新yum源

yum clean all

yum makecache

4.更新rpm包

yum -y update

5.安装依赖环境

yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel zlib1g-dev zlib*

zlib1g-dev可能会报不存在,暂时忽略

6.下载python3.7

cd /usr/local/src

wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz

如果国内下载过慢或链接失效,请使用以下链接

wget -c http://itityunwei.cn/linux_package/Python-3.7.0.tar.xz

7.解压python3.7

tar -vxf  Python-3.7.0.tar.xz (注意:不要加j参数)

8.安装python3.7

mkdir -p /usr/local/python3

cd /usr/local/src/Python-3.7.0

./configure –prefix=/usr/local/python3 –enable-optimizations –with-ssl

make && make install

9.创建软连接(快捷方式)

ln -s /usr/local/python3/bin/python3 /usr/local/bin/python3

ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3

ln -s /usr/local/python3/bin/virtualenv /usr/local/bin/virtualenv  (不存在,后面创建虚拟环境用,后面会安装)

10.检查python3是否成功安装

python3  -v

pip3  -v

11.修改pip源为国内源

cd /root

mkdir .pip

cd .pip

vim pip.conf

[global]

index-url = https://mirrors.aliyun.com/pypi/simple

12.二次编译安装python3,加入with-ssl

cd /usr/local/src/Python-3.7.0

./configure  –with-ssl

make && make install

13.升级pip3并安装虚拟环境

pip3 install –upgrade pip

pip3 install virtualenvwrapper

14.编辑.bash_profile文件

cd /root

cp .bash_profile   .bash_profile.back

vim  .bash_profile

底部新增以下几行

export WORKON_HOME=/Envs
export VIRTUALENVWRAPPER_VIRTUALENV=/Users/mosson/Library/Python/3.7/bin/virtualenv
export VIRTUALENVWRAPPER_PYTHON=/usr/local/python3/bin/python3
source /usr/local/python3/bin/virtualenvwrapper.sh

生效配置文件

source  .bash_profile

15.创建虚拟环境

创建虚拟环境
[root@localhost ~]# mkvirtualenv 虚拟环境的名字
如果需要特殊指定其他版本的python
[root@localhost ~]# mkvirtualenv -p python解释器所在的位置 虚拟环境存放的目录(默认是在/Envs)
切换虚拟环境
[root@localhost ~]# workon 虚拟环境的名字
退出虚拟环境
[root@localhost ~]# deactivate
查看虚拟环境
[root@localhost ~]# lsvirtualenv

16.解决python2和python3共存问题,以方便快速切换python版本,支持多个python版本共存

cd /usr/local/bin/

mv python  python2  (注意:这里的python是指当前系统运行的python版本,默认为python2,也是系统在全局任意界面读取的python版本,我这里要让python3全局生效,以替代python2作为默认版本,所以要重命名python为python2,最好是原来什么版本的执行程序就重命名为什么版本,这个python默认是python2的执行程序,重命名为python2)

mv python3  python (注意:要让python3全局生效,需要将python3重命名为python,让系统能调用python3来执行,简单说就是想要切换什么版本就重命名就行了,当然,相关版本的启动程序需要软连接到这个目录下)

cd

python

发现python3已经作为默认启动版本了

[root@localhost ~]# python
Python 3.7.0 (default, Jan 4 2021, 17:53:08)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type “help”, “copyright”, “credits” or “license” for more information.
>>>  exit()

done !

 

LNMP架构搭建

1.编译安装nginx(1.18.0)

nginx官网:nginx.org

环境:(最小化安装)

[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)

[root@localhost ~]# systemctl is-active firewalld.service
unknown
[root@localhost ~]# getenforce
Disabled

yum源安装:

[root@localhost ~]# yum -y install epel-release

重建yum元数据:

[root@localhost ~]# yum clean all

[root@localhost ~]# yum makecache

更新软件包:

[root@localhost ~]# yum update -y

安装tab键补齐功能:

[root@localhost ~]# yum -y install vim net-tools bash-c*

[root@localhost ~]# reboot

安装nginx依赖环境:(可脚本)

yum -y install wget gcc gcc-c++ make pcre pcre-devel zlib zlib-devel openssl openssl-devel

cd /usr/local/src/

wget -c http://nginx.org/download/nginx-1.18.0.tar.gz

如果下载过慢或者链接失效,请用以下链接:

wget -c http://itityunwei.cn/linux_package/nginx-1.18.0.tar.gz

tar -zxvf nginx-1.18.0.tar.gz

cd nginx-1.18.0

mkdir -p /usr/local/nginx

./configure   –prefix=/usr/local/nginx

make && make install

环境变量配置:

[root@localhost ~]# vim /etc/profile

底部新增一行export PATH=$PATH:/usr/local/nginx/sbin/

[root@localhost ~]# source /etc/profile

启动nginx:nginx

关闭nginx:nginx -s stop

配置用systemctl来管理nginx:

[root@localhost ~]# vim /usr/lib/systemd/system/nginx.service

[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
[Install]
WantedBy=multi-user.target

启动nginx并开机自启动

[root@localhost ~]# systemctl start nginx.service
[root@localhost ~]# systemctl enable nginx.service

查看nginx运行状态

[root@localhost ~]# systemctl is-active nginx.service

[root@localhost ~]# systemctl status nginx.service

2.编译安装php(7.3.25)

php官网:php.net

安装php依赖环境:(可脚本)

yum -y install epel-release

编译安装libzip(php7要libzip版本大于0.11)

yum remove libzip

wget -c https://nih.at/libzip/libzip-1.2.0.tar.gz

tar -zxvf libzip-1.2.0.tar.gz

cd libzip-1.2.0/

./configure

make && make install

添加搜索路径到配置文件

vim /usr/local/lib64

/usr/local/lib

/usr/lib

/usr/lib64

然后 更新配置

ldconfig -v

cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h

 

安装php环境依赖:
yum -y install gcc gcc-c++ make pcre pcre-devel   zlib zlib-devel openssl openssl-devel libxml2 libxml2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel openldap openldap-devel libmcrypt libmcrypt-devel
cd /usr/local/src/
wget -c https://www.php.net/distributions/php-7.3.25.tar.gz

如果下载过慢或者链接失效,请用以下链接:

wget -c http://itityunwei.cn/linux_package/php-7.3.25.tar.gz

tar -zxvf php-7.3.25.tar.gz
cd php-7.3.25
mkdir -p /usr/local/php
./configure –prefix=/usr/local/php –with-config-file-path=/usr/local/php/etc –enable-ctype –with-mysql=mysqlnd –with-mysqli=mysqlnd –with-freetype-dir –with-jpeg-dir –with-png-dir –with-zlib –with-libxml-dir=/usr –enable-xml –disable-rpath –enable-bcmath –enable-shmop –enable-sysvsem –enable-inline-optimization –with-curl –enable-mbregex –enable-mbstring –with-mcrypt –with-gd –enable-gd-native-ttf –with-openssI –with-mhash –enable-pcntl –enable-sockets –with-ldap-sasl –with-xmlrpc –enable-zip –enable-soap –with-gettext –enable-fpm

make && make install
cp php.ini-production /usr/local/php/etc/php.ini

环境变量配置:

vim /etc/profile

export PATH=$PATH:/usr/local/php/sbin/:/usr/local/php/bin/

source /etc/profile

mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

ln -s /usr/local/php/sbin/php-fpm /usr/local/bin/

cp /usr/local/php/etc/php-fpm.d/www.conf.back /usr/local/php/etc/php-fpm.d/www.conf

systemctl管理php启动

vim /usr/lib/systemd/system/php-fpm.service

[Unit]
Description=php-fpm
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/php/sbin/php-fpm
[Install]
WantedBy=multi-user.target

启动php:

[root@localhost system]# systemctl start php-fpm.service
[root@localhost system]# systemctl enable php-fpm.service

修改nginx配置:

cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.back

vim /usr/local/nginx/conf/nginx.conf

3.编译安装mysql(5.7.32)

官网:https://www.mysql.com/

yum install -y gcc gcc-c++ make tar openssl openssl-devel cmake ncurses ncurses-devel
useradd -s /sbin/nologin mysql
cd /usr/loca/src
wget -c https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.32.tar.gz

如果下载过慢或者链接失效,请用以下链接:

wget -c http://itityunwei.cn/linux_package/mysql-boost-5.7.32.tar.gz

tar -zxvf mysql-boost-5.7.32.tar.gz
cd mysql-5.7.32

mkdir -p /usr/local/mysql

mkdir -p /data/mysql

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DENABLE_DOWNLOADS=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/mysql/boost

如果发现国内主机执行后下载boost老是中断,请按下面方法:

cd /usr/local/mysql/boost

wget -c http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz(注意加-c参数,支持断点续传)

如果下载过慢或者链接失效,请用以下链接:

wget -c http://itityunwei.cn/linux_package/boost.tar.gz

tar -zxvf boost.tar.gz

cd /usr/local/src/mysql-5.7.32

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/mysql/boost/ -DMYSQL_DATADIR=/data/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DENABLE_DOWNLOADS=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/mysql/boost

 

make && make install
cp supprt-files/mysql.server /etc/init.d/mysqld
chmod a+x /etc/init.d/mysqld

配置mysql环境变量:

vim /etc/profile

底部新增一行:export PATH=$PATH:/usr/local/mysql/bin/

更新mysql配置:

vim /etc/my.cnf

把里面的东西删除干净

[mysqld]

bind-address=127.0.0.1
port=3306
datadir=/data/mysql
user=mysql
skip-name-resolve
long_query_time=2
slow_query_log_file=/data/mysql/mysql-slow.log
expire_logs_days=2
innodb-file-per-table= 1
innodb_flush_log_at_trx_commit = 2
log_warnings = 1
max_allowed_packet = 1024M
connect_timeout = 60
net_read_timeout = 120

[mysqld_safe]
log-error=/data/mysql/mysqld.log
pid-file=/data/mysql/mysqld.pid

mysql数据库初始化:

mkdir -pv /data/mysql

chown -R mysql:mysql /usr/local/mysql/ /data/mysql/

yum -y install perl-Module-Install

cd /usr/local/mysql/bin

./mysqld –initialize-insecure –user=mysql –basedir=/usr/local/mysql –datadir=/data/mysql

使用systemctl管理mysql:

[root@localhost bin]# vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=mysqld
After=network.target
[Service]
Type=forking
ExecStart=/etc/init.d/mysqld start
[Install]
WantedBy=multi-user.target

启动mysql:

[root@localhost ~]# systemctl start mysqld.service
[root@localhost ~]# systemctl enable mysqld.service

查看mysql运行状态:

[root@localhost ~]# systemctl is-active mysqld.service

[root@localhost ~]# systemctl status mysqld.service

设置mysql的root密码:

设置mysql的root密码:
进入mysql:
mysql
设置mysql root密码:
set password for root@localhost = password(‘输入要设置的密码’);
exit
登录mysql:
mysql -uroot -p

进入数据库授权主机访问:

grant all privileges on *.* to ‘root’@’%’ identified by ‘输入上面设置的root密码’ with grant option;

flush privileges;

exit

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

elif语句

#!/bin/bash
# testing
testuser=admin
#

if grep $testuser /etc/passwd
then
    echo 这个用户存在于这个系统中
#
elif ls -d /home/$testuser/
then
    echo 这个用户不存在于这个系统中
    echo 然而这个用户有个目录
#
fi

if-then-else语句

#!/bin/bash

if ls
then 
    date
    echo 这是时间
    
    cal 
    echo 这是日历

else    #这时候else语句不执行,因为上面if语句能够被执行
    date
    echo 这是时间
    
    cal
    echo 这是日历
fi



if datxxxx
then 
     date
     echo 这是时间
  
     cal
     echo 这是日历

else  #这时候执行else语句,因为上面的if语句不能被执行
    date
    echo 这是时间
 
    cal
    echo 这是日历
fi