virtualBox安裝centos7並配置nginx php mysql運行環境
virtualBox安裝centos7並配置nginx php mysql運行環境
一:virtualBox安裝centos7並進行基礎設置
1.下載dvd.iso安裝文件,下載地址:https://www.centos.org/download/
我選擇的是DVD.iso的版本,大家自行查詢三個版本的不同,對於我來說DVD版本已經夠了,最好用迅雷下載,本地下載太慢了
2.系統(設置)->啟動順序改為光驅軟驅硬盤
3.存儲(設置)->點擊盤片,選擇之前下載的.iso文件
4.網絡設置為橋接模式,主機與虛擬機可以互通
幾種網絡模式的介紹:https://www.douban.com/group/topic/15558388/
5.點擊啟動進入系統安裝
6.最小化安裝、虛擬硬盤自動分區,設置root密碼
7.安裝成功後,重新啟動
8.最簡安裝的系統不存在ifconfig命令,我們在系統上安裝一下
yum provides ifconfig 或 yum whatprovides ifconfig
查詢到ifconfig命令是依賴於 net-tools軟件的,所以我們來安裝net-tools軟件
yum install -y net-tools
測試到ifconfig命令可以用了(之前可以用ip addr命令代替)
9:初始wget軟件安裝
yum install -y wget
10:初始安裝killall命令,nginx及其他服務啟動關閉時會使用
yum install psmisc
11:如有需要,需設置靜態IP啟用,以後重啟就可以一直用這個IP了,由於我自己公司網絡配置,我沒有設置。
vi /etc/sysconfig/network-scripts/ifcfg-****文件 BOOTPROTO="dhcp"修改為BOOTPROTO="static" 添加:IPADDR=10.200.79.123 設置的靜態 ip地址 重啟網絡服務:service network restart 然後因為設置靜態IP的原因出現了網絡連接不上的問題,經解決:公司網段設置的問題,導致主機和虛擬機不在同一個網段,但是不影響互相訪問,公司內的同事也可以訪問我的虛擬機
二:搭建 nginx
參考地址:https://blog.csdn.net/faith306/article/details/78541974
根據文章安裝完成後,啟動nginx的過程中遇到幾個問題
1.log_format main的定義問題,錯誤如下:
[root@bogon rewrite]# /selfdata/server/nginx-1.12.2/sbin/nginx nginx: [emerg] unknown log format "main" in /selfdata/server/nginx-1.12.2/nginx.conf:26
上面文章中沒有main的定義,並且log_format定義在access_log使用main的下面,更改為
2.不存在日誌文件夾的問題
[root@bogon rewrite]# /selfdata/server/nginx-1.12.2/sbin/nginx nginx: [emerg] open() "/selfdata/logs/nginx/access/default.log" failed (2: No such file or directory)
這裏是因為:/selfdata/logs/nginx/文件夾下面access文件夾不存在導致的,創建即可,之所以需要這個文件夾,是因為在nginx的服務器配置conf/vhosts/default.conf配置文件中配置了這個日誌的地址。access和error文件夾都要創建
3.nginx程序目錄下不存在log目錄需要創建
[root@bogon nginx]# /selfdata/server/nginx-1.12.2/sbin/nginx [root@bogon nginx]# nginx: [emerg] open() "/selfdata/server/nginx-1.12.2/logs/nginx.pid" failed (2: No such file or directory)
經網上查詢,需要配置nginx程序對應的配置文件。而且需要創建logs文件夾,nginx目錄下初始化安裝完時裏面是沒有這個目錄的。
[root@bogon nginx-1.12.2]# mkdir logs [root@bogon nginx-1.12.2]# /selfdata/server/nginx-1.12.2/sbin/nginx -c /selfdata/server/nginx-1.12.2/nginx.conf
4.然後啟動,又顯示80端口被占用。
[root@bogon nginx-1.12.2]# /selfdata/server/nginx-1.12.2/sbin/nginx nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] still could not bind()
我分兩步來解決
第一:首先移除防火墻的影響,不管有沒有影響。參考地址:https://blog.csdn.net/zyhlearnjava/article/details/71908529
~~~防止文章丟失,我再抄一遍:
[root@localhost ~]# yum install iptables-services [root@localhost ~]# systemctl mask firewalld.service [root@localhost ~]# systemctl enable iptables.service [root@localhost ~]# systemctl enable ip6tables.service
進入iptables配置80端口,因為nginx默認是由80端口訪問
[root@localhost ~]# vi /etc/sysconfig/iptables
這是配置信息:
# Generated by iptables-save v1.4.21 on Fri May 12 21:28:29 2017 *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [6:696] -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT(我給vsftpd配置的端口) -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT(給nginx配置的端口,原樣輸入就行了) -A INPUT -p tcp -m state --state NEW -m tcp --dport 30000:30999 -j ACCEPT -A INPUT -j REJECT --reject-with icmp-host-prohibited -A FORWARD -j REJECT --reject-with icmp-host-prohibited COMMIT # Completed on Fri May 12 21:28:29 2017
然後:wq,保存退出就行了;
重啟iptables,配置才生效;
[root@localhost ~]# systemctl restart iptables.service
開啟防火墻,不管你開沒有,再開一遍:
[root@localhost ~]# systemctl start firewalld
開啟http訪問
[root@localhost ~]# firewall-cmd --permanent --add-service=http
加入80端口
[root@localhost ~]# firewall-cmd --permanent --zone=trusted --add-port=80/tcp
~~~抄完了
之後還是報錯
第二步:
[root@bogon nginx-1.12.2]# killall -9 nginx [root@bogon nginx-1.12.2]# /selfdata/server/nginx-1.12.2/sbin/nginx [root@bogon nginx-1.12.2]# ps -ef|grep nginx
啟用成功了
將nginx加入服務和開機啟動的操作沒有實踐成功,開啟的過程中報錯了,所以我沒加,先忽略的這部分
三:下載並安裝PHP
用上面文章參考安裝失敗了,查閱資料。參考另一個地址:https://blog.csdn.net/xiao_zhui/article/details/72556781;該文章主要是參考安裝組件部分,php編譯安裝之前需要這些組件支持
我再復制下來,
yum -y install libxml2 yum -y install libxml2-devel yum -y install openssl yum -y install openssl-devel yum -y install curl yum -y install curl-devel yum -y install libjpeg yum -y install libjpeg-devel yum -y install libpng yum -y install libpng-devel yum -y install freetype yum -y install freetype-devel yum -y install pcre yum -y install pcre-devel yum -y install libxslt yum -y install libxslt-devel yum -y install bzip2 yum -y install bzip2-devel
# ./configure --prefix=/selfdata/server/php-7.1.11 --with-config-file-path=/selfdata/server/php-7.1.11/etc --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-pdo --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip --enable-calendar # make # make install # cp /selfdata/package/php-7.1.11/php.ini-production /selfdata/server/php-7.1.11/etc/php.ini # cd /selfdata/server/php-7.1.11/etc # cp php-fpm.conf.default php-fpm.conf # cd /selfdata/server/php-7.1.11/etc/php-fpm.d # cp www.conf.default www.conf # vi /selfdata/server/php-7.1.11/etc/php-fpm.conf ~~修改內容 pid= /selfdata/server/php-7.1.11/var/run/php-fpm.pid ~~~內容結束 #vi /selfdata/server/php-7.1.11/etc/php-fpm.d/www.conf ~~~內容 user = www group = www listen = 127.0.0.1:9000 pm.max_children = 100 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 ~~~內容
四:mysql安裝
mysql第一次安裝時直接按照第一篇參考資料安裝的,直接文件夾安裝的,遇到了很多的錯誤,而且最後始終是提醒缺少PID文件,並且啟用不起來,而且沒有錯誤日誌,實在沒辦法,選擇了卸載,重新安裝,重新啊安裝采用的yum安裝的
1.卸載原有mysql殘余,在網絡查詢如何完全下載
2.yum mysql安裝參考:
https://www.linuxidc.com/Linux/2016-09/135288.htm
3.安裝完成之後需要進行初始的訪問設置,用戶設置這些
參考:
https://blog.csdn.net/java_raylu/article/details/73196737
https://blog.csdn.net/u010072512/article/details/51802472
virtualBox安裝centos7並配置nginx php mysql運行環境