Ubuntu下安装php-redis扩展
$ sudo apt-get install php5-dev $ wget --no-check-certificate http://github.com/nicolasff/phpredis/tarball/master -O phpredis.tar.gz $ tar -xzvf phpredis.tar.gz $ cd nicolasff-phpredis-94e0649 $ phpize $ ./configure $ make $ sudo make install
增加php.ini配置
extension=redis.so
mysql 远程访问权限开启
mysql -u root -p123456; mysql GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; mysql flush privileges;
mysql5.5远程主从设置
主机:10.0.0.1
从机:10.0.0.2
1 主机设置
1.1 配置文件/etc/mysql/my.cnf
server-id = 1 log_bin = /var/log/mysql/mysql-bin.log expire_logs_days = 2 max_binlog_size = 100M binlog_ignore_db = mysql binlog_ignore_db = information_schema binlog_ignore_db = performance_schema binlog_do_db = testcase binlog_do_db = db100 binlog_do_db = db200
1.2 mysql控制台命令启动master模式
mysql>GRANT replication slave on *.* to 'slave2'@'10.0.0.2' IDENTIFIED BY 'password'; mysql>SHOW master status;
2 从机设置
2.1 从机配置
server-id = 2 log_bin = /var/log/mysql/mysql-bin.log expire_logs_days = 2 max_binlog_size = 100M
2.2 从机控制台命令
mysql>slave stop; mysql>change master to master_host='10.0.0.1', master_port=3306, master_user='slave2', master_password='password', master_log_file='mysql-bin.000011', master_log_pos=189; mysql>slave start; mysql>show slave status \G;
3mysql远程账号设置
mysql>grant all privileges on *.* to njava@10.0.0.1 identified by "password" with grant option;
服务器上PHP使用QQ邮箱或者Gmail邮箱的SMTP发信
关键点
smtp地址需要加密:
gmail的smtp地址 【ssl://smtp.gmail.com 】
qq邮箱的smtp地址 【ssl://smtp.qq.com】
端口 【465】
linux内网利用iptables共享上网
一 上网机器设置,wlan0为互联网连接,eth0为内网网卡
1 设置/etc/sysctl.conf
net.ipv4.io_forward=1;
2 iptables规则
sudo iptables -t nat -A POSTROUTING -s 10.0.1.0/24 -o wlan0 -j MASQUERADE
3 /etc/network/interfaces
auto eth0 iface eth0 inet static address 10.0.1.1 netmask 255.255.255.0
局域网上网机器设置
1 /etc/network/interfaces
auto eth0 iface eth0 inet static address 10.0.1.2 gateway 10.0.1.1 netmask 255.255.255.0 dns-nameservers 8.8.8.8
删除老的grub菜单
sudo aptitude purge linux-image-3.0.0-16-generic sudo update-grub
自动同步linux服务器时间
在/etc/crontab中添加定时同步服务器时间,每天23点同步服务器时间
0 23 * * * root ntpdate asia.pool.ntp.org >> /var/log/ntpdate.log
ubuntu使用rsync+ssh备份
服务器一直没做备份,丢失信息,很惨,以后都使用rsync+ssh来同步服务器重要文件了。
WEB是要备份的服务器,CLIENT是放备份的服务器
1 在WEB上编写rsync备份脚本,使用root权限cron定时推送
2 rsync命令行语法如下
rsync -vzrtopg --delete -e ssh /var/www njava@bak-server01:/bak/www rsync -vclRarpogt --progress --delete -e ssh /var/lib/mysql/ root@bak-server01:/data/web01
macos下php+mysql不能使用localhost连接的问题解决
因为localhost是通过socket方式来连接,而127.0.0.1则是走的TCP协议。所以需要重新设置php-mysql的配置文件
$echo "show variables" | mysql | grep "socket" socket /opt/local/var/run/mysql5/mysqld.sock $vi /opt/local/var/db/php5/mysql.ini ; Do not edit this file; it is automatically generated by MacPorts. ; Any changes you make will be lost if you upgrade or uninstall php5-mysql. ; To configure PHP, edit /opt/local/etc/php5/php.ini. extension=mysql.so extension=mysqli.so extension=pdo_mysql.so mysql.default_socket= /opt/local/var/run/mysql5/mysqld.sock mysqli.default_socket= /opt/local/var/run/mysql5/mysqld.sock pdo_mysql.default_socket= /opt/local/var/run/mysql5/mysqld.sock
设置mysql.default_socket,mysqli.default_socket,pdo_mysql.default_socket
分析Mysql慢日志log_slow_queries
1 打开log_slow_queries
$sudo vi /etc/mysql/my.cnf log_slow_queries = /var/log/mysql/mysql-slow.log long_query_time = 5 log-queries-not-using-indexes
2使用工具分析mysql slow日志
myprofi.php
3 mysql调优工具
tuning-primer.sh