CentOS7 httpd MySQL PHP memcached SElinux

/omg

CentOS7 minimal

httpd
# yum install httpd
# systemctl start httpd.service
# systemctl enable httpd.service

firewalld
# firewall-cmd –zone=public –add-service=http –permanent
# firewall-cmd –zone=public –add-service=https –permanent
# firewall-cmd –reload

mariadb
# yum install mariadb-server mariadb
# systemctl start mariadb.service
# systemctl enable mariadb.service
# mysql_secure_installation

php
# yum install php php-mysql php-gd php-pear php-mbstring php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel
# chcon -R -t httpd_sys_content_t /home/sourcode/domains/sourcode.net/public_html
# systemctl restart httpd.service

memcached
# yum install php-pecl-memcached memcached
# vi /etc/httpd/conf.d/php.conf

#
# Apache specific PHP configuration options
# those can be override in each configured vhost
#
# php_value session.save_handler "files"
# php_value session.save_path "/var/lib/php/session"
php_value session.save_handler "memcached"
php_value session.save_path "127.0.0.1:11211"

# setsebool -P httpd_can_network_memcache 1
# getsebool httpd_can_network_memcache

# vi /etc/httpd/conf.d/sourcode.conf

</VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/home/sourcode/domains/sourcode.net/public_html"
<Directory "/home/sourcode/domains/sourcode.net/public_html">
Require all granted
</Directory> 
ServerName sourcode.net
ServerAlias www.sourcode.net
ErrorLog “/var/log/httpd/sourcode.net/error_log”
CustomLog “/var/log/httpd/sourcode.net/access_log” common
<VirtualHost>

# end

lost mysql root privileges

วันหนึ่งครับ

MySQL admin พบว่า สิทธิ root ของ MySQL servre เครื่อง master ตัวใหญ่ที่สุดถูกจำกัดเหลือแค่นี้

[[email protected] mysql]# mysql -u root -p
Enter password: 
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root' WITH GRANT OPTION;
ERROR 1045 (28000): Access denied for user 'root'@'%' (using password: YES)
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| theprince          |
+--------------------+
2 rows in set (0.00 sec)

งานเข้าละครับ – -!
จะด้วยเหตุผลอะไรก็ตาม hacker, physical crash , bla bla bla

แก้ด้วยการ
1. ปิด MySQL ก่อน
Redhat base

services mysqld stop

Debian base

/etc/init.d/mysql stop

2. start MySQL แบบไม่ใช้ password

mysqld_safe --skip-grant-tables &

3. login เป็น root โดยไม่ต้องใส่ password

mysql -u root

4.เพิ่มสิทธิให้ root

use mysql;
update user set Select_priv='Y', Insert_priv='Y',Update_priv='Y',Delete_priv='Y', Create_priv='Y',Drop_priv='Y',Reload_priv='Y',Shutdown_priv='Y', Process_priv='Y',File_priv='Y',Grant_priv='Y',References_priv='Y', Index_priv='Y',Alter_priv='Y',Show_db_priv='Y',Super_priv='Y', Create_tmp_table_priv='Y',Lock_tables_priv='Y',Execute_priv='Y', Repl_slave_priv='Y',Repl_client_priv='Y',Create_view_priv='Y', Show_view_priv='Y',Create_routine_priv='Y',Alter_routine_priv='Y', Create_user_priv='Y',Event_priv='Y',Trigger_priv='Y' where User='root';

5. หยุดการทำงานของ MySQL ในโหมดไม่ใช้ password
Redhat base

services mysqld stop

Debian base

/etc/init.d/mysql stop

6. เริ่มการทำงาน MySQL
Redhat base

services mysqld start

Debian base

/etc/init.d/mysql start

จบ.

ibdata1 ใหญ่ไป!

วัันหนึ่ง คุณตื่นเช้ามา และพบว่าพื้นที่ใน databases server ไม่พอใช้

คุณพยายามหาทางลบอะไรบางอย่าง ออกเพื่อให้ได้พื้นที่คืนมา…
แล้วคุณก็พบว่า ibdata1 ใช้พื้นที่ไปถึง 3.3GB !!!

