RedHat6.2 x86手动配置LNMP环境
為什么80%的碼農都做不了架構師?>>> ??
因為公司要求用RedHat配,順便讓我練習一下Linux里面的操作什么的。
折騰來折騰去終于搞好了,其實也沒那么難嘛。但是也要記錄一下。
首先,是在服務器里面用VMware搭建的RedHat6.2 x86系統。在RedHat里面yum里面的源基本是收費的。CentOS呢,是RedHat的衍生版,目的就是打破redhat的收費,所以兩者也沒啥區別。直接就用CentOS6的yum包來配置了。
首先,在終端里輸入:
cd?/etc/yum.repos.d/這里面是放yum源的地方。默認里面會有一個rhel-source.repo后綴的文件,咱們把他刪了或者重命名成.bak
然后下一步就是添加centos的源了。新建一個centos.base.repo文件。在里面輸入:
#?CentOS-Base.repo# #?The?mirror?system?uses?the?connecting?IP?address?of?the?client?and?the#?update?status?of?each?mirror?to?pick?mirrors?that?are?updated?to?and#?geographically?close?to?the?client.??You?should?use?this?for?CentOS?updates#?unless?you?are?manually?picking?other?mirrors.# #?If?the?mirrorlist=?does?not?work?for?you,?as?a?fall?back?you?can?try?the?#?remarked?out?baseurl=?line?instead.#?[base] name=CentOS-6?-?Base?-?mirrors.aliyun.com baseurl=http://mirrors.aliyun.com/centos/6/os/$basearch/#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=osgpgcheck=0gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6? #released?updates?[updates] name=CentOS-6?-?Updates?-?mirrors.aliyun.com baseurl=http://mirrors.aliyun.com/centos/6/updates/$basearch/#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=updatesgpgcheck=0gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6? #additional?packages?that?may?be?useful[extras] name=CentOS-6?-?Extras?-?mirrors.aliyun.com baseurl=http://mirrors.aliyun.com/centos/6/extras/$basearch/#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=extrasgpgcheck=0gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6? #additional?packages?that?extend?functionality?of?existing?packages[centosplus] name=CentOS-6?-?Plus?-?mirrors.aliyun.com baseurl=http://mirrors.aliyun.com/centos/6/centosplus/$basearch/#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=centosplusgpgcheck=0enabled=0gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6? #contrib?-?packages?by?Centos?Users[contrib] name=CentOS-6?-?Contrib?-?mirrors.aliyun.com baseurl=http://mirrors.aliyun.com/centos/6/contrib/$basearch/#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=contribgpgcheck=0enabled=0gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6保存之后,我們就有一個centos的源了。執行一下:yum -y update ?試一下吧!
下面是安裝Nginx了。我們需要執行:
yum?-y?--enablerepo=remi,remi-test?install?nginx有些朋友可能會遇到:No Nginx package!,這很簡單就能解決。
在剛才創建源的yum.repos.d文件夾里面,再創建一個nginx.repo文件。輸入以下內容:
[nginx]?? name=nginx?repo?? baseurl=http://nginx.org/packages/centos/6/$basearch/??gpgcheck=0??enabled=1OK,這是單獨添加一個Nginx的源。再執行一次上面的安裝Nginx的命令就Ok了!
繼續,安裝php以及php-fpm:
yum?-y?--enablerepo=remi,remi-test?install?php?php-fpm?php-common安裝PHP5.4.4模塊擴展,有些會提示No package,這些都是沒用的,不要管它!
yum?-y?--enablerepo=remi,remi-test?install?php-pecl-apc?php-cli?php-pear?php-pdo?php-mysql?php-pgsql?php-pecl-mongo?php-sqlite?php-pecl-memcache?php-pecl-memcached?php-gd?php-mbstring?php-mcrypt?php-xml這樣就OK了。運行下面的命令,如果出現錯誤,說明你上面的步驟出錯了。
啟動Nginx: service?nginx?start 啟動php-fpm: service?php-fpm?start下面是配置Nginx使用php-fpm,進入:
/etc/nginx/conf.d/打開:default.conf 文件。找到:
location?/?{??root???/usr/share/nginx/html;??#這一行是網站的根目錄,你的網站文件就放在這個里面!index??index.html?index.htm;??#這一行是添加網站的默認主頁的。當然,你也可以添加一個index.php!}再找到下面的內容,把它們前面的#去掉:
#location?~?\.php$?{??#???????root???????????html;??#???????fastcgi_pass???127.0.0.1:9000;??#???????fastcgi_index??index.php;??#???????fastcgi_param??SCRIPT_FILENAME?/usr/share/nginx/html$fastcgi_script_name;??#????????include????????fastcgi_params;??#}然后把redhat的防火墻文件打開,把80端口添加進白名單:
cd?/etc/sysconfig/打開iptables文件,輸入以下內容:
-A?INPUT?-m?state?--state?NEW?-m?tcp?-p?tcp?--dport?80?-j?ACCEPT重啟防火墻:
service?iptables?restart到此為止,php與Nginx已經搭建好了。我們來試一下。先重啟Nginx與php-fpm:
service?nginx?restart?? service?php-fpm?restart在你RedHat網頁里輸入:http://localhost/,成功出現 Welcome to nginx!則Nginx安裝成功。
然后進入你網站的根目錄:/usr/share/nginx/html
新建一個phpinfo.php文件:
<?phpphpinfo();?>然后訪問http://localhost/phpinfo.php
看是不是出現php配置的頁面了。如果出現就說明php安裝成功了。
開始安裝mysql!!!!!在終端里輸入:
yum?-y?--enablerepo=remi,remi-test?install?mysql?mysql-server啟動mysql and 設置自啟動:
service?mysqld?start?? chkconfig?--levels?235?mysqld?on然后,進入/usr/bin/文件夾,運行mysql_secure_installation文件:
cd?/usr/bin/./mysql_secure_installation這是配置mysql的安全模式。第一次裝mysql最好都配置一下。增加安全性!
執行上面的文件之后,會出現一些配置問題。
1、Enter current password for root (enter for none): (輸入當前的root密碼) 當前的密碼是空,所以直接回車。
2、Set root password? [Y/n] (是否設置密碼)輸入Y 回車。
3、New password: ?(新密碼)
4、Re-enter new password: ?(再輸一次)
5、Remove anonymous users? [Y/n] ?(刪除匿名賬戶)?
6、Disallow root login remotely? [Y/n] (禁止root用戶遠程登錄)
7、Remove test database and access to it? [Y/n] (刪除默認創建的test數據庫)
8、Reload privilege tables now? [Y/n] (重載權限表)
安全模式配置完畢!
然后把redhat的防火墻文件打開,把3306端口添加進白名單:
cd?/etc/sysconfig/打開iptables文件,輸入以下內容:
-A?INPUT?-m?state?--state?NEW?-m?tcp?-p?tcp?--dport?3306?-j?ACCEPT重啟防火墻:
service?iptables?restartOK!LNMP配置完畢!
轉載于:https://my.oschina.net/mik3y/blog/291612
總結
以上是生活随笔為你收集整理的RedHat6.2 x86手动配置LNMP环境的全部內容,希望文章能夠幫你解決所遇到的問題。