#
lamp综合小实验禁止转载,禁止搬运
遇到的问题:
一、浏览器打不开blog.jd.com:已经配置DNS,最终原因:这个图形化的CentOS7使用dncp获取的ip,DNS也获取的网关;解决:固定IP,手动设置DNS,并确认/etc/reslov.conf
二、NFS权限问题php对NFS目录没有写权限:最终解决:php是以apache运行的,NFS那边也创建个一模一样的apache并对/data/wordpress设置acl权限
三、nfs客户端报错:原因:手动删除了NFS服务端的共享目录;解决:客户端强制卸载NFS重新挂即可,或者杀进程
| 服务器名 | IP | 系统 | | ------------------------- | ---------------- | ------- | | User(带图形化的CentOS7) | 192.168.38.148 | CentOS7 | | powerdns | 192.168.38.147 | CentOS7 | | nginx-lb | 192.168.38.145 | CentOS7 | | LAP1/2 | 192.168.38.136/8 | CentOS7 | | NFS | 192.168.38.138 | CentOS7 | | MySQL-master | 192.168.38.139 | CentOS7 | | MySQL-slave | 192.168.38.140 | CentOS7 |
一、powerdns
参见powerdns
lamp环境+powerdns,该调优的调优
yum install httpd -y# 不然启动很慢sed '/#ServerName www.example.com/a ServerName www.example.com:80' /etc/httpd/conf/httpd.conf -i systemctl start httpd && systemctl enable httpd
rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-2.noarch.rpm yum install yum-utils -y sudo yum-config-manager --disable mysql80-community sudo yum-config-manager --enable mysql57-community yum makecache yum install mysql-community-server -y cat > /etc/my.cnf <<EOF [mysqld] socket=/var/lib/mysql/mysql.sock datadir=/data/mysqllog-bin server-id=1 expire-logs-days=15 binlog-format=row symbolic-links=0log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid EOF DB_PASSWORD=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 24` mkdir /data/mysql -p mysqld --initialize --datadir=/data/mysql --user=mysql systemctl start mysqld && systemctl enable mysqld mysqladmin -uroot -p$(grep " temporary password" /var/log/mysqld.log | awk '{print $NF}') password ${DB_PASSWORD}
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo yum install https://mirrors.huaweicloud.com/remi/enterprise/remi-release-7.rpm -y yum install php73-php php73-php-mysqlnd php73-php-fpm php73-php-xml php73-php-bcmath php73-php-mbstring php73-php-xmlrpc php73-php-soap php73-php-common php73-php-devel php73-php-gd php73-php-pecl-mcrypt php73-php-pecl-memcache php73-php-pecl-memcached php73-php-opcache -y systemctl start php73-php-fpm && systemctl enable php73-php-fpm
#创建powerdns数据库和授权用户DB_POWERDNS_PASSWORD=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 24` mysql -uroot -p${DB_PASSWORD} -e "create user powerdns@'localhost' identified by '${DB_POWERDNS_PASSWORD}';create database powerdns character set utf8 collate utf8_bin;grant all privileges on powerdns.* to powerdns@'localhost';flush privileges;"mysql -uroot -p${DB_PASSWORD} -e "alter database powerdns default CHARACTER SET latin1;"#创建完成后确认下该用户能否连接数据库
#导入表结构#表结构语句:https://doc.powerdns.com/md/authoritative/backend-generic-mysql/#default-schemamysql> source pdn.sql
#yum安装pdns(可以直接从epel源装)# 或者使用这个源(curl -o /etc/yum.repos.d/powerdns-auth-master.repo https://repo.powerdns.com/repo-files/centos-auth-master.repo)curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo yum install -y pdns pdns-backend-mysql
#配置pdns.confsed -n 250,254p /etc/pdns/pdns.conf launch=gmysql gmysql-host=localhost gmysql-user=powerdns gmysql-password=5jIXfISFu5W8pq8lVy3qUvtL gmysql-dbname=powerdns
#启动pdns,启动后看下服务是否正常,53端口有没有,数据库配错了就起不来systemctl enable pdns systemctl start pdns
#下载poweradmin源码 git clone https://github.com/poweradmin/poweradmin.git mv poweradmin /var/www/html/ chown -R apache /var/www/html/poweradmin
#配置httpd文件,使用hosts域名解析[root@powerdns ~]# cat /etc/httpd/conf.d/powerdns.conf<VirtualHost *:80> ServerName poweradmin.example.cn ProxyRequests Off ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/poweradmin/$1 DocumentRoot "/var/www/html/poweradmin" <Directory /var/www/html/poweradmin> Options None AllowOverride None Require all granted </Directory> ErrorLog "/var/log/httpd/poweradmin-error.log" TransferLog "/var/log/httpd/poweradmin-access.log"</VirtualHost> [root@powerdns ~]# httpd -tSyntax OK [root@powerdns ~]# systemctl restart httpd
#打开浏览器访问http://poweradmin.example.cn/install一步步配置#第一步选择语言,第三步填数据库信息和超管密码,第四步创建poweradmin用户,第五步创建数据库和用户(前面已经创建,不用管了),第六步手动创建config.inc.php填数据库信息,第七步,在虚拟机上移除install目录。#然后重新访问http://poweradmin.example.cn,用admin和超管密码登陆#然后添加主域(就是你的域名),然后编辑,添加记录#最后在虚拟机上dig或nslookup测试,有结果则成功yum install bind-utils -y -q && dig @127.0.0.1 www.jd.com
二、添加主域jd.com
并解析到nginx-lb的IP上
三、nginx-lb的配置
[root@nginx-lb ~]# cat > /etc/yum.repos.d/nginx.repo <<'EOF'[nginx] name=nginx baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ enabled=1 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=trueEOF [root@nginx-lb ~]# yum install nginx -y
[root@nginx-lb ~]# grep -v ^$ /etc/nginx/nginx.conf user nginx; worker_processes auto; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; tcp_nopush on; keepalive_timeout 65; server_tokens off; gzip on; include /etc/nginx/conf.d/*.conf; }
[root@nginx-lb conf.d]# cat default.conf upstream backend { server 192.168.38.136:80 max_fails=0 fail_timeout=10s; server 192.168.38.138:80 max_fails=0 fail_timeout=10s; } server { listen 80; server_name localhost; access_log /var/log/nginx/blog.access.log main; error_log /var/log/nginx/blog.error.log; location / { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://backend; } }
[root@nginx-lb conf.d]# nginx -tnginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful [root@nginx-lb conf.d]# nginx
四、web1和web2的配置
yum install httpd -y# 不然启动很慢sed '/#ServerName www.example.com/a ServerName www.example.com:80' /etc/httpd/conf/httpd.conf -i systemctl start httpd && systemctl enable httpd
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo yum install https://mirrors.huaweicloud.com/remi/enterprise/remi-release-7.rpm -y yum install php73-php php73-php-mysqlnd php73-php-fpm php73-php-xml php73-php-bcmath php73-php-mbstring php73-php-xmlrpc php73-php-soap php73-php-common php73-php-devel php73-php-gd php73-php-pecl-mcrypt php73-php-pecl-memcache php73-php-pecl-memcached php73-php-opcache -y systemctl start php73-php-fpm && systemctl enable php73-php-fpm
五、NFS服务器配置
[root@nfs1 ~]# yum install nfs-utils -y[root@nfs1 ~]# systemctl start nfs-server && systemctl enable nfs-server.service[root@nfs1 ~]# mkdir /data/wordpress -p[root@nfs1 ~]# wget https://cn.wordpress.org/latest-zh_CN.tar.gz -O wordpress-zh_CN.tar.gz[root@nfs1 ~]# tar xf wordpress-zh_CN.tar.gz [root@nfs1 ~]# mv -f wordpress /data/
[root@nfs1 ~]# cat /etc/exports/data/wordpress 192.168.38.*(rw,sync,no_subtree_check,no_root_squash) [root@nfs1 ~]# exportfs -rvexporting 192.168.38.*:/data/wordpress [root@nfs1 ~]# showmount -e 192.168.38.146Export list for 192.168.38.146: /data/wordpress 192.168.38.*
[root@nfs1 ~]# useradd -s /bin/nologin nfsuser[root@nfs1 ~]# getent passwd nfsusernfsuser:x:1000:1000::/home/nfsuser:/bin/nologin [root@nfs1 ~]# vim /etc/exports[root@nfs1 ~]# cat /etc/exports/data/wordpress 192.168.38.*(rw,sync,no_subtree_check,anonuid=1000,anongid=1000) [root@nfs1 ~]# chown -R nfsuser.nfsuser /data/wordpress[root@nfs1 ~]# exportfs -rvexporting 192.168.38.*:/data/wordpress
六、两个web服务器挂载nfs
[root@wp-web2 ~]# yum install nfs-utils autofs -y
[root@wp-web2 ~]# mkdir -p /data/wordpress
[root@wp-web2 ~]# grep data /etc/auto.master/data /etc/nfs.misc [root@wp-web2 ~]# cat /etc/nfs.misc wordpress -rw 192.168.38.146:/data/wordpress [root@wp-web2 ~]# systemctl restart autofs && systemctl enable autofs
七、两个web服务器配置httpd
##httpd和php应当调优,可以放到最后[root@wp-web1 ~]# cat /etc/httpd/conf.d/blog.jd.com.conf <VirtualHost *:80> ServerName blog.jd.com DirectoryIndex index.php ProxyRequests Off ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/data/wordpress/$1 DocumentRoot "/data/wordpress" <Directory /data/wordpress> Options None AllowOverride None Require all granted </Directory> ErrorLog "/var/log/httpd/blog.jd.com-error.log" TransferLog "/var/log/httpd/blog.jd.com-access.log"</VirtualHost> [root@wp-web1 ~]# httpd -tSyntax OK [root@wp-web1 ~]# systemctl reload httpd
此处应做访问测试
八、配置主从数据库
master数据库
rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-2.noarch.rpm yum install yum-utils -y sudo yum-config-manager --disable mysql80-community sudo yum-config-manager --enable mysql57-community yum makecache yum install mysql-community-server -y cat > /etc/my.cnf <<EOF [mysqld] socket=/var/lib/mysql/mysql.sock datadir=/data/mysqllog-bin gtid_mode=on enforce_gtid_consistency=on server-id=1 expire-logs-days=15 binlog-format=row symbolic-links=0log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid EOF DB_PASSWORD=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 24` mkdir /data/mysql -p mysqld --initialize --datadir=/data/mysql --user=mysql systemctl start mysqld && systemctl enable mysqld mysqladmin -uroot -p$(grep " temporary password" /var/log/mysqld.log | awk '{print $NF}') password ${DB_PASSWORD}
mysql> grant replication slave on *.* to 'repluser'@'192.168.38.%' identified by 'gRdoX3VZWutzDlPmiA2dGyHA'; mysql> flush privileges;
slave库
#安装数据库#修改数据库配置[root@mysql-slave ~]# cat /etc/my.cnf[mysqld] socket=/var/lib/mysql/mysql.sock datadir=/data/mysql server-id=1 gtid-mode=on enforce_gtid_consistency=on symbolic-links=0log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid [root@mysql-slave ~]# systemctl restart mysqld && systemctl enable mysqld
mysql> CHANGE MASTER TO -> MASTER_HOST='192.168.38.139', -> MASTER_USER='repluser', -> MASTER_PASSWORD='gRdoX3VZWutzDlPmiA2dGyHA', -> MASTER_PORT=3306, -> MASTER_AUTO_POSITION=1; mysql> START SLAVE;
#两个yes表示OKmysql> show slave status\G ...... Slave_IO_Running: Yes Slave_SQL_Running: Yes
九、创建wordpress数据库
master节点操作
这里的mysql要让php连接,因此两个web要分别授权或者用%代替
DB_WORDPRESS_PASSWORD=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 24` mysql -uroot -p${DB_PASSWORD} -e "create user wordpress@'192.168.38.%' identified by '${DB_WORDPRESS_PASSWORD}';create database wordpress character set utf8 collate utf8_bin;grant all privileges on wordpress.* to wordpress@'192.168.38.%';flush privileges;"
十、web访问blog.jd.com
因为已经搭建了DNS服务器了,只需要将windos的dns改为192.168.38.147即可访问blog.jd.com
但是网页显示没有写权限(但普通用户都可以往该nfs目录写文件)
经过测试nfs目录权限改为777即可(chmod 777 /data/wordpress)
最终解决办法:nfs服务器创建apache用户并设置acl权限(/etc/exports文件此处没改)
[root@nfs1 ~]# /usr/sbin/groupadd -g 48 -r apache 2> /dev/null || :[root@nfs1 ~]# /usr/sbin/useradd -c "Apache" -u 48 -g apache -s /sbin/nologin -r -d /usr/share/httpd apache 2> /dev/null || :[root@nfs1 ~]# setfacl -R -m u:apache:rwx /data/wordpress/
十、最终效果:
十一、再部署个phpadmin
#这个直接解压即可用
十二、再部署个discuz
操作NFS
#下载源代码 yum install git -y git clone https://gitee.com/ComsenzDiscuz/DiscuzX.git cp DiscuzX/upload /data/discuz -a chown nfsuser.nfsuser -R /data/discuz setfacl -R -m u:apache:rwx /data/discuz exportfs -rv
操作master数据库
DB_DISCUZ_PASSWORD=`cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 24` mysql -uroot -p${DB_PASSWORD} -e "create user discuz@'192.168.38.%' identified by '${DB_DISCUZ_PASSWORD}';create database discuz character set utf8 collate utf8_bin;grant all privileges on discuz.* to discuz@'192.168.38.%';flush privileges;"
操作两台web
[root@wp-web1 ~]# grep discuz /etc/nfs.misc discuz -rw 192.168.38.146:/data/discuz [root@wp-web1 ~]# systemctl reload autofs.service
[root@wp-web1 ~]# cat > /etc/httpd/conf.d/bbs.jd.com.conf << 'EOF'<VirtualHost *:80> ServerName bbs.jd.com ProxyRequests Off ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/data/discuz/$1 DocumentRoot "/data/discuz" <Directory /data/discuz> Options None AllowOverride None Require all granted </Directory> ErrorLog "/var/log/httpd/bbs.jd.com-error.log" TransferLog "/var/log/httpd/bbs.jd.com-access.log"</VirtualHost> EOF [root@wp-web1 ~]# httpd -tSyntax OK [root@wp-web1 ~]# systemctl reload httpd
设置DNS解析
访问测试(没有问题):
就是这个文件属性怪怪的:
十三、系统调优
#本来这个应该放在最前面的,最后就最后吧,#内核参数调优#文件句柄数调优#nginx,php,httpd,mysql调优等
禁止转载,禁止搬运,爬虫司马
总结:
两个域名的访问互不影响,证明nginx那块配置的还行