total 3.3G
-rw-r----- 1 mysql root   64K Aug  5 14:16 db3.err
-rw-r--r-- 1 root  root     0 Jul 11 14:50 debian-5.5.flag
-rw-rw---- 1 mysql mysql 3.3G Aug  5 14:16 ibdata1
-rw-rw---- 1 mysql mysql 5.0M Aug  5 14:16 ib_logfile0
-rw-rw---- 1 mysql mysql 5.0M Jul 31 14:19 ib_logfile1
drwxr-xr-x 2 mysql root  1.5K Jul 11 14:51 mysql
-rwxr-xr-x 1 root  root   353 Jul 13 16:08 MySQL_dump.sh
-rw------- 1 root  root     6 Jul 11 14:51 mysql_upgrade_info
drwx------ 2 mysql mysql  400 Jul 11 14:51 performance_schema
drwx------ 2 mysql mysql  200 Jul 31 14:18 project_logger

คุณคิดในใจว่า ‘ลอง drop database แล้ว dump ขึ้นไปใหม่ มันคงลดขนาดลง’

คุณคิดผิด!

วิธีแก้ปัญหาจริงๆแล้วคือ
1. mysqldump -u root -p –all-databases > all_databases.sql
2. drop databases ทิ้งให้หมด รวมทั้ง mysql database ด้วย (แต่ไม่ต้อง drop information_schema กับ performance_schema )
3. service mysqld stop
4. rm ibdata1 ib_log*
5. service mysqld start
6. mysql -u root -p < all_databases.sql ปล. หลังจากที่คุณเริ่มต้นทำงาน mysql ใหม่ในขั้นตอนที่ 5 คุณจะพบว่า ibdata1 มีขนาดเล็กลง... จริงๆนะ [sourcecode language="plain"] total 29M drwxrwxrwt 5 mysql mysql 260 Aug 5 14:17 . drwxr-xr-x 30 root root 4.0K Jul 1 13:35 .. -rw-r----- 1 mysql root 69K Aug 5 14:17 db3.err -rw-rw---- 1 mysql mysql 5 Aug 5 14:17 db3.pid -rw-r--r-- 1 root root 0 Jul 11 14:50 debian-5.5.flag -rw-rw---- 1 mysql mysql 18M Aug 5 14:17 ibdata1 -rw-rw---- 1 mysql mysql 5.0M Aug 5 14:17 ib_logfile0 -rw-rw---- 1 mysql mysql 5.0M Aug 5 14:16 ib_logfile1 drwxr-xr-x 2 mysql root 1.5K Jul 11 14:51 mysql -rwxr-xr-x 1 root root 353 Jul 13 16:08 MySQL_dump.sh -rw------- 1 root root 6 Jul 11 14:51 mysql_upgrade_info drwx------ 2 mysql mysql 400 Jul 11 14:51 performance_schema drwx------ 2 mysql mysql 200 Jul 31 14:18 project_logger [/sourcecode]

innotop debian

# innotop -u root -p password -h localhost
Can’t locate Term/ReadKey.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.10.1 /usr/local/share/perl/5.10.1 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl .) at /usr/bin/innotop line 1341.
BEGIN failed–compilation aborted at /usr/bin/innotop line 1341.

# aptitude -y install libterm-readkey-perl
The following NEW packages will be installed:
libterm-readkey-perl
0 packages upgraded, 1 newly installed, 0 to remove and 8 not upgraded.
Need to get 33.7 kB of archives. After unpacking 139 kB will be used.
Get:1 http://ftp.debian.org/debian/ squeeze/main libterm-readkey-perl amd64 2.30-4 [33.7 kB]
Fetched 33.7 kB in 2s (11.6 kB/s)
Selecting previously deselected package libterm-readkey-perl.
(Reading database … 31153 files and directories currently installed.)
Unpacking libterm-readkey-perl (from …/libterm-readkey-perl_2.30-4_amd64.deb) …
Processing triggers for man-db …
Setting up libterm-readkey-perl (2.30-4) …

pymysql python3 debian squeeze

from : previous post

มันไม่ทำงานครับ… ผมขอโทษ
ต้องทำการ patch ด้วยการ

# git clone https://github.com/petehunt/PyMySQL.git
# cd PyMySQL/
# ./build-py3k.sh 
# cd py3k/
# python3 setup.py install

example.

