安装Haproxy: (已经安装)
1. yum install gcc gcc-c++ make openssl-devel kernel-devel
2. tar zxvf haproxy-1.7.6.tar.gz
3. make TARGET=linux26 CPU=x86_64 PREFIX=/root/haproxy USE_OPENSSL=1 ADDLIB=-lz
4. make install PREFIX=/root/haproxy
---------------------------------------------------------------------------------------------
安装包在 /home 下
yum install gcc gcc-c++ make openssl-devel kernel-devel
安装 nginx:
1. yum install unzip
2. yum install -y nginx
安装PHP5.6:
1. yum install openssl openssl-devel libxml2-devel libxml2 bzip2 bzip2-devel curl-devel php-mcrypt libmcrypt libmcrypt-devel readline-devel
2. tar zxvf php_v5.6.40.tar.gz
3. cd php-5.6.40/
4. chmod +x ./configure
5. yum install libxml2-devel -y
6. yum install -y epel-release
7. yum install -y libmcrypt-devel
8. yum install readline-devel
9. ./configure --prefix=/usr/local/php5.6 --with-config-file-path=/usr/local/php5.6/etc --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-opcache --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gettext --enable-mbstring --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-zlib --enable-zip --with-bz2 --with-readline
10. make
11. make test
12. make install
13. vi /etc/profile
14. 最后处添加: PATH=$PATH:/usr/local/php5.6/bin
export PATH
15. wq 保存,source /etc/profile
16. php --ini 看从哪里读取 php.ini路径
17. cp /etc/php.ini /usr/local/php5.6/etc/php.ini
安装 php-redis 扩展:
1. unzip phpredis-3.1.4.zip
2. cd phpredis-3.1.4
3. /usr/local/php5.6/bin/phpize
4. chmod +x ./configure
5. ./configure --with-php-config=/usr/local/php5.6/bin/php-config
6. make && make install
7. 看 redis.so 安装到哪里个路径下,然后修改 php.ini
8. 修改 php.ini ,在 Modules Settings 下 添加: extension = "/usr/local/php5.6/lib/php/extensions/no-debug-non-zts-20131226/redis.so"
9. php -m 列表里有 redis 表示安装成功
10. 如果失败,请重启php-fpm, 然后到 phpredis 扩展安装目录执行 make clean, 然后按照 第3---第9 重新实施一遍。
PHP优化:
1. cd /dev/shm
2. touch php-fcgi.sock
3. chmod 0757 php-fcgi.sock
4. vi /usr/local/php5.6/etc/php-fpm.conf
5. 搜索9000 , 然后注释掉 ;listen = 127.0.0.1:9000
6. 添加 listen = /dev/shm/php-fcgi.sock
7. 修改 pm.max_children = 300
8. 修改 pm.start_servers = 20
9. 修改 pm.min_spare_servers = 5
10. 修改 pm.max_spare_servers = 35
11. 修改 pm.max_requests = 10240
12. 优化 opcache
安装 mysql:
1. tar -zxvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
2. cd mysql-5.7.23-linux-glibc2.12-x86_64
3. groupadd mysql
4. useradd -r -g mysql -s /sbin/nologin mysql
5. yum install -y libaio
6. ./bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql 注明: 此步骤会生成一个临时初始密码
最后一行信息如:[Note] A temporary password is generated for root@localhost: :Jd+OZkuw5Pk root@localhost: 后面的都是密码,需要记录
7. ./bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/
8. cp /home/my.cnf /etc/my.cnf
9. support-files/mysql.server start // 看是否能成功启动, 输出 OK 代表启动成功,然后关闭
10. support-files/mysql.server stop
11. 解决Can 't connect to local MySQL server through socket '/tmp/mysql.sock '(2)
12. vi /etc/my.cnf
13. [client] 下 修改 socket = /home/mysql-5.7.23-linux-glibc2.12-x86_64/mysql.sock
14. 并且给 /home/mysql-5.7.23-linux-glibc2.12-x86_64 目录赋予权限
15. support-files/mysql.server start 启动mysql
16. bin/mysql -uroot -p':Jd+OZkuw5Pk' // 使用初始密码访问
17. set password = password('werterdg4334t@='); // 修改密码
18. flush privileges; // 刷新 使命令生效
19. 设置外网访问权限 : use mysql;
20. GRANT ALL ON *.* TO root@'%' IDENTIFIED BY 'adsdafsdfre@=' WITH GRANT OPTION;
21. flush privileges;
22. 本地连接远程数据 看是否OK
Mysql 配置主从:
1. 创建数据库 testtest
2. 导入表结构 testtest.sql
3. 主库配置: vi /etc/my.cnf
4. 字段修改:log-bin=mysql-bin
5. server-id=1 // 唯一值 不能和从库一样
6. support-files/mysql.server restart
7. bin/mysql -uroot -p'sdffsdfgersfer@=' // 控制台登录mysql
8. use mysql;
9. GRANT FILE ON *.* TO 'testtest'@'%' IDENTIFIED BY 'sdfsdfsedfdsf@=='; // 创建同步账号,禁止用root
10. GRANT replication slave on *.* to 'testtest'@'%' identified by 'sdfsdfsedfdsf@=='; // 授权
11. Grant all on testest.* to testtest; // 授权
12. flush privileges; // 命令生效
13. 远程登录使用 testtest这个账号,看是否有权限操作 testtest 库
14. 从库配置: vi /etc/my.cnf
15. read_only = 1
16. server-id = 2
17. log-bin=mysql-bin
18. binlog-do-db=testtest // 设置要同步的库名称
19. change master to master_host='192.168.0.190',master_user='testtest',master_password='dfgbdfgdfgfd@=',master_log_pos=2; // master_host 主库的内网IP password主库的登录密码
20. start slave;
21. show slave status\G; // 发现Slave_IO_Running: Yes Slave_SQL_Running: Yes 都是YES 代表正常
22. 主库插入数据 , 从库看是否更新,如果更新代表配置成功。
mysql 优化:
1. 最大连接数
2. 超时、错误等优化
iptables 优化:
1. 当前允许最多IP访问
2. 设置过滤规则