经典互联网架构 (2)

[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=http://www.likecs.com/opt/mysql/bin/mysqld --defaults-file=http://www.likecs.com/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 =
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;
}
}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zwdsjx.html