[email protected]:/usr/src/PyMySQL# ./build-py3k.sh 
Building Python 3.0 version in ./py3k...
RefactoringTool: Skipping implicit fixer: buffer
RefactoringTool: Skipping implicit fixer: idioms
RefactoringTool: Skipping implicit fixer: set_literal
RefactoringTool: Skipping implicit fixer: ws_comma
RefactoringTool: No changes to ./setup.py
RefactoringTool: Refactored ./pymysql/__init__.py
RefactoringTool: Refactored ./pymysql/charset.py
RefactoringTool: Refactored ./pymysql/connections.py
RefactoringTool: Refactored ./pymysql/converters.py
RefactoringTool: Refactored ./pymysql/cursors.py
RefactoringTool: Refactored ./pymysql/err.py
RefactoringTool: No changes to ./pymysql/util.py
RefactoringTool: No changes to ./pymysql/constants/COMMAND.py
RefactoringTool: No changes to ./pymysql/constants/FIELD_TYPE.py
RefactoringTool: No changes to ./pymysql/tests/__init__.py
RefactoringTool: Refactored ./pymysql/tests/test_DictCursor.py
RefactoringTool: No changes to ./pymysql/tests/test_SSCursor.py
RefactoringTool: Refactored ./pymysql/tests/test_basic.py
RefactoringTool: Refactored ./pymysql/tests/test_issues.py
RefactoringTool: Refactored ./pymysql/tests/thirdparty/__init__.py
RefactoringTool: Refactored ./pymysql/tests/thirdparty/test_MySQLdb/__init__.py
RefactoringTool: Refactored ./pymysql/tests/thirdparty/test_MySQLdb/capabilities.py
RefactoringTool: Refactored ./pymysql/tests/thirdparty/test_MySQLdb/dbapi20.py
RefactoringTool: Refactored ./pymysql/tests/thirdparty/test_MySQLdb/test_MySQLdb_capabilities.py
RefactoringTool: Refactored ./pymysql/tests/thirdparty/test_MySQLdb/test_MySQLdb_dbapi20.py
RefactoringTool: Refactored ./pymysql/tests/thirdparty/test_MySQLdb/test_MySQLdb_nonstandard.py
RefactoringTool: Files that need to be modified:
RefactoringTool: ./setup.py
RefactoringTool: ./pymysql/__init__.py
RefactoringTool: ./pymysql/charset.py
RefactoringTool: ./pymysql/connections.py
RefactoringTool: ./pymysql/converters.py
RefactoringTool: ./pymysql/cursors.py
RefactoringTool: ./pymysql/err.py
RefactoringTool: ./pymysql/util.py
RefactoringTool: ./pymysql/constants/COMMAND.py
RefactoringTool: ./pymysql/constants/FIELD_TYPE.py
RefactoringTool: ./pymysql/tests/__init__.py
RefactoringTool: ./pymysql/tests/test_DictCursor.py
RefactoringTool: ./pymysql/tests/test_SSCursor.py
RefactoringTool: ./pymysql/tests/test_basic.py
RefactoringTool: ./pymysql/tests/test_issues.py
RefactoringTool: ./pymysql/tests/thirdparty/__init__.py
RefactoringTool: ./pymysql/tests/thirdparty/test_MySQLdb/__init__.py
RefactoringTool: ./pymysql/tests/thirdparty/test_MySQLdb/capabilities.py
RefactoringTool: ./pymysql/tests/thirdparty/test_MySQLdb/dbapi20.py
RefactoringTool: ./pymysql/tests/thirdparty/test_MySQLdb/test_MySQLdb_capabilities.py
RefactoringTool: ./pymysql/tests/thirdparty/test_MySQLdb/test_MySQLdb_dbapi20.py
RefactoringTool: ./pymysql/tests/thirdparty/test_MySQLdb/test_MySQLdb_nonstandard.py
patching file ./pymysql/__init__.py
patching file ./pymysql/charset.py
patching file ./pymysql/connections.py
patching file ./pymysql/converters.py
patching file ./pymysql/cursors.py
patching file ./pymysql/err.py
patching file ./pymysql/tests/test_DictCursor.py
patching file ./pymysql/tests/test_basic.py
patching file ./pymysql/tests/test_issues.py
patching file ./pymysql/tests/thirdparty/__init__.py
patching file ./pymysql/tests/thirdparty/test_MySQLdb/__init__.py
patching file ./pymysql/tests/thirdparty/test_MySQLdb/capabilities.py
patching file ./pymysql/tests/thirdparty/test_MySQLdb/dbapi20.py
patching file ./pymysql/tests/thirdparty/test_MySQLdb/test_MySQLdb_capabilities.py
patching file ./pymysql/tests/thirdparty/test_MySQLdb/test_MySQLdb_dbapi20.py
patching file ./pymysql/tests/thirdparty/test_MySQLdb/test_MySQLdb_nonstandard.py
patching file setup.py
Hunk #1 succeeded at 33 (offset 18 lines).



