Project

General

Profile

Database Server Installation Shared » History » Version 52

Eric Hou, 05/19/2010 02:30 PM

1 1 Amber Herold
h1. Database Server Installation
2
3
h2. Install MySQL 
4
5
The following is for the computer that hosts the databases. This involves installing MySQL server and creation/configuration of the leginondb and projectdb databases.
6
7 38 Amber Herold
8 1 Amber Herold
 
9 42 Amber Herold
h3. 1 Install MySQL-Server and MySQL-Client
10 38 Amber Herold
11
*Note:* You may already have MySQL Server and Client installed. Check by typing mysql at the command line. 
12
If you see a MySQL prompt (mysql>), you may skip this step.
13 1 Amber Herold
14 15 Neil Voss
To install Mysql on Linux you have two options (the first option is better):
15 1 Amber Herold
16 15 Neil Voss
# Use your package installer (yum, zypper, YaST, apt-get). For example:
17 52 Eric Hou
   <pre>sudo yum install mysql mysql-server</pre>
18
   For Suse
19
   <pre>yast2 -i mysql mysql-client</pre>
20 15 Neil Voss
# Download the latest MySQL-server package for Linux from http://www.mysql.com
21 1 Amber Herold
22 42 Amber Herold
h3. 2 Locate Example MySQL configuration files 
23 1 Amber Herold
24 42 Amber Herold
They are usually located in /usr/share/mysql.
25
26 1 Amber Herold
<pre>
27
ls /usr/share/mysql/my*
28 15 Neil Voss
    /usr/share/mysql/my-huge.cnf
29
    /usr/share/mysql/my-innodb-heavy-4G.cnf
30
    /usr/share/mysql/my-large.cnf
31
    /usr/share/mysql/my-medium.cnf
32
    /usr/share/mysql/my-small.cnf
33 20 Neil Voss
</pre>
34
If that does not work try the locate function
35
<pre>
36 15 Neil Voss
locate my | egrep "\.cnf$"
37
    /etc/my.cnf
38 1 Amber Herold
    /usr/share/mysql/my-huge.cnf
39
    /usr/share/mysql/my-innodb-heavy-4G.cnf
40
    /usr/share/mysql/my-large.cnf
41
    /usr/share/mysql/my-medium.cnf
42
    /usr/share/mysql/my-small.cnf
43 3 Amber Herold
</pre>
44 1 Amber Herold
45 42 Amber Herold
h3. 3 Configure my.cnf in /etc using my-huge.cnf as the template
46 1 Amber Herold
47 18 Neil Voss
# Copy my-huge.cnf to my.cnf
48 19 Neil Voss
<pre>sudo cp -v /usr/share/mysql/my-huge.cnf /etc/my.cnf</pre>
49 22 Neil Voss
# Edit /etc/my.cnf to add or change query cache variables like these (be sure to place them under the @[mysqld]@ section):
50 1 Amber Herold
<pre>
51 39 Amber Herold
query_cache_type = 1
52 1 Amber Herold
query_cache_size = 100M
53 21 Neil Voss
query_cache_limit= 100M
54 1 Amber Herold
</pre>
55 11 Neil Voss
# Search for the text default-storage-engine in /etc/my.cnf.  If it exists and is set to other than MyISAM, you should change it to:
56 1 Amber Herold
<pre>default-storage-engine=MyISAM</pre>
57 10 Neil Voss
58 42 Amber Herold
h3. 4 Start the MySQL Server
59 1 Amber Herold
60 10 Neil Voss
For CentOS/Fedora/RHEL system use the service command:
61
62 1 Amber Herold
<pre>
63 10 Neil Voss
sudo /sbin/service mysqld start
64 1 Amber Herold
</pre>
65
66 10 Neil Voss
For other Unix systems:
67
68
<pre>
69
sudo /etc/init.d/mysqld start
70
</pre>
71
72 12 Neil Voss
or on some installations,
73 1 Amber Herold
74
<pre>
75 10 Neil Voss
sudo /etc/init.d/mysql start
76 1 Amber Herold
</pre>
77
78
For future reference: start | stop | restart MySQL Server with similar commands:
79
80
<pre>
81 10 Neil Voss
sudo /etc/init.d/mysqld start
82
sudo /etc/init.d/mysqld stop
83
sudo /etc/init.d/mysqld restart
84 1 Amber Herold
sudo /sbin/service mysqld start
85 10 Neil Voss
sudo /sbin/service mysqld stop
86
sudo /sbin/service mysqld restart
87 1 Amber Herold
</pre>
88
89 42 Amber Herold
h3. 5 Configure MySQL to start automatically at boot
90 1 Amber Herold
91
<pre>
92
sudo /sbin/chkconfig mysqld on
93
</pre>
94 23 Neil Voss
or for SuSe:
95
<pre>
96
sudo /sbin/chkconfig mysql on
97
</pre>
98 1 Amber Herold
99 42 Amber Herold
h3. 6 For future reference, the database location will be:
100 1 Amber Herold
101 10 Neil Voss
<pre>
102
ls /var/lib/mysql
103 1 Amber Herold
    ibdata1  ib_logfile0  ib_logfile1  mysql  mysql.sock  test
