centos6.4+nginx+mysql+php+phpmyadmin整合过程详解
本文实例讲述了centos6.4+nginx+mysql+php+phpmyadmin整合过程。分享给大家供大家参考,具体如下:
装了很多次机,做了很多次重复工作,最后,总结以下装CentOS经验:
注:很多问题其实都不是问题,先把selinux关了!setenforce0,不然会死的很惨!
1.先更新源
启用国内的源:163或sohu
163:http://mirrors.163.com/.help/centos.html
如果想使用新的软件,建议用REPL和remi的源
#remi的源 rpm-ivhhttp://rpms.famillecollet.com/enterprise/remi-release-6.rpm rpm--import/etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 #FedoraREPL的源 rpm-ivhhttp://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm rpm--import/etc/pki/rpm-gpg/RPM-GPG-KEY-remi
然后yumupdate升级系统
下面才是安装我们需要的软件,例如nginx+php+php-fpm+mysql+vsftpd等
下面开始配置:
1.设置系统时间
cp/usr/share/zoneinfo/Asia/Hong_Kong/etc/localtime date#查看系统时间 */30****/usr/sbin/ntpdatetime.nist.gov crontab-e
加入这行:*/30****/usr/sbin/ntpdatetime.nist.gov
2.更新系统
yumupdate
3.安装Nginx:
Niginx官方的更新源增加:vim/etc/yum.repos.d/nginx.repo
增加以下内容
[nginx] name=nginxrepo baseurl=http://nginx.org/packages/centos/6/$basearch/ gpgcheck=0 enabled=1 yuminstallnginx
优化Nginx配置:
#根据CPU核心processes而定 worker_processes6; worker_cpu_affinity000001000010000100001000010000100000;<br><br> #启用epoll worker_rlimit_nofile51200; events{ worker_connections51200; useepoll; } #参数调整 sendfileon; tcp_nopushon; tcp_nodelayon; server_tokensoff; keepalive_timeout50; server_names_hash_bucket_size128; client_header_buffer_size32k; large_client_header_buffers432k; client_max_body_size50m; #fastcgi优化 fastcgi_connect_timeout300; fastcgi_send_timeout300; fastcgi_read_timeout300; fastcgi_buffer_size64k; fastcgi_buffers464k; fastcgi_busy_buffers_size128k; fastcgi_temp_file_write_size256k; #开启gzip并优化 gzipon; gzip_min_length1k; gzip_buffers416k; gzip_http_version1.0; gzip_comp_level2; gzip_typestext/plainapplication/x-javascripttext/cssapplication/xml; gzip_varyon;
设置开机启动:
servicenginxstart chkconfignginxon #安装php,php-fpm yuminstallphpphp-fpmphp-bcmatchphp-gdphp-mbstringphp-mcryptphp-mysql
配置PHP脚本的运行:
cp/etc/nginx/conf.d/default.confetc/nginx/conf.d/default.confbak vim/etc/nginx/conf.d/default.conf
设置网站的默认目录:#这里php-fpm是采用监听端口的方式,同一台机的话最好采用unixsocket
#去除下面这段内容的注释 location~\.php${ root/home/www; fastcgi_pass127.0.0.1:9000; fastcgi_indexindex.php; fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name; includefastcgi_params; } #注意其中fastcgi_param行的参数,改为$document_root$fastcgi_script_name,或者使用绝对路径
4.vsftpd配置
先配置iptables,vi/etc/sysconfig/iptables,复制--dport22那行,粘贴改成21端口。保存,重启serviceiptablesrestart。
yuminstallvsftpdftp touch/var/log/vsftpd.log servicevsftpdstart chkconfigvsftpdon vim/etc/vsftpd/vsftpd.conf #修改相关参数如下: #设定不允许匿名访问 anonymous_enable=NO #设定本地用户可以访问。注:如使用虚拟宿主用户,在该项目设定为NO的情况下所有虚拟用户将无法访问。 local_enable=YES #使用户不能离开主目录,并制定文件 chroot_list_enable=YES chroot_list_file=/etc/vsftpd/chroot_list #设定vsftpd的服务日志保存路径。注意,该文件默认不存在。必须要手动touch出来,前面步骤已经创建 xferlog_file=/var/log/vsftpd.log #允许使用ASCII模式上传和下载 ascii_upload_enable=YES ascii_download_enable=YES #PAM认证文件名。PAM将根据/etc/pam.d/vsftpd进行认证 pam_service_name=vsftpd #以下这些是关于Vsftpd虚拟用户支持的重要CentOSFTP服务配置项目。默认vsftpd.conf中不包含这些设定项目,需要自己手动添加RHEL/CentOSFTP服务配置。 #设定启用虚拟用户功能。 guest_enable=YES #指定虚拟用户的宿主用户。-RHEL/CentOS中已经有内置的ftp用户了 guest_username=ftp #设定虚拟用户个人vsftp的RHEL/CentOSFTP服务文件存放路径。存放虚拟用户个性的CentOSFTP服务文件(配置文件名=虚拟用户名)user_config_dir=/etc/vsftpd/vuser_conf touch/etc/vsftpd/chroot_list echoftp>>/etc/vsftpd/chroot_list yuminstalldb4db4-utils vim/etc/vsftpd/vuser_passwd.txt
加入相应的用户信息,其中奇数行为你新增用户的账号,偶数行为密码,不能有空格
username1
password1
username2
password2
保存文件退出,生成用户认证的db文件
db_load-T-thash-f/etc/vsftpd/vuser_passwd.txt/etc/vsftpd/vuser_passwd.db vim/etc/pam.d/vsftpd
用#注释所有的内容,然后增加以下两行内容:
authrequiredpam_userdb.sodb=/etc/vsftpd/vuser_passwd accountrequiredpam_userdb.sodb=/etc/vsftpd/vuser_passwd
保存退出。再创建虚拟用户的ftp服务文件夹,以及前文中所增加的账号用户的配置文件
mkdir/etc/vsftpd/vuser_conf/ vim/etc/vsftpd/vuser_conf/username1
填写以下内容:
#username1用户的根目录(自己决定) local_root=/home/www/ftp write_enable=YES anon_umask=0 anon_world_readable_only=NO anon_upload_enable=YES anon_mkdir_write_enable=YES anon_other_write_enable=YES
保存内容,退出。要创建上述配置文件中所设置的用户根目录,并为其设置权限
mkdir/home/www/ftp chmod777/home/www/ftp servicevsftpdrestart
ok
#有时候会出现,可以连接ftp,却不能列出目录,这个是iptable的端口问题。开启PASV即可,vim/etc/vsftpd/vsftpd.conf
pasv_enable=YES pasv_min_port=9000 pasv_max_port=9020
然后在iptables里面加上这两个端口,还是前面说的,yy一行22,再p一下,把22改成9000:9020;
还有可能是selinux的关机,
modprobeip_nat_ftp serviceiptablesrestart&&servicevsftpdrestart
5.安装Mysql5.6
yumupdate #数据库服务器的安装,请自行在mysql官方找最新的rpm rpm-Uvhhttp://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm yuminstallmysql-server
安装完成后记得运行
mysql_security_installation
远程连接时,还要将mysql3306端口加入iptables,同样使用前面的方法,复制一句22的,改成3306,重启iptables即可。
配置mysql远程连接:命令行使用root登录
mysql-uroot-p usemysql; updateusersethost='%'whereuser='root';
另外可能的工作:
安装phpMyAdmin
googlephpMyAdmin找到在sourceforge的地址,然后在网站根目录下wget下来。
解压,重命名目录,进入目录,
cpconfig.sample.inc.phpconfig.inc.php
重启nginx
注意这里还得再改一下,浏览器进入phpmyadmin地址,可能会出现下面的错误:
Cannotstartsessionwithouterrors,pleasecheckerrorsgiveninyourPHPand/orwebserverlogfileandconfigureyourPHPinstallationproperly.
需要将/var/lib/php/session的所有者改为nginx
chown-Rnginx:nginx/var/lib/php/session
现在应该可以访问了...
配置mysql远程连接
因为管理需要,我们需要远程连接一下mysql,以进行管理。安装好phpmyadmin后,在用户那里可以选择新建一个用户,将主机设置为需要连接的主机ip或任意主机即可
自动挂载硬盘:
由于外置了一个硬盘,所以得配置开机自动挂载。vim/etc/fstab加入:
/dev/sdc/mnt/dataautodefaults00
centos网络配置:
IP设置:/etc/sysconfig/network-scripts/ifcfg-eth0
网关设置:/etc/sysconfig/network
DNS设置:/etc/resolv.conf
重启网络:
servicenetworkrestart
关闭SELiinux
在后面的工作中,发现很多地方不方便,例如ftp无法上传等问题,ssh远程无法连接等,于是关闭SELinux,运行以下命令:
#/usr/sbin/setenforce0 #echo"usr/sbin/setenforce0">>/etc/rc.local
这样就可以把关闭SELinux加入开机启动。
希望本文所述对大家CentOS服务器配置有所帮助。