码迷,mamicode.com
首页 > 系统相关 > 详细

Linux之经典互联网架构

时间:2019-01-14 00:22:02      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:name   exp   pos   数据   自带   php-fpm   iss   mission   rdp   


经典互联网架构

netstat -tulnp |grep 80
ss -tulnp|grep 80


前期铺垫:

1. Linux要能上网
2. 掌握Linux软件包安装方法
2.1 rpm包管理
2.1.1 光盘挂载
mount /dev/cdrom /mnt
cd /mnt
ls
2.1.2 安装rpm包
rpm -ivh vsftpd-3.0.2-22.el7.x86_64.rpm
rpm -Uvh vsftpd-3.0.2-22.el7.x86_64.rpm
2.13 卸载rpm
rpm -e vsftpd-3.0.2-22.el7.x86_64

2.1.4 rpm包的查询
[root@python3 ~]# rpm -q vsftpd
vsftpd-3.0.2-22.el7.x86_64
[root@python3 ~]# rpm -q vsftp
package vsftp is not installed
[root@python3 ~]#
[root@python3 ~]# rpm -qa |grep vsf
[root@python3 ~]# which vim
/usr/bin/vim
[root@python3 ~]# rpm -qf /usr/bin/vim

**2.1.5 额外补充

A ----> B ---> C

A BC B DF F AC

rpm -ivh a b c d e f


2.2 yum 使用
2.2.1 使用aliyun yum站点源
Base源
cd /etc/yum.repos.d/
mv *.repo /tmp
wget http://mirrors.aliyun.com/repo/Centos-7.repo

EPEL源
yum install -y epel-release

2.2.2 使用yum安装软件
yum install -y openssl openssl-devel

2.2.3 软件包查询及组安装
yum list |grep vsftpd
yum grouplist
yum groupinstall "Development Tools"

2.2.4 卸载软件包
yum remove

 

2.2.5 优化yum源
(1)本地镜像yum源(光盘挂载到/mnt下)
[local]
name=localios
baseurl=file:///mnt
gpgcheck=0

yum clean all
yum install -y vsftpd

(2)局域网yum源(ftp)
1.安装ftp软件
yum install -y vsftpd
2.启动ftp服务
[root@python3 ~]# systemctl start vsftpd
[root@python3 ~]# systemctl enable vsftpd

3.创建站点目录,并将光盘软件拷贝其中
[root@python3 ~]# cp -a /mnt/* /var/ftp/pub/centos7

4.生成ftp站点的yum源配置文件
[ftp]
name=centos7
baseurl=ftp://10.0.0.100/pub/centos7
gpgcheck=0


5.安装软件测试
yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel gcc gcc-c++ openssl-devel zlib zlib-devel -y


2.3 源码包应用

2.3.1 解压
.zip
unzip xxx.zip
.tar
.tar.gz
.tgz
.tar.bz2
.tar.xz
tar xf xxx.tar
.iso
mount -o loop xxx.iso /test
.cpio
cpio -idcmv < xxx.cpio

2.3.2 源码包安装
(1)python3.6源码包安装
./configure ------> 定制功能
make
make install

mysql 源码包
cmake
make
make install

(2) redis 源码包安装
make

修改环境变量
vim /etc/profile

添加以下一行:
export PATH=/opt/redis-3.2.10/src:$PATH

生效配置
source /etc/profile


(3) 让python链接redis

unzip redis-py-master.zip
cd redis-py-master
python3 setup.py install


对redis的单实例进行连接操作
python3
>>>import redis
>>>r = redis.StrictRedis(host=‘localhost‘, port=6379)
>>>r.set(‘name‘, ‘oldguo‘)
True
>>>r.get(‘name‘)
‘oldguo‘


3. 二进制包(mysql5.7.20)

3.1 解压及制作软连接
tar xf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
ln -s mysql-5.7.20-linux-glibc2.12-x86_64 mysql

3.2 编辑环境变量
vim /etc/profile
添加以下一行:
export PATH=/opt/mysql/bin:$PATH

生效配置:
source /etc/profile

3.3 卸载自带mariadb
yum remove mariadb-libs