104
</pre>
105
106 42 Amber Herold
h3. 7 Create the Leginon database, call it leginondb
107 3 Amber Herold
108 10 Neil Voss
<pre>
109 1 Amber Herold
sudo mysqladmin create leginondb
110
</pre>
111
112 42 Amber Herold
h3. 8 Create the Project database, call it projectdb
113 1 Amber Herold
114
<pre>
115
sudo mysqladmin create projectdb
116
</pre>
117
118 42 Amber Herold
h3. 9 Connect to mysql db
119 11 Neil Voss
120 40 Amber Herold
If starting from scratch, the mysql root user will have no password. This is assumed to be the case and we will set it later.
121 1 Amber Herold
122 23 Neil Voss
<pre>
123 28 Neil Voss
mysql -u root mysql
124 23 Neil Voss
</pre>
125 1 Amber Herold
126 40 Amber Herold
You should see a mysql prompt: mysql>
127
128
You can view the current mysql users with the following command.
129 11 Neil Voss
<pre>
130 40 Amber Herold
select user, password, host from user;
131 1 Amber Herold
      +------+----------+-----------+
132
      | user | password | host      |
133
      +------+----------+-----------+
134
      | root |          | localhost |
135
      | root |          | host1     |
136
      |      |          | host1     |
137
      |      |          | localhost |
138
      +------+----------+-----------+
139
      4 rows in set (0.00 sec)
