之前的阿里云服务器环境都是用一键安装包的形式安装的。虽然安装的过程简单,但是安装之后就会出现磁盘占用太大。
我做了一个简单的比较我用一键安装包的形式安装之后使用的空间是7G多,但是通过命令自行安装的话,使用的磁盘空间是2G多点。
好了,下面我们具体的看看,怎么用yum安装LNMP的环境。当然这些都是我老大总结出来的。
linux CentOS6.5
nginx 1.10
mysql 5.7
php 5.6
vi /etc/yum.repos.d/nginx.repo [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/6/$basearch/ gpgcheck=0 enabled=1
yum remove httpd* php* yum install nginx
chkconfig nginx on
rpm -ivh http://repo.mysql.com/mysql57-community-release-el6.rpm yum install mysql-community-serve
service mysqld start grep 'temporary password' /var/log/mysqld.log
SET password = PASSWORD('K4eY@pZ555rR34Zx'); // 修改密码
grant all privileges on *.* to root@'%' identified by 'K4eY@p544R34Zx'; flush privileges; // 刷新权限 chkconfig mysqld on // 设置开机启动
rpm -Uvh http://ftp.iij.ad.jp/pub/linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm yum install --enablerepo=remi --enablerepo=remi-php56 php php-bcmath php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-gd php-xml php-memcache php-redis php-fpm php-mysql php-common php-mssql
vi etc/php.ini expose_php = Off // 关闭php信息 service php-fpm restart
yum -y install memcached
vi /etc/sysconfig/iptables
示例代码,将下面的代码全部拷贝到文件里。
# Firewall configuration written by system-config-firewall # Manual customization of this file is not recommended. *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT #http -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT #mysql -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT #ssh -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT -A INPUT -j REJECT --reject-with icmp-host-prohibited -A FORWARD -j REJECT --reject-with icmp-host-prohibited COMMIT
//重启
/etc/init.d/iptables restart
// 设置随系统启动
chkconfig iptables on
chkconfig mysqld --level 2345 on chkconfig nginx --level 2345 on chkconfig php-fpm --level 2345 on chkconfig memcached --level 2345 on
关闭SELINUX
vi /etc/selinux/config #SELINUX=enforcing #注释掉 #SELINUXTYPE=targeted #注释掉 SELINUX=disabled #增加 :wq #保存退出 shutdown -r now #重启系统
Nginx: //注:如手工更改配置文件,强烈建议 reload service nginx {start|stop|status|restart|reload|configtest}
MySQL:
service mysqld {start|stop|restart|reload|status}
PHP:
service php-fpm {start|stop|restart|reload|status}
Pure-Ftpd:
service pureftpd {start|stop|restart|status}
Redis:
service redis-server {start|stop|status|restart|reload}
Memcached:
service memcached {start|stop|status|restart|reload}
通过上面的步骤就很轻松的解决了LNMP环境的安装,是不是很简单。告别一键安装包,手动安装更给力。
host主机配置
server { listen 80; # 绑定的域名 server_name www.cc1021.com; # 默认首页文件 index index.html index.htm index.php; # 网站地址 root /data/wwwroot/static; location ~ .*\.(php|php5)?$ { #fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi_params; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 1h; } # 伪静态配置 # include /alidata/server/nginx/conf/rewrite/default.conf; # 日志文件 # access_log /data/log/nginx/access/static.log; }
主从配置
vi /etc/my.cnf [mysqld] log-bin=mysql-bin server-id=222 show master status; +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000004 | 308 | | | +------------------+----------+--------------+------------------+ GRANT REPLICATION SLAVE ON *.* to 'root'@'%' identified by 'sheyi_2016'; change master to master_host='192.168.1.200',master_user='root',master_password='sheyi_2016',master_log_file='mysql-bin.000004',master_log_pos=26666;
检查从服务器复制功能状态
show slave status\G