3.4 生成配置文件(/etc/my.cnf)
vim /etc/my.cnf
[mysqld]
basedir=/opt/mysql
datadir=/opt/mysql/data
socket=/tmp/mysql.sock
user=mysql
log_error=/var/log/mysql.log
log_bin=/opt/mysql/data/mysql-bin
server_id=100
[mysql]
socket=/tmp/mysql.sock

3.5 创建用户和数据目录,并授权
useradd mysql
mkdir /opt/mysql/data
chown -R mysql.mysql /opt/mysql


3.6 初始化数据

[root@python3 ~]# mysqld --initialize-insecure --basedir=/opt/mysql --datadir=/opt/mysql/data --user=mysql
2019-01-04T03:58:03.128958Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-01-04T03:58:03.142436Z 0 [ERROR] Could not open file ‘/var/log/mysql.log‘ for error logging: Permission denied
2019-01-04T03:58:03.142492Z 0 [ERROR] Aborting

报错解决:
touch /var/log/mysql.log
chown -R mysql.mysql /var/log/mysql.log


再次初始化:
mysqld --initialize-insecure --basedir=/opt/mysql --datadir=/opt/mysql/data --user=mysql


3.7 启动mysql
cd /opt/mysql/support-files
./mysql.server start

cp mysql.server /etc/init.d/mysqld

/etc/init.d/mysqld restart


扩展:使用systemctl 管理mysql
vim /etc/systemd/system/mysqld.service

[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/opt/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000


systemctl restart mysqld

netstat -tulnp |grep 3306


3.8 测试python3链接mysql

创建mysql链接用户

grant all on *.* to root@‘10.0.0.%‘ identified by ‘123‘;
create database bbs charset utf8;

python代码测试:

pip3 install --upgrade pip
pip3 install pymysql

vim testmysql.py
#!/usr/bin/python3
import pymysql
db = pymysql.connect("10.0.0.100","root","123","bbs" )
cursor.execute("SELECT VERSION()")
data = cursor.fetchone()
print ("Database version : %s " % data)
db.close()

python3 testmysql.py

 

4.经典互联网架构项目(LNMP)

LNMPT = Linux Nginx MySQL PHP
LNMPJ = Linux Nginx MySQL PHP


LNMP架构环境部署
1) 使用官方Nginx yum源

[root@nginx ~]# vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

#安装Nginx
[root@nginx ~]# yum install nginx -y
2) 启动Nginx,并将Nginx加入开机自启

systemctl start nginx
systemctl enable nginx
3) 使用第三方扩展源安装php7.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

[root@nginx ~]# yum remove php-mysql-5.4 php php-fpm php-common
[root@nginx ~]# vim /etc/yum.repos.d/php.repo
[php]
name = php Repository
baseurl = http://us-east.repo.webtatic.com/yum/el7/x86_64/
gpgcheck = 0

[root@nginx ~]# yum -y install php71w php71w-cli php71w-common php71w-devel php71w-embedded php71w-gd php71w-mcrypt php71w-mbstring php71w-pdo php71w-xml php71w-fpm php71w-mysqlnd php71w-opcache php71w-pecl-memcached php71w-pecl-redis php71w-pecl-mongodb
3) 配置php-fpm用户与Nginx的运行用户保持一致

[root@nginx ~]# sed -i ‘/^user/c user = www‘ /etc/php-fpm.d/www.conf
[root@nginx ~]# sed -i ‘/^group/c group = www‘ /etc/php-fpm.d/www.conf
4) 启动php-fpm,并将其加入开机自启

[root@nginx ~]# systemctl start php-fpm
[root@nginx ~]# systemctl enable php-fpm
5) 安装mysql数据库

[root@nginx ~]# mysqladmin password ‘123‘
[root@nginx ~]# mysql -uroot -p123
2.LNMP架构环境配置


vim /etc/nginx/conf.d/php.conf
server {
server_name 10.0.0.12;
listen 80;
root /code/wordpress;
index index.php index.html;

location ~ \.php$ {
root /code/bbs;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

 

 

 

 


LNMuWSGI+redis

 

Linux之经典互联网架构

标签:name   exp   pos   数据   自带   php-fpm   iss   mission   rdp   

原文地址:https://www.cnblogs.com/yuanxiaohui/p/10264633.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!