140
</pre>
141
142 42 Amber Herold
h3. 10 Create user
143 1 Amber Herold
144 41 Amber Herold
Create and grant privileges to a user called usr_object for the databases on both the localhost and other hosts involved. For example, use wild card '%' for all hosts. You can set specific (@ALTER, CREATE, DROP, DELETE, INSERT, RENAME, SELECT, UPDATE@) privileges or @ALL@ privileges to the user. See MySQL Reference Manual for details. The following examples demonstrate some of the options available.
145 3 Amber Herold
146 36 Amber Herold
At the mysql prompt execute the following commands:
147 1 Amber Herold
<pre>
148 36 Amber Herold
CREATE USER usr_object@'localhost' IDENTIFIED BY 'YOUR PASSWORD';
149
GRANT ALTER, CREATE, INSERT, SELECT, UPDATE ON leginondb.* TO usr_object@'localhost';
150
GRANT ALTER, CREATE, INSERT, SELECT, UPDATE ON projectdb.* TO usr_object@'localhost';
151 1 Amber Herold
</pre>
152
153 41 Amber Herold
You may choose to use the following less secure version (no password and all privileges) of the commands above, however, we recommend not allowing the DROP and DELETE privileges.
154 1 Amber Herold
155 36 Amber Herold
At the mysql prompt execute the following commands:
156 24 Neil Voss
<pre>
157 36 Amber Herold
CREATE USER usr_object@'localhost';
158
GRANT ALL PRIVILEGES ON leginondb.* TO usr_object@'localhost';
159 1 Amber Herold
GRANT ALL PRIVILEGES ON projectdb.* TO usr_object@'localhost';
160
</pre>
161 24 Neil Voss
162 41 Amber Herold
You may also choose to assign a domain to your commands and use a wildcard to allow access from all computers in the domain. 
163 26 Neil Voss
164 1 Amber Herold
<pre>
165 36 Amber Herold
CREATE USER usr_object@'%.mydomain.edu' IDENTIFIED BY 'YOUR PASSWORD';
166
GRANT ALTER, CREATE, INSERT, SELECT, UPDATE ON leginondb.* to usr_object@'%.mydomain.edu';
167 1 Amber Herold
GRANT ALTER, CREATE, INSERT, SELECT, UPDATE ON projectdb.* to usr_object@'%.mydomain.edu';
168 24 Neil Voss
</pre>
169 3 Amber Herold
170 42 Amber Herold
h3. 11 Give create and access privileges for the processing databases which begin with "ap".
171 10 Neil Voss
172 24 Neil Voss
<pre>
173 27 Neil Voss
# if your web host is local
174 36 Amber Herold
GRANT ALTER, CREATE, INSERT, SELECT, UPDATE ON `ap%`.* to usr_object@localhost; 
175 27 Neil Voss
# for all other hosts if you are accessing the databases from another computer
176 36 Amber Herold
GRANT ALTER, CREATE, INSERT, SELECT, UPDATE ON `ap%`.* to usr_object@'%.mydomain.edu';       
177 1 Amber Herold
</pre>
178
179 42 Amber Herold
h3. 12 Change Root password
180 1 Amber Herold
181 28 Neil Voss
To set the root password use the command: 
182 1 Amber Herold
183 28 Neil Voss
<pre>
184
sudo mysqladmin -u root password NEWPASSWORD
185
</pre>
186 1 Amber Herold
187 28 Neil Voss
Or you can do it from within mysql
188 10 Neil Voss
<pre>
189 36 Amber Herold
update user set password=password('your_own_root_password') where user="root";
190 1 Amber Herold
Query OK, 2 rows affected (0.01 sec)
191
Rows matched: 2  Changed: 2  Warnings: 0
192
193 43 Amber Herold
# run the flush privileges command to avoid problems
194 36 Amber Herold
flush privileges;
195
^D or exit;
196 3 Amber Herold
</pre>
197 1 Amber Herold
198 3 Amber Herold
199 1 Amber Herold
From now on, you will need to specify the password to connect to the database as root user like this:
200
201 30 Neil Voss
<pre>
202 36 Amber Herold
mysql -u root -p mysql
203 1 Amber Herold
</pre>
204
205 42 Amber Herold
h3. 13 Check MySQL variables
206 1 Amber Herold
207 31 Neil Voss
<pre>
208 44 Amber Herold
# at the command prompt, log into the leginon database
209
210 36 Amber Herold
mysql -u usr_object -p leginondb
211 1 Amber Herold
212 44 Amber Herold
# At the mysql prompt show variables that begin with 'query'.
213
# Check that the changes you made to my.cfg are in place.
214
215 36 Amber Herold
SHOW VARIABLES LIKE 'query%';
216 1 Amber Herold
      +------------------------------+-----------+
217
      | Variable_name                | Value     |
218
      +------------------------------+-----------+
219
      | ft_query_expansion_limit     | 20        |
220
      | have_query_cache             | YES       |
221
      | long_query_time              | 10        |
222
      | query_alloc_block_size       | 8192      |
223 44 Amber Herold
      | query_cache_limit            | 104857600 | ---This should correspond to your change
224 1 Amber Herold
      | query_cache_min_res_unit     | 4096      |
225 44 Amber Herold
      | query_cache_size             | 104857600 | ---This should correspond to your change
226
      | query_cache_type             | ON        | ---This should correspond to your change