[email protected]:/usr/src/PyMySQL/py3k# python3 setup.py install
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.1
creating build/lib.linux-x86_64-3.1/pymysql
copying pymysql/__init__.py -> build/lib.linux-x86_64-3.1/pymysql
copying pymysql/connections.py -> build/lib.linux-x86_64-3.1/pymysql
copying pymysql/converters.py -> build/lib.linux-x86_64-3.1/pymysql
copying pymysql/util.py -> build/lib.linux-x86_64-3.1/pymysql
copying pymysql/err.py -> build/lib.linux-x86_64-3.1/pymysql
copying pymysql/charset.py -> build/lib.linux-x86_64-3.1/pymysql
copying pymysql/cursors.py -> build/lib.linux-x86_64-3.1/pymysql
copying pymysql/times.py -> build/lib.linux-x86_64-3.1/pymysql
creating build/lib.linux-x86_64-3.1/pymysql/constants
copying pymysql/constants/__init__.py -> build/lib.linux-x86_64-3.1/pymysql/constants
copying pymysql/constants/ER.py -> build/lib.linux-x86_64-3.1/pymysql/constants
copying pymysql/constants/FLAG.py -> build/lib.linux-x86_64-3.1/pymysql/constants
copying pymysql/constants/COMMAND.py -> build/lib.linux-x86_64-3.1/pymysql/constants
copying pymysql/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-3.1/pymysql/constants
copying pymysql/constants/CLIENT.py -> build/lib.linux-x86_64-3.1/pymysql/constants
copying pymysql/constants/SERVER_STATUS.py -> build/lib.linux-x86_64-3.1/pymysql/constants
creating build/lib.linux-x86_64-3.1/pymysql/tests
copying pymysql/tests/test_basic.py -> build/lib.linux-x86_64-3.1/pymysql/tests
copying pymysql/tests/__init__.py -> build/lib.linux-x86_64-3.1/pymysql/tests
copying pymysql/tests/test_issues.py -> build/lib.linux-x86_64-3.1/pymysql/tests
copying pymysql/tests/test_DictCursor.py -> build/lib.linux-x86_64-3.1/pymysql/tests
copying pymysql/tests/test_SSCursor.py -> build/lib.linux-x86_64-3.1/pymysql/tests
copying pymysql/tests/base.py -> build/lib.linux-x86_64-3.1/pymysql/tests
copying pymysql/tests/test_example.py -> build/lib.linux-x86_64-3.1/pymysql/tests
running install_lib
creating /usr/local/lib/python3.1/dist-packages/pymysql
copying build/lib.linux-x86_64-3.1/pymysql/__init__.py -> /usr/local/lib/python3.1/dist-packages/pymysql
copying build/lib.linux-x86_64-3.1/pymysql/connections.py -> /usr/local/lib/python3.1/dist-packages/pymysql
copying build/lib.linux-x86_64-3.1/pymysql/converters.py -> /usr/local/lib/python3.1/dist-packages/pymysql
copying build/lib.linux-x86_64-3.1/pymysql/util.py -> /usr/local/lib/python3.1/dist-packages/pymysql
copying build/lib.linux-x86_64-3.1/pymysql/err.py -> /usr/local/lib/python3.1/dist-packages/pymysql
copying build/lib.linux-x86_64-3.1/pymysql/charset.py -> /usr/local/lib/python3.1/dist-packages/pymysql
creating /usr/local/lib/python3.1/dist-packages/pymysql/constants
copying build/lib.linux-x86_64-3.1/pymysql/constants/__init__.py -> /usr/local/lib/python3.1/dist-packages/pymysql/constants
copying build/lib.linux-x86_64-3.1/pymysql/constants/ER.py -> /usr/local/lib/python3.1/dist-packages/pymysql/constants
copying build/lib.linux-x86_64-3.1/pymysql/constants/FLAG.py -> /usr/local/lib/python3.1/dist-packages/pymysql/constants
copying build/lib.linux-x86_64-3.1/pymysql/constants/COMMAND.py -> /usr/local/lib/python3.1/dist-packages/pymysql/constants
copying build/lib.linux-x86_64-3.1/pymysql/constants/FIELD_TYPE.py -> /usr/local/lib/python3.1/dist-packages/pymysql/constants
copying build/lib.linux-x86_64-3.1/pymysql/constants/CLIENT.py -> /usr/local/lib/python3.1/dist-packages/pymysql/constants
copying build/lib.linux-x86_64-3.1/pymysql/constants/SERVER_STATUS.py -> /usr/local/lib/python3.1/dist-packages/pymysql/constants
copying build/lib.linux-x86_64-3.1/pymysql/cursors.py -> /usr/local/lib/python3.1/dist-packages/pymysql
creating /usr/local/lib/python3.1/dist-packages/pymysql/tests
copying build/lib.linux-x86_64-3.1/pymysql/tests/test_basic.py -> /usr/local/lib/python3.1/dist-packages/pymysql/tests
copying build/lib.linux-x86_64-3.1/pymysql/tests/__init__.py -> /usr/local/lib/python3.1/dist-packages/pymysql/tests
copying build/lib.linux-x86_64-3.1/pymysql/tests/test_issues.py -> /usr/local/lib/python3.1/dist-packages/pymysql/tests
copying build/lib.linux-x86_64-3.1/pymysql/tests/test_DictCursor.py -> /usr/local/lib/python3.1/dist-packages/pymysql/tests
copying build/lib.linux-x86_64-3.1/pymysql/tests/test_SSCursor.py -> /usr/local/lib/python3.1/dist-packages/pymysql/tests
copying build/lib.linux-x86_64-3.1/pymysql/tests/base.py -> /usr/local/lib/python3.1/dist-packages/pymysql/tests
copying build/lib.linux-x86_64-3.1/pymysql/tests/test_example.py -> /usr/local/lib/python3.1/dist-packages/pymysql/tests
copying build/lib.linux-x86_64-3.1/pymysql/times.py -> /usr/local/lib/python3.1/dist-packages/pymysql
byte-compiling /usr/local/lib/python3.1/dist-packages/pymysql/__init__.py to __init__.pyc
byte-compiling /usr/local/lib/python3.1/dist-packages/pymysql/connections.py to connections.pyc
byte-compiling /usr/local/lib/python3.1/dist-packages/pymysql/converters.py to converters.pyc
byte-compiling /usr/local/lib/python3.1/dist-packages/pymysql/util.py to util.pyc
byte-compiling /usr/local/lib/python3.1/dist-packages/pymysql/err.py to err.pyc
byte-compiling /usr/local/lib/python3.1/dist-packages/pymysql/charset.py to charset.pyc
byte-compiling /usr/local/lib/python3.1/dist-packages/pymysql/constants/__init__.py to __init__.pyc
byte-compiling /usr/local/lib/python3.1/dist-packages/pymysql/constants/ER.py to ER.pyc
byte-compiling /usr/local/lib/python3.1/dist-packages/pymysql/constants/FLAG.py to FLAG.pyc
byte-compiling /usr/local/lib/python3.1/dist-packages/pymysql/constants/COMMAND.py to COMMAND.pyc
byte-compiling /usr/local/lib/python3.1/dist-packages/pymysql/constants/FIELD_TYPE.py to FIELD_TYPE.pyc
byte-compiling /usr/local/lib/python3.1/dist-packages/pymysql/constants/CLIENT.py to CLIENT.pyc
byte-compiling /usr/local/lib/python3.1/dist-packages/pymysql/constants/SERVER_STATUS.py to SERVER_STATUS.pyc
byte-compiling /usr/local/lib/python3.1/dist-packages/pymysql/cursors.py to cursors.pyc
byte-compiling /usr/local/lib/python3.1/dist-packages/pymysql/tests/test_basic.py to test_basic.pyc
byte-compiling /usr/local/lib/python3.1/dist-packages/pymysql/tests/__init__.py to __init__.pyc
byte-compiling /usr/local/lib/python3.1/dist-packages/pymysql/tests/test_issues.py to test_issues.pyc
byte-compiling /usr/local/lib/python3.1/dist-packages/pymysql/tests/test_DictCursor.py to test_DictCursor.pyc
byte-compiling /usr/local/lib/python3.1/dist-packages/pymysql/tests/test_SSCursor.py to test_SSCursor.pyc
byte-compiling /usr/local/lib/python3.1/dist-packages/pymysql/tests/base.py to base.pyc
byte-compiling /usr/local/lib/python3.1/dist-packages/pymysql/tests/test_example.py to test_example.pyc
byte-compiling /usr/local/lib/python3.1/dist-packages/pymysql/times.py to times.pyc
running install_egg_info
Writing /usr/local/lib/python3.1/dist-packages/PyMySQL3-0.5.egg-info