227 1 Amber Herold
      | query_cache_wlock_invalidate | OFF       |
228
      | query_prealloc_size          | 8192      |
229
      +------------------------------+-----------+
230
      10 rows in set (0.00 sec)
231 36 Amber Herold
232 1 Amber Herold
exit;
233
</pre>
234 42 Amber Herold
235 1 Amber Herold
h3. 14 Make sure MySQL is running
236 3 Amber Herold
237 36 Amber Herold
<pre>
238 45 Amber Herold
mysqlshow -u root
239 1 Amber Herold
      +--------------+
240 30 Neil Voss
      | Databases    |
241
      +--------------+
242
      | mysql        |
243
      | leginondb    |
244 1 Amber Herold
      | projectdb    |
245
      +--------------+
246 30 Neil Voss
</pre>
247 36 Amber Herold
248 1 Amber Herold
h3. Run the following command from the command line:
249 30 Neil Voss
250 46 Amber Herold
251 1 Amber Herold
<pre>
252
php -r "mysql_connect('localhost', 'usr_object', 'PASSWORD', 'leginondb'); echo mysql_stat();"; echo ""
253 30 Neil Voss
</pre>
254 1 Amber Herold
255
Expected output:
256
257
<pre>
258
Uptime: 1452562 Threads: 1 Questions: 618 Slow queries: 0 Opens: 117 Flush tables: 1 Open tables: 106 Queries per second avg: 0.000
259 47 Amber Herold
</pre>
260
261 48 Amber Herold
If there are any error messages, mysql may be configured incorrectly.
262
263 47 Amber Herold
*Note:* If you do not have php and php-mysql packages installed you need to install them to run the above command. The yum installation is:
264
<pre>
265
sudo yum -y install php php-mysql
266 36 Amber Herold
</pre>
267 30 Neil Voss
268 1 Amber Herold
269 30 Neil Voss
h2. Configure phpMyAdmin 
270 1 Amber Herold
271 50 Amber Herold
You are not required to install phpMyAdmin for Appion or Leginon, however, it is a useful tool for interfacing with the mysql databases. 
272 49 Amber Herold
273 51 Amber Herold
If you have not already installed phpMyAdmin, do so. The yum installation is:
274
<pre>
275
sudo yum -y install phpMyAdmin
276
</pre>
277
278
279 12 Neil Voss
Edit the phpMyAdmin config file @/etc/phpMyAdmin/config.inc.php@ and change the following lines:
280 30 Neil Voss
281 1 Amber Herold
<pre>
282
$cfg['Servers'][$i]['AllowRoot']     = FALSE;
283 30 Neil Voss
</pre>
284 1 Amber Herold
285
Edit the phpMyAdmin apache config file @/etc/httpd/conf.d/phpMyAdmin.conf@ and change the following lines:
286
287
<pre>
288
<Directory /usr/share/phpMyAdmin/>
289
   order deny,allow
290
   deny from all
291
   allow from 127.0.0.1
292
   allow from YOUR_IP_ADDRESS
293 31 Neil Voss
</Directory>
294
</pre>
295 1 Amber Herold
296 33 Neil Voss
*Note:* If you want to access phpMyAdmin from another computer, you can also add it to this config file with an @allow from@ tag
297
298
Next restart the web server to take on the new setting
299
<pre>
300
sudo /sbin/service httpd restart
301 1 Amber Herold
</pre>
302 35 Neil Voss
303
To test the phpMyAdmin configuration, point your browser to http://YOUR_IP_ADDRESS/phpMyAdmin or http://localhost/phpMyAdmin and login with the usr_object user.
304 33 Neil Voss
305
!phpMyAdmin.png!
306
307
A common problem is that the firewall may be blocking access to the web server and mysql server. On CentOS/Fedora you can configure this with the system config:
308
309
<pre>
310
system-config-securitylevel
311
</pre>
312 1 Amber Herold
313
Firewall configuration is specific to different Unix distributions, so consult a guide on how to do this on non-RedHat machines.